Skip to content

Commit

Permalink
fix: always render a Suspense on the client
Browse files Browse the repository at this point in the history
Temporary workaround for RevereCRE/relay-nextjs#41
  • Loading branch information
matthieu-foucault committed Jan 19, 2022
1 parent 35b4a82 commit b3290ea
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getClientEnvironment } from "../lib/relay/client";
import "normalize.css";
import BCGovTypography from "components/BCGovTypography";
import SessionExpiryHandler from "components/Session/SessionExpiryHandler";

import { Suspense } from "react";
const clientEnv = getClientEnvironment();
const initialPreloadedQuery = getInitialPreloadedQuery({
createClientEnvironment: () => getClientEnvironment()!,
Expand All @@ -15,11 +15,20 @@ function MyApp({ Component, pageProps }: AppProps) {
const relayProps = getRelayProps(pageProps, initialPreloadedQuery);
const env = relayProps.preloadedQuery?.environment ?? clientEnv!;

const component =
typeof window !== "undefined" ? (
<Suspense fallback="loading">
<Component {...pageProps} {...relayProps} />
</Suspense>
) : (
<Component {...pageProps} {...relayProps} />
);

return (
<RelayEnvironmentProvider environment={env}>
{typeof window !== "undefined" && <SessionExpiryHandler />}
<BCGovTypography />
<Component {...pageProps} {...relayProps} />
{component}
</RelayEnvironmentProvider>
);
}
Expand Down

0 comments on commit b3290ea

Please sign in to comment.