-
Notifications
You must be signed in to change notification settings - Fork 324
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
[BUG] Render cache is reset when handling multiple requests at the same time #415
Comments
I remember now! Here is the output of a page that has an iframe request to another template. What's happening is that -- sometimes -- network cancels on request and tries again (not sure where the retry logic is coming from but seems to be browser driven) Browser seems to take the last successful response . When the server gets these requests, it will try to process them. But when the connection closes, the async operation has no where to go because the associating callback functions has already been discarded. React's default behaviour is to use the default cache set in the This was the reason why I had a default cache to capture these failed requests' async operations. These cache values will never get used because they will never be bound to a |
@wizardlyhel So this is not a real issue? I'm not sure if I understand completely the network related stuff. Edit: I've tried with 2 requests from different browsers (Chrome and Safari) at the same time and I still see logs for the default cache 🙈 |
Per https://reactjs.org/docs/context.html#reactcreatecontext
Makes me think that some subsection of the app tree is being re-rendered outside of the scope of the provider with the value. Might be related to R18 streaming, or concurrent requests. I'm curious what other global JS state (shared between requests in Vite dev server) might be affecting this?
Can we reproduce it in e.g. https://github.com/jplhomer/vite-streaming-ssr-demo ? |
Okay back to square one ... I rechecked the code I had and found some errors with it .. not related to this particular issue but .. it might be something we should be aware of. When streaming html into the DOM, it will request resources even if it is hidden .. for example, the iframe example I had:
This can happen as many times as streaming needs to organize the app output. FIX: Make sure the iframe component is a client component and the This behaviour will happen to any DOM resource:
|
I'm running out of ideas to debug this |
@wizardlyhel It indeed looked like a bug in React to me. I saw React is internally pushing and popping contexts, and it looked like it was popping too much at some point. I did not find the root cause, though, so this is just an assumption. The fact that this issue is reproducible in a simpler repo also supports this... |
Re-export useMoney hook
Describe the bug
We currently use
<RenderCacheProvider>
in SSR to provide a cache where fetch promises are placed for the different rendering cycles of a request. This works with 1 request at a time but looks like it doesn't when handling multiple requests at the same time.The cache provider has an initial value that should be replaced by each request's cache. However, it looks like the context gets reset to the initial value before the rendering finishes.
To Reproduce
main
branch.foundation/RenderCacheProvider/RenderCacheContext.tsx
such as this:<RenderCacheProvider>
, which provides a new cache object for the current request.<RenderCacheProvider>
provides a new cache object per request at first, but at some point the Context gets reset to the initial value (the proxy above).Expected behaviour
The proxy should not log anything because it must be replaced by the per-request-cache from the provider.
Additional context
Optionally, remove hydration from
dev/src/entry-client.jsx
(comment outexport default renderHydrogen(...)
to make sure RSC is not triggered. The bug is with the SSR part.I found this issue while testing the SSR + RSC approach in #390 and noticed that the SSR part was buggy when handling multiple requests.
Could this be a bug in React experimental, @wizardlyhel ?
The text was updated successfully, but these errors were encountered: