diff --git a/packages/next/src/build/utils.ts b/packages/next/src/build/utils.ts index 7999bd21438f2..36eb8b3d54651 100644 --- a/packages/next/src/build/utils.ts +++ b/packages/next/src/build/utils.ts @@ -1386,6 +1386,7 @@ export async function buildAppStaticPaths({ ComponentMod.staticGenerationAsyncStorage, { page, + url: undefined, renderOpts: { incrementalCache, supportsDynamicHTML: true, diff --git a/packages/next/src/client/components/static-generation-async-storage.external.ts b/packages/next/src/client/components/static-generation-async-storage.external.ts index f426f7ff8f52d..ae72c953b6ab7 100644 --- a/packages/next/src/client/components/static-generation-async-storage.external.ts +++ b/packages/next/src/client/components/static-generation-async-storage.external.ts @@ -19,20 +19,25 @@ export interface StaticGenerationStore { /** * The URL of the request. This only specifies the pathname and the search - * part of the URL. + * part of the URL. This is `undefined` when generating static paths (ie, we + * do not know the current URL because we're invoking the function to generate + * the pathnames). */ - readonly url?: { - /** - * The pathname of the requested URL. - */ - readonly pathname: string - - /** - * The search part of the requested URL. If the request did not provide a - * search part, this will be undefined. - */ - readonly search?: string - } + readonly url: + | { + /** + * The pathname of the requested URL. + */ + readonly pathname: string + + /** + * The search part of the requested URL. If the request did not provide a + * search part, this will be undefined. + */ + readonly search?: string + } + | undefined + readonly incrementalCache?: IncrementalCache readonly isOnDemandRevalidate?: boolean readonly isPrerendering?: boolean diff --git a/packages/next/src/server/async-storage/static-generation-async-storage-wrapper.ts b/packages/next/src/server/async-storage/static-generation-async-storage-wrapper.ts index 1d28c20d21736..dddc1b54ce49f 100644 --- a/packages/next/src/server/async-storage/static-generation-async-storage-wrapper.ts +++ b/packages/next/src/server/async-storage/static-generation-async-storage-wrapper.ts @@ -15,20 +15,23 @@ export type StaticGenerationContext = { /** * The URL of the request. This only specifies the pathname and the search - * part of the URL. + * part of the URL. This is only undefined when generating static paths (ie, + * there is no request in progress, nor do we know one). */ - url?: { - /** - * The pathname of the requested URL. - */ - pathname: string + url: + | { + /** + * The pathname of the requested URL. + */ + pathname: string - /** - * The search part of the requested URL. If the request did not provide a - * search part, this will be an empty string. - */ - search?: string - } + /** + * The search part of the requested URL. If the request did not provide a + * search part, this will be an empty string. + */ + search?: string + } + | undefined requestEndedState?: { ended?: boolean } renderOpts: { incrementalCache?: IncrementalCache