-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto register server components and immediately hydrate stores
- Loading branch information
1 parent
eac7745
commit 517d389
Showing
13 changed files
with
566 additions
and
45 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
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,23 @@ | ||
import * as React from 'react'; | ||
import RSDWClient from 'react-server-dom-webpack/client'; | ||
|
||
if (!('use' in React)) { | ||
throw new Error('React.use is not defined. Please ensure you are using React 18.3.0-canary-670811593-20240322 or later to use server components.'); | ||
} | ||
|
||
// It's not the exact type, but it's close enough for now | ||
type Use = <T>(promise: Promise<T>) => T; | ||
const { use } = React as { use: Use }; | ||
|
||
const renderCache: Record<string, Promise<unknown>> = {}; | ||
|
||
const fetchRSC = ({ componentName }: { componentName: string }) => { | ||
if (!renderCache[componentName]) { | ||
renderCache[componentName] = RSDWClient.createFromFetch(fetch(`/rsc/${componentName}`)); | ||
} | ||
return renderCache[componentName]; | ||
} | ||
|
||
const RSCClientRoot = ({ componentName }: { componentName: string }) => use(fetchRSC({ componentName })); | ||
|
||
export default RSCClientRoot; |
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
Oops, something went wrong.