Skip to content

Commit

Permalink
fix: rare hydration problem
Browse files Browse the repository at this point in the history
  • Loading branch information
marudor committed Jan 18, 2025
1 parent 58f9a99 commit 75b7ded
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { hydrateRoot } from 'react-dom/client';
import { HeadProvider } from 'react-head';

const cache = createEmotionCache({ prepend: true, key: 'css' });
const router = createRouter();

async function render() {
const router = createRouter();
await router.load();

hydrateRoot(
Expand Down
14 changes: 10 additions & 4 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ const queryClientOptions: QueryClientConfig = {

const queryClient = new QueryClient(queryClientOptions);

if (!import.meta.env.SSR && window.__TSR__) {
const queryClientData = parse(window.__TSR__.dehydrated).payload
.queryClientState;
hydrate(queryClient, queryClientData);
if (!import.meta.env.SSR) {
window.addEventListener('load', () => {
try {
if (window.__TSR__) {
const queryClientData = parse(window.__TSR__.dehydrated).payload
.queryClientState;
hydrate(queryClient, queryClientData);
}
} catch {}
});
}

const trpcUtils = createTRPCQueryUtils({
Expand Down

0 comments on commit 75b7ded

Please sign in to comment.