Skip to content

react-relay-offline useRestore & state reconciliation #33

Description

@morrys

the useRestore hook allows you to manage the restore of data persisted in the storage.
To be used if relay components are used outside of the QueryRenderer or for web applications without SSR & react-native (

const isRehydrated = useRestore(environment);
   if (!isRehydrated) {
     return <Loading />;
   }
  • Example of what happens when using the useQuery/QueryRenderer without useRestore:

  • Example of what happens when using the useQuery/QueryRenderer with useRestore:

    • the application shows a loading and does not render the useQuery component until it is rehydrated
    • if the application is online, the original policy is used and the execute of the QueryFetcher is performed
    • if the application is offline, the policy used will be store-only and the execute will look for the data in the store
  • Example of what happens when you use the useQuery/QueryRenderer without useRestore in SSR applications:

    • the first renderer is executed by setting the store-only policy
    • the store is not empty (having initialized the store with the data recovered from the server. The data recovered from the store will be displayed
    • the state is reconciled between the initial one (recovered from the server) and the state present in the storage, this makes a notification in the store that forces the updating of all the fragments subscribed
    • the restore is resolved (https://github.com/morrys/react-relay-offline/blob/master/src/hooks/useQueryOffline.ts#L59) and the forceUpdate is not executed as data are already displayed previously (priority is given to displaying data returned by status reconciliation)
  • In applications with SSR the useRestore should never be used

With the proposed change in relay-hooks, it will be possible to avoid using the useRestore as it will always be possible to perform a forced execution of the QueryFetcher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions