Skip to content

Reinitialize streaming updates after store persist rehydration #2545

Closed
@uloco

Description

@uloco

We are in a react native app and need to persist the api data to make it possible to use the app when being offline.
After fetching the data with a query, a graphql subscription is established to get streaming updates from the api, which will only deliver incremental changes.

I did implement this as described in the docs via onCacheEntryCreated and update the local cache accordingly with updateCachedData and this works fine for the very initial load when the store is completely empty.
But unfortunately as we persist the data, this will only be called once. When the app restarts and data gets rehydrated, the subscription will no longer trigger.

I think this is by design but really unfortunate in our scenario.

What we basically want is

  1. call the query every time the app restarts, gets in focus or reconnects to the internet. (This is somewhat working now)
  2. connect the graphql subscription when the first call succeeds.

How would you deal with this scenario?

Sidenote

I also followed your docs about Persistance and Rehydration and added the extractRehydrationInfo as described, but I am not quite sure what this does, as the whole redux state is rehydrated anyway including the whole api slice.

Though we are not using redux-persist but redux-storage, but I don't think this should matter.

We do not persist the subscriptions object in the api slice though, since this causes a memory leak increasing cache subscriptions with every restart and refetchOnMountOrArgChange not working properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions