Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect data after app goes in the background #705

Open
vkammerer opened this issue Nov 12, 2023 · 2 comments
Open

Incorrect data after app goes in the background #705

vkammerer opened this issue Nov 12, 2023 · 2 comments
Labels
bug Something isn't working realtime This issue or pull request is related to realtime

Comments

@vkammerer
Copy link

When an iOS app goes in the background, it looses network after a while (about 90 seconds according to my tests with the simulator).
If new rows are then created in a Supabase table that the app listens to, the app doesn't receive the data (which is expected).
When the app reconnects after idling, it starts receiving table addition events (which is expected), but it emits a representation of the data without the events that happened while is was offline (which is not expected).

I looked a bit at the code and can see that supabase-flutter manages its own cache, and that it manages internal representations of a table on atomic events like "INSERT" for example.

Maybe a solution could be to fetch the whole table after a reconnection? Or maybe to pass a reference to the previous message for all atomic events, so that the app can ensure that it hasn't missed one?

See video below for an example: the "third message" is ignored, and an incorrect representation of the messages list is emitted.
https://github.com/supabase/supabase-flutter/assets/1177483/5b44500b-d3eb-476b-8946-f02d4029c8f4

Steps to reproduce the behavior:

  1. Listen to a table
supabase.from('messages').stream(primaryKey: ['id']).listen((event) {
  setState(() {
    _messages = event.map(Message.fromJson).toList();
});
  1. Move the app to the background
  2. Wait 1:30 minute
  3. Add a row in the supabase table
  4. Bring the app to the foreground
  5. Add a row in the supabase table

Expected behavior
The stream emits a correct representation of the data.

Version:
I am on MacOS

dart pub deps | grep -E "supabase|gotrue|postgrest|storage_client|realtime_client|functions_client"
│   ├── supabase_flutter 2.0.0-dev.1
│   │   ├── supabase 2.0.0-dev.1
│   │   │   ├── functions_client 2.0.0-dev.0
│   │   │   ├── gotrue 2.0.0-dev.0
│   │   │   ├── postgrest 2.0.0-dev.0
│   │   │   ├── realtime_client 2.0.0-dev.1
│   │   │   ├── storage_client 2.0.0-dev.0
@vkammerer vkammerer added the bug Something isn't working label Nov 12, 2023
@dshukertjr dshukertjr added the realtime This issue or pull request is related to realtime label Nov 13, 2023
@dippa-1
Copy link

dippa-1 commented Jan 20, 2024

Thanks for testing this, as I was wondering what the behaviour in this case is.

How have you fixed it?
I assume the solution is, in the case of Flutter, to add a life cycle state listener and when the app is in foreground again, refetch the data of all streams again.

Just to be sure: I assume that the stream behaves the same as an on change listener, right?

@vkammerer
Copy link
Author

vkammerer commented Jan 21, 2024

@dippa-1 I haven't fixed it, instead I decided not to use supabase for now. It should be not the responsibility of the user of this library to fix it, I guess that the supabase team is aware of that and plans to address this issue some time in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working realtime This issue or pull request is related to realtime
Projects
None yet
Development

No branches or pull requests

3 participants