diff --git a/packages/next/build/webpack/loaders/next-app-loader.ts b/packages/next/build/webpack/loaders/next-app-loader.ts index 81a52387707881a..0e428687b0b2b13 100644 --- a/packages/next/build/webpack/loaders/next-app-loader.ts +++ b/packages/next/build/webpack/loaders/next-app-loader.ts @@ -243,7 +243,7 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{ export const LayoutRouter = require('next/dist/client/components/layout-router.js').default export const RenderFromTemplateContext = require('next/dist/client/components/render-from-template-context.js').default - export const staticGenerationAsyncStorage = require('next/dist/client/components/static-generation-async-storage.js').staticGenerationAsyncStorage + export const staticGenerationAsyncStorage = require('next/dist/client/components/static-generation-async-storage').staticGenerationAsyncStorage export const requestAsyncStorage = require('next/dist/client/components/request-async-storage.js').requestAsyncStorage export const serverHooks = require('next/dist/client/components/hooks-server-context.js') diff --git a/packages/next/client/components/static-generation-async-storage/browser.ts b/packages/next/client/components/static-generation-async-storage/browser.ts new file mode 100644 index 000000000000000..3f9b9fe75d5b62a --- /dev/null +++ b/packages/next/client/components/static-generation-async-storage/browser.ts @@ -0,0 +1,13 @@ +import type { AsyncLocalStorage } from 'async_hooks' + +export interface StaticGenerationStore { + inUse?: boolean + pathname?: string + revalidate?: number + fetchRevalidate?: number + isStaticGeneration?: boolean +} + +export let staticGenerationAsyncStorage: + | AsyncLocalStorage + | StaticGenerationStore = {} diff --git a/packages/next/client/components/static-generation-async-storage.ts b/packages/next/client/components/static-generation-async-storage/node.ts similarity index 100% rename from packages/next/client/components/static-generation-async-storage.ts rename to packages/next/client/components/static-generation-async-storage/node.ts diff --git a/packages/next/client/components/static-generation-async-storage/package.json b/packages/next/client/components/static-generation-async-storage/package.json new file mode 100644 index 000000000000000..473d1d8f4b73443 --- /dev/null +++ b/packages/next/client/components/static-generation-async-storage/package.json @@ -0,0 +1,4 @@ +{ + "browser": "./browser.js", + "main": "./node.js" +} diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index ddeec17943f6ccf..b8073e4d12e23c7 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -2109,7 +2109,11 @@ export async function compile(task, opts) { ], opts ) - await task.serial(['ncc_react_refresh_utils', 'ncc_next__react_dev_overlay']) + await task.serial([ + 'ncc_react_refresh_utils', + 'ncc_next__react_dev_overlay', + 'copy_package_json', + ]) } export async function bin(task, opts) { @@ -2196,6 +2200,29 @@ export async function nextbuildjest(task, opts) { notify('Compiled build/jest files') } +export async function copy_package_json(task, opts) { + await fs.copy( + join( + __dirname, + 'client/components/static-generation-async-storage/package.json' + ), + join( + __dirname, + 'dist/client/components/static-generation-async-storage/package.json' + ) + ) + await fs.copy( + join( + __dirname, + 'client/components/static-generation-async-storage/package.json' + ), + join( + __dirname, + 'dist/esm/client/components/static-generation-async-storage/package.json' + ) + ) +} + export async function client(task, opts) { await task .source(opts.src || 'client/**/*.+(js|ts|tsx)')