Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-server/src/features/request-context/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "virtual:inject-async-local-storage";

// we don't require async hooks and fallbacks to sync context
// (see virtual:inject-async-local-storage)

Expand Down
7 changes: 5 additions & 2 deletions packages/react-server/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ export function vitePluginReactServer(
}),
createVirtualPlugin(
ENTRY_SERVER_WRAPPER.slice("virtual:".length),
// the first import doesn't necessarily guarantee the execution order depending on chunking.
// so, we also have it on packages/react-server/src/features/request-context/utils.ts.
// TODO: this might not be enough for React.cache
() => `
import "virtual:inject-async-local-storage";
export { handler } from "${entryServer}";
Expand All @@ -373,8 +376,8 @@ export function vitePluginReactServer(
),
// make `AsyncLocalStorage` available globally for React.cache from edge build
// https://github.com/facebook/react/blob/f14d7f0d2597ea25da12bcf97772e8803f2a394c/packages/react-server/src/forks/ReactFlightServerConfig.dom-edge.js#L16-L19
createVirtualPlugin("inject-async-local-storage", () => {
if (options?.noAsyncLocalStorage) {
createVirtualPlugin("inject-async-local-storage", function () {
if (this.environment.name !== "rsc" || options?.noAsyncLocalStorage) {
return "export {}";
}
return `
Expand Down