-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(no-ssr): only throw on the server
- Loading branch information
Showing
1 changed file
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |