-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
45b51a6
commit de85fb4
Showing
14 changed files
with
575 additions
and
54 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.