Skip to content

Commit

Permalink
fix(nextjs): Check before using window identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed May 23, 2024
1 parent b71dae6 commit 539e534
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/src/app-router/client/useAwaitablePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useAwaitablePush = () => {
const router = useRouter();

return useInternalNavFun({
windowNav: window?.history.pushState.bind(window.history),
windowNav: typeof window !== 'undefined' ? window.history.pushState.bind(window.history) : undefined,
routerNav: router.push.bind(router),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useAwaitableReplace = () => {
const router = useRouter();

return useInternalNavFun({
windowNav: window?.history.replaceState.bind(window.history),
windowNav: typeof window !== 'undefined' ? window.history.replaceState.bind(window.history) : undefined,
routerNav: router.replace.bind(router),
});
};
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/client/useInternalNavFun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ declare global {
}

export const useInternalNavFun = (props: {
windowNav: typeof window.history.pushState | typeof window.history.replaceState;
windowNav: typeof window.history.pushState | typeof window.history.replaceState | undefined;
routerNav: AppRouterInstance['push'] | AppRouterInstance['replace'];
}) => {
const { windowNav, routerNav } = props;
const pathname = usePathname();
const [isPending, startTransition] = useTransition();

if (typeof window !== 'undefined') {
if (windowNav) {
window.__clerk_internal_navFun = (to, opts) => {
return new Promise<void>(res => {
if (!window.__clerk_internal_navPromisesBuffer) {
Expand Down

0 comments on commit 539e534

Please sign in to comment.