-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry-client.tsx
42 lines (37 loc) · 1.04 KB
/
entry-client.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint-disable no-var */
import { startClient } from "rakkasjs";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
suspense: true,
staleTime: 100,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
},
},
});
function setQueryData(data: Record<string, unknown>) {
for (const [key, value] of Object.entries(data)) {
queryClient.setQueryData(JSON.parse(key), value, { updatedAt: Date.now() });
}
}
declare global {
var $TQD: Record<string, unknown> | undefined;
var $TQS: typeof setQueryData;
}
// Insert data that was already streamed before this point
setQueryData(globalThis.$TQD ?? {});
// Delete the global variable so that it doesn't get serialized again
delete globalThis.$TQD;
// From now on, insert data directly
globalThis.$TQS = setQueryData;
startClient({
hooks: {
wrapApp(app) {
return (
<QueryClientProvider client={queryClient}>{app}</QueryClientProvider>
);
},
},
});