Skip to content

Commit

Permalink
Import Next's CJS AsyncLocalStorage modules (vercel/turborepo#3634)
Browse files Browse the repository at this point in the history
The node evaluation always renders with `type: "commonjs"` and `require()` calls, so we'll always import the CJS files. But here we're importing the ESM files. That means we have 2 distinct instances of `requestAsyncStorage` in our node instance, and they cannot properly communicate with the other.

Fixes WEB-543
  • Loading branch information
jridgewell authored Feb 6, 2023
1 parent 38c78b6 commit 9694fc4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ async function runOperation(renderData: RenderData) {
body = result.toUnchunkedString();
}
return {
headers: [["Content-Type", result.contentType() ?? MIME_TEXT_HTML_UTF8]],
headers: [
["Content-Type", result.contentType() ?? MIME_TEXT_HTML_UTF8],
] as [string, string][],
body,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export { default as AppRouter } from "next/dist/client/components/app-router.js"
export { default as LayoutRouter } from "next/dist/client/components/layout-router.js";
export { default as RenderFromTemplateContext } from "next/dist/client/components/render-from-template-context.js";
export { default as GlobalError } from "next/dist/client/components/error-boundary.js";
export { staticGenerationAsyncStorage } from "next/dist/esm/client/components/static-generation-async-storage.js";
export { requestAsyncStorage } from "next/dist/esm/client/components/request-async-storage.js";
import * as serverHooks from "next/dist/esm/client/components/hooks-server-context.js";
export { staticGenerationAsyncStorage } from "next/dist/client/components/static-generation-async-storage.js";
export { requestAsyncStorage } from "next/dist/client/components/request-async-storage.js";
import * as serverHooks from "next/dist/client/components/hooks-server-context.js";
export { serverHooks };
export { renderToReadableStream } from "next/dist/compiled/react-server-dom-webpack/server.browser";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare const PAGE: string;

import { adapter, enhanceGlobals } from "next/dist/esm/server/web/adapter";
import { adapter, enhanceGlobals } from "next/dist/server/web/adapter";

enhanceGlobals();

Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/next-core/js/types/modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "next/dist/esm/client/components/static-generation-async-storage.js";
declare module "next/dist/esm/client/components/request-async-storage.js";
declare module "next/dist/esm/client/components/hooks-server-context.js";
declare module "next/dist/client/components/static-generation-async-storage.js";
declare module "next/dist/client/components/request-async-storage.js";
declare module "next/dist/client/components/hooks-server-context.js";
declare module "next/dist/compiled/react-server-dom-webpack/server.browser";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { cookies } from "next/headers";

export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>
{JSON.stringify(cookies(), null, 2)}
{children}
</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test from "./test";

export default function Page() {
return (
<div>
<Test />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { useEffect } from "react";

export default function Test() {
useEffect(() => {
import("@turbo/pack-test-harness").then(() => {
it("should run", () => {});
});
return () => {};
}, []);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
};

0 comments on commit 9694fc4

Please sign in to comment.