Fix theme error on ssr

This commit is contained in:
Zoe Roux 2024-03-17 23:16:55 +01:00
parent b6d122e449
commit 64031668c1
No known key found for this signature in database
2 changed files with 31 additions and 29 deletions

View File

@ -210,6 +210,7 @@ App.getInitialProps = async (ctx: AppContext) => {
if (typeof window !== "undefined") return { pageProps: superjson.serialize(appProps.pageProps) };
try {
const getUrl = Component.getFetchUrls;
const getLayoutUrl =
Component.getLayout && "Layout" in Component.getLayout
@ -240,7 +241,9 @@ App.getInitialProps = async (ctx: AppContext) => {
}
}
appProps.pageProps.theme = readCookie(ctx.ctx.req?.headers.cookie, "theme") ?? "auto";
} catch (e) {
console.error("SSR error, disabling it.");
}
return { pageProps: superjson.serialize(appProps.pageProps) };
};

View File

@ -62,8 +62,7 @@ export const readCookie = <T extends ZodTypeAny>(
}
if (c.indexOf(name) == 0) {
const str = c.substring(name.length, c.length);
const ret = JSON.parse(str);
return parser ? parser.parse(ret) : ret;
return parser ? parser.parse(JSON.parse(str)) : str;
}
}
return null;