reactjs / server-components-demo

Demo app of React Server Components.
https://reactjs.org/server-components
MIT License
4.27k stars 639 forks source link

useServerResponse: Infinite render when deactivating cache #34

Closed arnaudbzn closed 3 years ago

arnaudbzn commented 3 years ago

It seems that the cache usage is mandatory for this demo project. In useServerResponse, when commenting the following block of code:

  if (response) {
    return response;
  }

The app enters in a infinite loop of renders (see the screenshot attached, I've added a console log to debug).

The expected behavior is just to not use the cache and re-fetch, but there are probably other technical requirements introduced by the React Server Components architecture.

Screenshot 2020-12-27 at 16 41 06
gaearon commented 3 years ago

This is intentional. Caching is central to Suspense in general — the model is that it’s always backed by some cache. It doesn’t have to be the same cache throughout the app lifetime (we replace the cache when invalidating, for example).