-
Notifications
You must be signed in to change notification settings - Fork 323
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
Update React experimental version #758
Conversation
I did a deep-dive on this and narrowed it down to an issue with React trying to
To isolate and reproduce, replace import renderHydrogen from '@shopify/hydrogen/entry-server';
import {ShopifyProvider, useShopQuery} from '@shopify/hydrogen';
import {Suspense} from 'react';
import shopifyConfig from '../shopify.config';
function App() {
return (
<ShopifyProvider shopifyConfig={shopifyConfig}>
<p>Hello:</p>
<Suspense fallback="Loading shop name...">
<ShopName />
</Suspense>
</ShopifyProvider>
);
}
function ShopName() {
const {
data: {
shop: {name},
},
} = useShopQuery({query: `query ShopName { shop { name }}`});
return <p>{name}</p>;
}
const pages = import.meta.globEager('./pages/**/*.server.[jt](s|sx)');
export default renderHydrogen(App, {pages}); And disable writing RSC script chunks in // bufferReadableStream(rscToScriptTagReadable.getReader(), (chunk) => {
// log.trace('rsc chunk');
// return response.write(chunk);
// }); And fix an issue in if (typeof __flight !== 'undefined' && __flight && __flight.length > 0) { What happens is:
Screen.Recording.2022-02-25.at.3.49.46.PM.movWhat I've tried
|
Thanks a lot for checking it, Josh! I couldn't find a workaround either. I guess we will need to report it in React repo and see if they have some pointers. |
If you add the onRecoverableError option does it tell you where the mismatch is occurring? Also if you go before this PR facebook/react#22629 the flickering would go away. |
@salazarm I don't think it gives us much information:
|
In DEV, If you check the properties of the Error object can you see a |
I don't see |
This error happens when there's a synchronous update during hydration. This can happen in a few different ways, but the most common one is if when something calls setState inside of useLayoutEffect. That will cause everything below that component to synchronously finish. Not sure if that's what's happening in your case, but having seen this many times before I'd say it's likely. We don't currently track expose information about which update caused the synchronous re-render. DevTools is working on a feature that does this, though. @bvaughn Did the "update tracking" feature ship yet? Is there some way we could try it out to debug this issue? In the meantime, I would check for updates inside useLayoutEffect because that's often what this ends up being. |
Thanks for helping here!
Afaik, we don't use However, I found something similar to what you described: Shopify/hydrogen@453e2ef (I guess we could use This change fixed the |
The "legacy" Profiler shows which Fiber(s) scheduled a commit using the The new Timeline profiler could also be helpful here as it shows state updates and the name of the component scheduling the update (unfortunately not the component stack, yet) in context with other info (like JS call stack). That's also available if you're using the latest DevTools and the 18 RC. |
@salazarm @acdlite It looks like I was under the impression that I've downgraded to |
Hi all, hydration changed in experimental React 18 versions about a month ago completely. What you describe here looks very similar to an issue we recently opened here. facebook/react#23381 |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple questions. Could you also add a changeset with instructions for upgrading to the correct new React experimental version?
examples/template-hydrogen-default/src/components/NotFound.server.jsx
Outdated
Show resolved
Hide resolved
@jplhomer Can we revisit this? There are still a few extra Suspense but in general I don't see that many mismatches or flashes anymore: https://hydrogen-rc.frandiox.workers.dev/ It's updated to the latest version released 2 days ago. I've also updated the Vite RSC plugin and everything seems to work. Can you please check? If we merge this we can start using server context 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge this since it resolves the hydration errors we're seeing in the main branch, and it gets us on the most recent experimental release.
We are still seeing Suspense errors in some places, and the temporary fix (which is in this PR) is to wrap client components with Suspense boundaries. We haven't nailed down exactly why this is happening yet. I can generally reproduce it during SSR when a server component suspends, we stream the fallback to the client, and then resolves containing other client components. If the client module references have not yet been flushed to the RSC stream (which is a bunch of script tags being interleaved in the SSR stream in our implementation), this causes a hydration error. This seems to align with our fix of wrapping those client components with suspense boundaries.
It's difficult to get this into a standalone repro, but I'll try to get something to you soon to look at @acdlite and @salazarm! Appreciate your help in this PR ❤️
Description
This PR upgrades to Hydrogen to the latest version of React experimental. This includes the latest changes to the Fizz streaming SSR API. It also includes server context, which has an impact on our pseudo server-only-context utilities.
We need to add these Suspense boundaries to prevent this hydration error:
I'm tracking this issue in #920 so we can resolve it later.
Before submitting the PR, please make sure you do the following:
yarn changeset add
to update the changelog, if neededfixes #123
)