Changes to Support Meta's RSC implementation #445
Replies: 3 comments 6 replies
-
Some components that are using |
Beta Was this translation helpful? Give feedback.
-
Thanks for starting this @blittle ! About changes in entry-client and entry-serverI like the concept of function ClientApp({children}) {
return children;
} Couldn't this be added to Side comment about the Also, can't we run React Router+1 for removing it from the client as well if we just need the Link. Caching
I like this approach more than passing As you know, we could use the server-only context we have in #390 instead. The main problems are:
Therefore, perhaps we should go with your proposed approach first until the previous issues are clarified, at least. If we eventually rely on this server-only context, perhaps using ReadableStreamThere's a feature flag that can be enabled in CFW right now to use the current implemented version of ReadableStream. With this flag, SSR and RSC won't be streamed (CFW does not support |
Beta Was this translation helpful? Give feedback.
-
Our team is currently prototyping the use of Hydrogen in an app that relies on this ability to dynamically set the We think this ability to dynamically set storefronts at 'runtime' is really valuable but we want to make sure we're not going against Hydrogen's design philosophy by doing this. Is Hydrogen meant for only one static storefront? |
Beta Was this translation helpful? Give feedback.
-
TLDR: Meta's React Server Component implementation doesn't yet support context within server components. This is temporary until a new API is introduced by React. Until then, any hook or component that depends on a context within a server component has been removed. These changes have been implemented in the draft PR: Shopify/hydrogen#317
Right now Hydrogen uses a custom React Server Components (RSC) implementation. We'd like to switch to the Meta's RSC version for Hydrogen's 1.0 release. Doing so means a number of breaking changes to the framework:
App.server.jsx
All Providers have been removed from
App.server.jsx
within the starter template. Instead there is a newApp.client.jsx
component. That client component contains the context providers that are used in downstream client components. By default this is justHelmetProvider
andCartProvider
. If a merchant introduced a custom context provider into theirApp.server.jsx
component, it will need to be moved toApp.client.jsx
.NOTE: No downstream server component will have access to the contexts provided within App.client.jsx
ShopifyProvider
ShopifyProvider
contains only the configuration data about the current storefront fromshopify.config.js
.This data is static, and doesn't change after hydrogen boots. Instead of the provider, call
setShopifyConfig
withthe data from
shopify.config.js
. This needs to be done in both entry-server.jsx and entry-client.jsx:entry-client.jsx:
entry-server.jsx:
ReactHelmet
Provider still is used, but only in client components. The provider is setup within
App.client.jsx
.ReactRouter
React Router is no longer used on the server. This means you can no longer use React Router hooks to get at param variables. Params are now passed as a prop to the top level server component. Those params have to be passed as a prop to every component that might depend on them.
The client still uses React Router, though only for the Link component. I don't think that necessitates using React Router anymore at all. I propose we re-implement the Link component and remove React Router altogether.
Caching
Caching requests on the server (
useQuery
anduseShopQuery
) currently relies on context. The current cache is unique per request. That cache isolated per request by context. This has to be removed. In order to maintain the request/cache isolation, I propose that we pass auseQuery
anduseShopQuery
prop to the root server component. Any server component that wants to fetch data would need to use those functions, instead of importing it.This has the side effect of automatically making
useQuery
anduseShopQuery
only accessible in server components, because you cannot pass functions from server components to client components.Note: the branch works right now with the context removed, but the caching is shared across all requests
ReadableStream
Official RSC needs either Node APIs or the Web Standard ReadableStream to work. Not all edge workers have implemented the ReadableStream API.
Beta Was this translation helpful? Give feedback.
All reactions