Skip to content

Commit

Permalink
Deserialize SuperJSON-ed pageProps before passing to dehydratedState
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Apr 29, 2021
1 parent 4bb6ded commit 1a6ec28
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/src/blitz-app-root.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -85,8 +86,15 @@ export function withBlitzAppRoot(UserAppRoot: React.ComponentType<any>) {
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 (
<BlitzProvider dehydratedState={props.pageProps.dehydratedState}>
<BlitzProvider dehydratedState={dehydratedState}>
{noPageFlicker && <NoPageFlicker />}
<UserAppRoot {...props} Component={component} />
</BlitzProvider>
Expand Down

0 comments on commit 1a6ec28

Please sign in to comment.