diff --git a/.changeset/twelve-books-glow.md b/.changeset/twelve-books-glow.md new file mode 100644 index 00000000000..00cf468da95 --- /dev/null +++ b/.changeset/twelve-books-glow.md @@ -0,0 +1,5 @@ +--- +"@clerk/nextjs": patch +--- + +Bug fix: Handle `nextGetStore.getStore()` returning `undefined`. Previously a TypeError would occur, when `pagePath` was accessed. diff --git a/packages/nextjs/src/server/nextFetcher.ts b/packages/nextjs/src/server/nextFetcher.ts index dc74668df65..7a73ade19cd 100644 --- a/packages/nextjs/src/server/nextFetcher.ts +++ b/packages/nextjs/src/server/nextFetcher.ts @@ -5,7 +5,7 @@ type Fetcher = typeof globalThis.fetch; */ type NextFetcher = Fetcher & { readonly __nextPatched: true; - readonly __nextGetStaticStore: () => { getStore: () => StaticGenerationAsyncStorage }; + readonly __nextGetStaticStore: () => { getStore: () => StaticGenerationAsyncStorage | undefined }; }; /** diff --git a/packages/nextjs/src/server/protect.ts b/packages/nextjs/src/server/protect.ts index 8e6a73a5a9f..0d9721aa8cd 100644 --- a/packages/nextjs/src/server/protect.ts +++ b/packages/nextjs/src/server/protect.ts @@ -134,7 +134,7 @@ const isAppRouterInternalNavigation = (req: Request) => const isPagePathAvailable = () => { const __fetch = globalThis.fetch; - return Boolean(isNextFetcher(__fetch) ? __fetch.__nextGetStaticStore().getStore().pagePath : false); + return Boolean(isNextFetcher(__fetch) ? __fetch.__nextGetStaticStore().getStore()?.pagePath : false); }; const isPagesRouterInternalNavigation = (req: Request) => !!req.headers.get(nextConstants.Headers.NextjsData);