-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement RSC using react-server and react-client (#317)
* wip: Create custom flight renderer with local version of react-server * wip: mock client manifest and add module reference to client components * wip: hack RSC resolution * wip: wrap component in Proxy to access original properties * refactor: rename RSC server files * wip: add official RSC hydrator * fix: Rename response.readRoot and remove explicit hydration * wip: remove RR and Helmet providers from the server * wip: Add test app * wip: remove hydration providers * wip: add renderToReadableStream for RSC * refactor: cleanup custom RSC code * refactor: move and rename files * wip: fix test app * refactor: cleanup custom RSC code * refactor: do not pass named boolean in RSC * refactor: simplify ClientMarker * test: fix ClientMarker tests * fix: delay throwing error when client component is missing * refactor: simplify import globs code * feat: provide request object to rendering tree * wip: example of useServerRequest * feat: inline RSC response in the SSR HTML response * fix: add default value to the SSR provider * feat: stream rsc in script tags * feat: update the starter template to work * fix: lint errors * refactor: move code around and cleanup * chore: upgrade Vite to 2.7.0 * chore: add react-server-dom-vite as vendor * feat: replace local react-server and react-client with react-server-dom-vite vendor * fix: react-server-dom-vite allow exporting hooks from client components temporarily * fix: move the server logging locations * feat: Implement ReadableStream branch in SSR and RSC * test: fix playground apps * fix: avoid importing undefined exports depending on the running environment * feat: Buffer RSC response if it cannot be streamed * fix: tests * fix: e2e test * fix: linting * fix: rename test helper * fix: update hydrogen template files * feat: remove react-ssr-prepass. RSC already makes ReadableStream required * refactor: simplify hydration calls * feat: remove old dependencies * feat: enable tree shaking in worker build * fix: Release stream lock before piping * chore: fix formatting * refactor: move code to entry-server to be consistent * refactor: remove HydrationWriter in favor of Node native PassThrough * fix: move constant to a separate file to avoid importing app logic in GraphiQL * refactor: remove old code * fix: maybe fix tests for windows * fix: stream import in workers * fix: flush RSC right after writing head * feat: replace RenderCacheProvider with new ServerRequestProvider cache * refactor: cleanup * fix: suspense breaking hydration * fix: normalize RSC chunks * refactor: simplify customBody check * feat: minor tree-shaking improvements * fix: enable browser hydration * fix: replace TransformStream with ReadableStream to support Firefox * refactor: cleanup and rename variables * fix: normalizePath * fix: better regex * fix: request.context property is reserved in CFW * perf: Do not clone request to avoid extra memory and warnings in CFW * chore: add TODO to remove weird Suspense boundary * fix: Add back ShopifyProvider; call setShopConfig as part of renderHydrogen * chore: remove RSCTest demo code * fix: useMemo is allowed in RSC * fix: Dot not create Response with streams to support CFW Co-authored-by: Bret Little <[email protected]> Co-authored-by: M. Bagher Abiat <[email protected]> Co-authored-by: Josh Larson <[email protected]>
- Loading branch information
1 parent
9ac6d03
commit d8c87eb
Showing
132 changed files
with
8,313 additions
and
2,413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
import {ShopifyServerProvider, DefaultRoutes} from '@shopify/hydrogen'; | ||
import {Switch} from 'react-router-dom'; | ||
import {DefaultRoutes} from '@shopify/hydrogen'; | ||
import {Suspense} from 'react'; | ||
|
||
import shopifyConfig from '../shopify.config'; | ||
|
||
import DefaultSeo from './components/DefaultSeo.server'; | ||
import NotFound from './components/NotFound.server'; | ||
import CartProvider from './components/CartProvider.client'; | ||
import AppClient from './App.client'; | ||
import LoadingFallback from './components/LoadingFallback'; | ||
|
||
export default function App({log, ...serverState}) { | ||
const pages = import.meta.globEager('./pages/**/*.server.[jt]sx'); | ||
|
||
return ( | ||
<Suspense fallback={<LoadingFallback />}> | ||
<ShopifyServerProvider shopifyConfig={shopifyConfig} {...serverState}> | ||
<CartProvider> | ||
<DefaultSeo /> | ||
<Switch> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</Switch> | ||
</CartProvider> | ||
</ShopifyServerProvider> | ||
<AppClient helmetContext={serverState.helmetContext}> | ||
<DefaultSeo /> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</AppClient> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import renderHydrogen from '@shopify/hydrogen/entry-client'; | ||
import {ShopifyProvider} from '@shopify/hydrogen/client'; | ||
|
||
import shopifyConfig from '../shopify.config'; | ||
|
||
function ClientApp({children}) { | ||
return ( | ||
<ShopifyProvider shopifyConfig={shopifyConfig}>{children}</ShopifyProvider> | ||
); | ||
return children; | ||
} | ||
|
||
export default renderHydrogen(ClientApp); | ||
export default renderHydrogen(ClientApp, {shopifyConfig}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import renderHydrogen from '@shopify/hydrogen/entry-server'; | ||
import shopifyConfig from '../shopify.config'; | ||
|
||
import App from './App.server'; | ||
|
||
export default renderHydrogen(App, () => { | ||
// Custom hook | ||
}); | ||
export default renderHydrogen(App, {shopifyConfig}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
examples/template-hydrogen-default/src/pages/pages/[handle].server.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
examples/template-hydrogen-default/src/pages/products/[handle].server.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {HelmetProvider} from '@shopify/hydrogen/client'; | ||
import CartProvider from './components/CartProvider.client'; | ||
|
||
/** | ||
* Setup client context, though the children are most likely server components | ||
*/ | ||
export default function ClientApp({helmetContext, children}) { | ||
return ( | ||
<HelmetProvider helmetContext={helmetContext}> | ||
<CartProvider>{children}</CartProvider> | ||
</HelmetProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
import {ShopifyServerProvider, DefaultRoutes} from '@shopify/hydrogen'; | ||
import {Switch} from 'react-router-dom'; | ||
import {DefaultRoutes} from '@shopify/hydrogen'; | ||
import {Suspense} from 'react'; | ||
|
||
import shopifyConfig from '../shopify.config'; | ||
|
||
import DefaultSeo from './components/DefaultSeo.server'; | ||
import NotFound from './components/NotFound.server'; | ||
import CartProvider from './components/CartProvider.client'; | ||
import AppClient from './App.client'; | ||
import LoadingFallback from './components/LoadingFallback'; | ||
|
||
export default function App({log, ...serverState}) { | ||
const pages = import.meta.globEager('./pages/**/*.server.[jt]sx'); | ||
|
||
return ( | ||
<Suspense fallback={<LoadingFallback />}> | ||
<ShopifyServerProvider shopifyConfig={shopifyConfig} {...serverState}> | ||
<CartProvider> | ||
<DefaultSeo /> | ||
<Switch> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</Switch> | ||
</CartProvider> | ||
</ShopifyServerProvider> | ||
<AppClient helmetContext={serverState.helmetContext}> | ||
<DefaultSeo /> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</AppClient> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import renderHydrogen from '@shopify/hydrogen/entry-client'; | ||
import {ShopifyProvider} from '@shopify/hydrogen/client'; | ||
|
||
import shopifyConfig from '../shopify.config'; | ||
|
||
function ClientApp({children}) { | ||
return ( | ||
<ShopifyProvider shopifyConfig={shopifyConfig}>{children}</ShopifyProvider> | ||
); | ||
return children; | ||
} | ||
|
||
export default renderHydrogen(ClientApp); | ||
export default renderHydrogen(ClientApp, {shopifyConfig}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import renderHydrogen from '@shopify/hydrogen/entry-server'; | ||
import shopifyConfig from '../shopify.config'; | ||
|
||
import App from './App.server'; | ||
|
||
export default renderHydrogen(App, () => { | ||
// Custom hook | ||
}); | ||
export default renderHydrogen(App, {shopifyConfig}); |
Oops, something went wrong.