Skip to content
Open
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
12 changes: 9 additions & 3 deletions packages/vinext/src/entries/app-rsc-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ ${
} from ${JSON.stringify(appRouteHandlerResponsePath)};`
: ""
}
const __loadAppRouteHandlerDispatch = () => import(${JSON.stringify(appRouteHandlerDispatchPath)});
let __dispatchAppRouteHandlerFn;
const __loadAppRouteHandlerDispatch = async () => {
if (__dispatchAppRouteHandlerFn) return __dispatchAppRouteHandlerFn;
const { dispatchAppRouteHandler } = await import(${JSON.stringify(appRouteHandlerDispatchPath)});
__dispatchAppRouteHandlerFn = dispatchAppRouteHandler;
return __dispatchAppRouteHandlerFn;
};
${
hasServerActions
? `const __loadAppServerActionExecution = () => import(${JSON.stringify(appServerActionExecutionPath)});`
Expand Down Expand Up @@ -947,8 +953,8 @@ export default createAppRscHandler({
route,
searchParams,
}) {
const { dispatchAppRouteHandler: __dispatchAppRouteHandler } =
await __loadAppRouteHandlerDispatch();
const __dispatchAppRouteHandler =
__dispatchAppRouteHandlerFn ?? (await __loadAppRouteHandlerDispatch());
return __dispatchAppRouteHandler({
basePath: __basePath,
cleanPathname,
Expand Down
8 changes: 6 additions & 2 deletions tests/entry-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,13 @@ describe("App Router entry templates", () => {
it("generateRscEntry defers route-handler and server-action runtimes", () => {
const code = generateRscEntry("/tmp/test/app", minimalAppRoutes, null, [], null, "", false);

expect(code).toContain('const __loadAppRouteHandlerDispatch = () => import("');
expect(code).toContain("let __dispatchAppRouteHandlerFn;");
expect(code).toContain("const __loadAppRouteHandlerDispatch = async () => {");
expect(code).toContain('const { dispatchAppRouteHandler } = await import("');
expect(code).toContain('const __loadAppServerActionExecution = () => import("');
expect(code).toContain("await __loadAppRouteHandlerDispatch()");
expect(code).toContain(
"__dispatchAppRouteHandlerFn ?? (await __loadAppRouteHandlerDispatch())",
);
expect(code).toContain("await __loadAppServerActionExecution()");
expect(code).not.toMatch(/import \{\s*dispatchAppRouteHandler as __dispatchAppRouteHandler,/);
expect(code).not.toMatch(
Expand Down
Loading