morrys / react-relay-offline

TypeScript library files for Relay Modern Offline
https://morrys.github.io/react-relay-offline/docs/react-relay-offline.html
MIT License
227 stars 15 forks source link

react-relay-offline useRestore & state reconciliation #33

Open morrys opened 4 years ago

morrys commented 4 years ago

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 />;
   }

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.

w01fgang commented 3 years ago

the first renderer is executed by setting the store-only policy

If there is a non-nullable field in the query and it doesn't exist, will the application crash?

morrys commented 3 years ago

Hi @w01fgang, if during the first rendered application the store is empty, the queryrender returns the same result as when the queryrender is loading

morrys commented 1 year ago

hi @bglgwyng, I put the reference to your issue here which seems more appropriate to me. For the moment I would avoid adding other components inside the library, I would prefer as soon as I have time to update the library to the latest version of relay-hooks and relay-runtime The important thing is to understand how to use the restore and use it in the most appropriate way. https://github.com/morrys/wora/issues/138#issue-1809008096

Thanks for the tip 💯

bglgwyng commented 1 year ago

I completely agree that the addition of this feature requires careful consideration. I believe we might not even require the useRestore at all. The provided example code for restoring seems sufficient. In my opinion, the current behavior of useRestore with an updatable Relay environment (using useMemo) appears a bit buggy. This might be due to the inclusion of useState inside useRestore. Perhaps allowing programmers to handle the restore logic themselves would be clearer and result in fewer issues.