Skip to content

Commit

Permalink
fix(no-ssr): only throw on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 7, 2023
1 parent c79edfe commit a4164ea
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/no-ssr/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/** @see https://foxact.skk.moe/no-ssr */
export const noSSR = (extraMessage?: string) => {
const error = new Error(extraMessage);
if (typeof window === 'undefined') {
const error = new Error(extraMessage);

// Next.js marks errors with `NEXT_DYNAMIC_NO_SSR_CODE` digest as recoverable:
// https://github.com/vercel/next.js/blob/ded28edeae16f8f8b4b9b117a83b5232e3623029/packages/next/src/client/on-recoverable-error.ts#L3
(error as any).digest = 'NEXT_DYNAMIC_NO_SSR_CODE';
// Next.js marks errors with `NEXT_DYNAMIC_NO_SSR_CODE` digest as recoverable:
// https://github.com/vercel/next.js/blob/ded28edeae16f8f8b4b9b117a83b5232e3623029/packages/next/src/client/on-recoverable-error.ts#L3
(error as any).digest = 'NEXT_DYNAMIC_NO_SSR_CODE';

(error as any).recoverableError = 'NO_SSR';
(error as any).recoverableError = 'NO_SSR';

throw error;
throw error;
}
};

0 comments on commit a4164ea

Please sign in to comment.