mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Don't log SSR suspension error
This commit is contained in:
parent
5d90d162eb
commit
489ef8bec3
@ -34,10 +34,19 @@ export function suspend(): never {
|
||||
*/
|
||||
export function suspendIfSsr() {
|
||||
if (typeof window === "undefined") {
|
||||
throw new Error(deindent`
|
||||
This code path is not supported in SSR. This error should be caught by the closest Suspense boundary, and hence never be thrown on the client. If you still see the error, make sure the component is rendered inside a Suspense boundary.
|
||||
const error = Object.assign(
|
||||
new Error(deindent`
|
||||
This code path is not supported in SSR. This error should be caught by the closest Suspense boundary, and hence never be thrown on the client. If you still see the error, make sure the component is rendered inside a Suspense boundary.
|
||||
|
||||
See: https://react.dev/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content
|
||||
`);
|
||||
See: https://react.dev/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content
|
||||
`),
|
||||
{
|
||||
// set the digest so nextjs doesn't log the error
|
||||
// https://github.com/vercel/next.js/blob/d01d6d9c35a8c2725b3d74c1402ab76d4779a6cf/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts#L14
|
||||
digest: "BAILOUT_TO_CLIENT_SIDE_RENDERING",
|
||||
}
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@ -520,9 +520,9 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
|
||||
|
||||
static get [stackAppInternalsSymbol]() {
|
||||
return {
|
||||
fromClientJson: async <HasTokenStore extends boolean, ProjectId extends string>(
|
||||
fromClientJson: <HasTokenStore extends boolean, ProjectId extends string>(
|
||||
json: StackClientAppJson<HasTokenStore, ProjectId>
|
||||
): Promise<StackClientApp<HasTokenStore, ProjectId>> => {
|
||||
): StackClientApp<HasTokenStore, ProjectId> => {
|
||||
const existing = allClientApps.get(json.uniqueIdentifier);
|
||||
if (existing) {
|
||||
const [checkString, clientApp] = existing;
|
||||
@ -867,7 +867,7 @@ type StackClientAppConstructor = {
|
||||
[stackAppInternalsSymbol]: {
|
||||
fromClientJson<HasTokenStore extends boolean, ProjectId extends string>(
|
||||
json: StackClientAppJson<HasTokenStore, ProjectId>
|
||||
): Promise<StackClientApp<HasTokenStore, ProjectId>>,
|
||||
): StackClientApp<HasTokenStore, ProjectId>,
|
||||
},
|
||||
};
|
||||
export const StackClientApp: StackClientAppConstructor = _StackClientAppImpl;
|
||||
|
||||
@ -9,17 +9,12 @@ export const StackContext = React.createContext<null | {
|
||||
app: StackClientApp<true>,
|
||||
}>(null);
|
||||
|
||||
const fromClientJsonCached = cache((appJson: StackClientAppJson<true, string>) => StackClientApp[stackAppInternalsSymbol].fromClientJson(appJson));
|
||||
|
||||
export function StackProviderClient(props: {
|
||||
appJsonPromise: Promise<StackClientAppJson<true, string>>,
|
||||
children?: React.ReactNode,
|
||||
}) {
|
||||
const appJson = use(props.appJsonPromise);
|
||||
const appPromise = useStrictMemo(() => {
|
||||
return fromClientJsonCached(appJson);
|
||||
}, [appJson]);
|
||||
const app = use(appPromise);
|
||||
const app = StackClientApp[stackAppInternalsSymbol].fromClientJson(appJson);
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
(globalThis as any).stackApp = app;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user