Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Handle __nextGetStaticStore returning undefined #3939

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading