You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm migrating a project from React to Preact and I noticed a weird difference in prepass during SSR. I know Preact is not guaranteed to be fully compatible with React, so maybe this is not a bug at all :)
But looks like ref values get lost when using Suspense on SSR. Take this component as an example:
constApp=()=>{constinitialised=useRef(false);console.log("initialised",initialised.current);if(!initialised.current){initialised.current=true;}const[{ data }]=useQuery({query: ` { country(code: "HU") { name } } `});return<span>{data.country.name}</span>;};
What happens here is when the component is getting rendered in prepass:
Component sets initialised ref to true (it's false by default)
useQuery uses Suspense, so it throws a promise while it's fetching
Once the promise is resolved, the component gets rendered again
initialised ref value got lost, it's false again (with React it's still true)
After taking a deeper look into react-ssr-prepass and react when it comes to Suspense I've found the following to be the case:
When React suspends on initial mount it will erase hookState in progress and retain hookState on subsequent Suspensions.
React-ssr-prepass keeps hookState around so one of the assumptions we do in compat doesn't hold up
I'm migrating a project from React to Preact and I noticed a weird difference in prepass during SSR. I know Preact is not guaranteed to be fully compatible with React, so maybe this is not a bug at all :)
But looks like ref values get lost when using Suspense on SSR. Take this component as an example:
What happens here is when the component is getting rendered in prepass:
initialised
ref totrue
(it'sfalse
by default)useQuery
uses Suspense, so it throws a promise while it's fetchinginitialised
ref value got lost, it'sfalse
again (with React it's stilltrue
)To Reproduce (with Preact)
Sandbox with Preact: https://codesandbox.io/s/preact-ref-bug-preact-lswel?file=/src/App.js
The output is:
Expected behaviour (with React)
Sandbox with React: https://codesandbox.io/s/preact-ref-bug-react-h6ukj?file=/src/App.js
The output is:
Let me know if you need more details!
The text was updated successfully, but these errors were encountered: