From 1a6ec281774dd8627723f85e6fb59cb0be538b5c Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 29 Apr 2021 09:54:26 +0200 Subject: [PATCH] Deserialize SuperJSON-ed pageProps before passing to dehydratedState --- packages/core/src/blitz-app-root.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/blitz-app-root.tsx b/packages/core/src/blitz-app-root.tsx index 9c38d00efa..0ad0b222f3 100644 --- a/packages/core/src/blitz-app-root.tsx +++ b/packages/core/src/blitz-app-root.tsx @@ -1,4 +1,5 @@ import React, {ComponentPropsWithoutRef, useEffect} from "react" +import SuperJSON from "superjson" import {useAuthorizeIf} from "./auth/auth-client" import {publicDataStore} from "./auth/public-data-store" import {BlitzProvider} from "./blitz-provider" @@ -85,8 +86,15 @@ export function withBlitzAppRoot(UserAppRoot: React.ComponentType) { document.documentElement.classList.add("blitz-first-render-complete") }, []) + let dehydratedState = props.pageProps.dehydratedState + if (dehydratedState && "_superjson" in props.pageProps) { + const {_superjson, ...json} = props.pageProps + const deserialized = SuperJSON.deserialize({json, meta: _superjson}) as any + dehydratedState = deserialized.dehydratedState + } + return ( - + {noPageFlicker && }