Skip to content

Commit

Permalink
fix(nextjs): Handle __nextGetStaticStore returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Aug 13, 2024
1 parent b6f0613 commit 5a90f37
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-books-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nextjs": patch
---

Bug fix: Handle `nextGetStore.getStore()` returning `undefined`. Previously a TypeError would occur, when `pagePath` was accessed.
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/nextFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Fetcher = typeof globalThis.fetch;
*/
type NextFetcher = Fetcher & {
readonly __nextPatched: true;
readonly __nextGetStaticStore: () => { getStore: () => StaticGenerationAsyncStorage };
readonly __nextGetStaticStore: () => { getStore: () => StaticGenerationAsyncStorage | undefined };
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5a90f37

Please sign in to comment.