@tanstack/router-ssr-query-core 1.166.8 → 1.166.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +108 -133
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +106 -132
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,138 +1,113 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const ogMutationCacheConfig = queryClient.getMutationCache().config;
|
|
94
|
-
queryClient.getMutationCache().config = {
|
|
95
|
-
...ogMutationCacheConfig,
|
|
96
|
-
onError: (error, ...rest) => {
|
|
97
|
-
if (routerCore.isRedirect(error)) {
|
|
98
|
-
error.options._fromLocation = router.state.location;
|
|
99
|
-
return router.navigate(router.resolveRedirect(error).options);
|
|
100
|
-
}
|
|
101
|
-
return ogMutationCacheConfig.onError?.(error, ...rest);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const ogQueryCacheConfig = queryClient.getQueryCache().config;
|
|
105
|
-
queryClient.getQueryCache().config = {
|
|
106
|
-
...ogQueryCacheConfig,
|
|
107
|
-
onError: (error, ...rest) => {
|
|
108
|
-
if (routerCore.isRedirect(error)) {
|
|
109
|
-
error.options._fromLocation = router.state.location;
|
|
110
|
-
return router.navigate(router.resolveRedirect(error).options);
|
|
111
|
-
}
|
|
112
|
-
return ogQueryCacheConfig.onError?.(error, ...rest);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
2
|
+
let _tanstack_query_core = require("@tanstack/query-core");
|
|
3
|
+
let _tanstack_router_core = require("@tanstack/router-core");
|
|
4
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
function setupCoreRouterSsrQueryIntegration({ router, queryClient, handleRedirects = true }) {
|
|
7
|
+
const ogHydrate = router.options.hydrate;
|
|
8
|
+
const ogDehydrate = router.options.dehydrate;
|
|
9
|
+
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
10
|
+
const sentQueries = /* @__PURE__ */ new Set();
|
|
11
|
+
const queryStream = createPushableStream();
|
|
12
|
+
let unsubscribe = void 0;
|
|
13
|
+
router.options.dehydrate = async () => {
|
|
14
|
+
router.serverSsr.onRenderFinished(() => {
|
|
15
|
+
queryStream.close();
|
|
16
|
+
unsubscribe?.();
|
|
17
|
+
unsubscribe = void 0;
|
|
18
|
+
});
|
|
19
|
+
const dehydratedRouter = {
|
|
20
|
+
...await ogDehydrate?.(),
|
|
21
|
+
queryStream: queryStream.stream
|
|
22
|
+
};
|
|
23
|
+
const dehydratedQueryClient = (0, _tanstack_query_core.dehydrate)(queryClient);
|
|
24
|
+
if (dehydratedQueryClient.queries.length > 0) {
|
|
25
|
+
dehydratedQueryClient.queries.forEach((query) => {
|
|
26
|
+
sentQueries.add(query.queryHash);
|
|
27
|
+
});
|
|
28
|
+
dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient;
|
|
29
|
+
}
|
|
30
|
+
return dehydratedRouter;
|
|
31
|
+
};
|
|
32
|
+
const ogClientOptions = queryClient.getDefaultOptions();
|
|
33
|
+
queryClient.setDefaultOptions({
|
|
34
|
+
...ogClientOptions,
|
|
35
|
+
dehydrate: {
|
|
36
|
+
shouldDehydrateQuery: () => true,
|
|
37
|
+
...ogClientOptions.dehydrate
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
unsubscribe = queryClient.getQueryCache().subscribe((event) => {
|
|
41
|
+
if (!router.serverSsr?.isDehydrated()) return;
|
|
42
|
+
if (sentQueries.has(event.query.queryHash)) return;
|
|
43
|
+
if (!event.query.promise) return;
|
|
44
|
+
if (queryStream.isClosed()) {
|
|
45
|
+
console.warn(`tried to stream query ${event.query.queryHash} after stream was already closed`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
sentQueries.add(event.query.queryHash);
|
|
49
|
+
queryStream.enqueue((0, _tanstack_query_core.dehydrate)(queryClient, { shouldDehydrateQuery: (query) => {
|
|
50
|
+
if (query.queryHash === event.query.queryHash) return ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true;
|
|
51
|
+
return false;
|
|
52
|
+
} }));
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
router.options.hydrate = async (dehydrated) => {
|
|
56
|
+
await ogHydrate?.(dehydrated);
|
|
57
|
+
if (dehydrated.dehydratedQueryClient) (0, _tanstack_query_core.hydrate)(queryClient, dehydrated.dehydratedQueryClient);
|
|
58
|
+
const reader = dehydrated.queryStream.getReader();
|
|
59
|
+
reader.read().then(async function handle({ done, value }) {
|
|
60
|
+
(0, _tanstack_query_core.hydrate)(queryClient, value);
|
|
61
|
+
if (done) return;
|
|
62
|
+
return handle(await reader.read());
|
|
63
|
+
}).catch((err) => {
|
|
64
|
+
console.error("Error reading query stream:", err);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
if (handleRedirects) {
|
|
68
|
+
const ogMutationCacheConfig = queryClient.getMutationCache().config;
|
|
69
|
+
queryClient.getMutationCache().config = {
|
|
70
|
+
...ogMutationCacheConfig,
|
|
71
|
+
onError: (error, ...rest) => {
|
|
72
|
+
if ((0, _tanstack_router_core.isRedirect)(error)) {
|
|
73
|
+
error.options._fromLocation = router.state.location;
|
|
74
|
+
return router.navigate(router.resolveRedirect(error).options);
|
|
75
|
+
}
|
|
76
|
+
return ogMutationCacheConfig.onError?.(error, ...rest);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const ogQueryCacheConfig = queryClient.getQueryCache().config;
|
|
80
|
+
queryClient.getQueryCache().config = {
|
|
81
|
+
...ogQueryCacheConfig,
|
|
82
|
+
onError: (error, ...rest) => {
|
|
83
|
+
if ((0, _tanstack_router_core.isRedirect)(error)) {
|
|
84
|
+
error.options._fromLocation = router.state.location;
|
|
85
|
+
return router.navigate(router.resolveRedirect(error).options);
|
|
86
|
+
}
|
|
87
|
+
return ogQueryCacheConfig.onError?.(error, ...rest);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
117
92
|
}
|
|
118
93
|
function createPushableStream() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
error: (err) => controllerRef.error(err)
|
|
135
|
-
};
|
|
94
|
+
let controllerRef;
|
|
95
|
+
const stream = new ReadableStream({ start(controller) {
|
|
96
|
+
controllerRef = controller;
|
|
97
|
+
} });
|
|
98
|
+
let _isClosed = false;
|
|
99
|
+
return {
|
|
100
|
+
stream,
|
|
101
|
+
enqueue: (chunk) => controllerRef.enqueue(chunk),
|
|
102
|
+
close: () => {
|
|
103
|
+
controllerRef.close();
|
|
104
|
+
_isClosed = true;
|
|
105
|
+
},
|
|
106
|
+
isClosed: () => _isClosed,
|
|
107
|
+
error: (err) => controllerRef.error(err)
|
|
108
|
+
};
|
|
136
109
|
}
|
|
110
|
+
//#endregion
|
|
137
111
|
exports.setupCoreRouterSsrQueryIntegration = setupCoreRouterSsrQueryIntegration;
|
|
138
|
-
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n dehydrate as queryDehydrate,\n hydrate as queryHydrate,\n} from '@tanstack/query-core'\nimport { isRedirect } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type {\n QueryClient,\n DehydratedState as QueryDehydratedState,\n} from '@tanstack/query-core'\n\nexport type RouterSsrQueryOptions<TRouter extends AnyRouter> = {\n router: TRouter\n queryClient: QueryClient\n\n /**\n * If `true`, the QueryClient will handle errors thrown by `redirect()` inside of mutations and queries.\n *\n * @default true\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction)\n */\n handleRedirects?: boolean\n}\n\ntype DehydratedRouterQueryState = {\n dehydratedQueryClient?: QueryDehydratedState\n queryStream: ReadableStream<QueryDehydratedState>\n}\n\nexport function setupCoreRouterSsrQueryIntegration<TRouter extends AnyRouter>({\n router,\n queryClient,\n handleRedirects = true,\n}: RouterSsrQueryOptions<TRouter>) {\n const ogHydrate = router.options.hydrate\n const ogDehydrate = router.options.dehydrate\n\n if (isServer ?? router.isServer) {\n const sentQueries = new Set<string>()\n const queryStream = createPushableStream()\n let unsubscribe: (() => void) | undefined = undefined\n router.options.dehydrate =\n async (): Promise<DehydratedRouterQueryState> => {\n router.serverSsr!.onRenderFinished(() => {\n queryStream.close()\n unsubscribe?.()\n unsubscribe = undefined\n })\n const ogDehydrated = await ogDehydrate?.()\n\n const dehydratedRouter = {\n ...ogDehydrated,\n // prepare the stream for queries coming up during rendering\n queryStream: queryStream.stream,\n }\n\n const dehydratedQueryClient = queryDehydrate(queryClient)\n if (dehydratedQueryClient.queries.length > 0) {\n dehydratedQueryClient.queries.forEach((query) => {\n sentQueries.add(query.queryHash)\n })\n dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient\n }\n\n return dehydratedRouter\n }\n\n const ogClientOptions = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...ogClientOptions,\n dehydrate: {\n shouldDehydrateQuery: () => true,\n ...ogClientOptions.dehydrate,\n },\n })\n\n unsubscribe = queryClient.getQueryCache().subscribe((event) => {\n // before rendering starts, we do not stream individual queries\n // instead we dehydrate the entire query client in router's dehydrate()\n // if attachRouterServerSsrUtils() has not been called yet, `router.serverSsr` will be undefined and we also do not stream\n if (!router.serverSsr?.isDehydrated()) {\n return\n }\n if (sentQueries.has(event.query.queryHash)) {\n return\n }\n // promise not yet set on the query, so we cannot stream it yet\n if (!event.query.promise) {\n return\n }\n if (queryStream.isClosed()) {\n console.warn(\n `tried to stream query ${event.query.queryHash} after stream was already closed`,\n )\n return\n }\n sentQueries.add(event.query.queryHash)\n queryStream.enqueue(\n queryDehydrate(queryClient, {\n shouldDehydrateQuery: (query) => {\n if (query.queryHash === event.query.queryHash) {\n return (\n ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true\n )\n }\n return false\n },\n }),\n )\n })\n // on the client\n } else {\n router.options.hydrate = async (dehydrated: DehydratedRouterQueryState) => {\n await ogHydrate?.(dehydrated)\n // hydrate the query client with the dehydrated data (if it was dehydrated on the server)\n if (dehydrated.dehydratedQueryClient) {\n queryHydrate(queryClient, dehydrated.dehydratedQueryClient)\n }\n\n // read the query stream and hydrate the queries as they come in\n const reader = dehydrated.queryStream.getReader()\n reader\n .read()\n .then(async function handle({ done, value }) {\n queryHydrate(queryClient, value)\n if (done) {\n return\n }\n const result = await reader.read()\n return handle(result)\n })\n .catch((err) => {\n console.error('Error reading query stream:', err)\n })\n }\n if (handleRedirects) {\n const ogMutationCacheConfig = queryClient.getMutationCache().config\n queryClient.getMutationCache().config = {\n ...ogMutationCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogMutationCacheConfig.onError?.(error, ...rest)\n },\n }\n\n const ogQueryCacheConfig = queryClient.getQueryCache().config\n queryClient.getQueryCache().config = {\n ...ogQueryCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogQueryCacheConfig.onError?.(error, ...rest)\n },\n }\n }\n }\n}\n\ntype PushableStream = {\n stream: ReadableStream\n enqueue: (chunk: unknown) => void\n close: () => void\n isClosed: () => boolean\n error: (err: unknown) => void\n}\n\nfunction createPushableStream(): PushableStream {\n let controllerRef: ReadableStreamDefaultController\n const stream = new ReadableStream({\n start(controller) {\n controllerRef = controller\n },\n })\n let _isClosed = false\n\n return {\n stream,\n enqueue: (chunk) => controllerRef.enqueue(chunk),\n close: () => {\n controllerRef.close()\n _isClosed = true\n },\n isClosed: () => _isClosed,\n error: (err: unknown) => controllerRef.error(err),\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import {\n dehydrate as queryDehydrate,\n hydrate as queryHydrate,\n} from '@tanstack/query-core'\nimport { isRedirect } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type {\n QueryClient,\n DehydratedState as QueryDehydratedState,\n} from '@tanstack/query-core'\n\nexport type RouterSsrQueryOptions<TRouter extends AnyRouter> = {\n router: TRouter\n queryClient: QueryClient\n\n /**\n * If `true`, the QueryClient will handle errors thrown by `redirect()` inside of mutations and queries.\n *\n * @default true\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction)\n */\n handleRedirects?: boolean\n}\n\ntype DehydratedRouterQueryState = {\n dehydratedQueryClient?: QueryDehydratedState\n queryStream: ReadableStream<QueryDehydratedState>\n}\n\nexport function setupCoreRouterSsrQueryIntegration<TRouter extends AnyRouter>({\n router,\n queryClient,\n handleRedirects = true,\n}: RouterSsrQueryOptions<TRouter>) {\n const ogHydrate = router.options.hydrate\n const ogDehydrate = router.options.dehydrate\n\n if (isServer ?? router.isServer) {\n const sentQueries = new Set<string>()\n const queryStream = createPushableStream()\n let unsubscribe: (() => void) | undefined = undefined\n router.options.dehydrate =\n async (): Promise<DehydratedRouterQueryState> => {\n router.serverSsr!.onRenderFinished(() => {\n queryStream.close()\n unsubscribe?.()\n unsubscribe = undefined\n })\n const ogDehydrated = await ogDehydrate?.()\n\n const dehydratedRouter = {\n ...ogDehydrated,\n // prepare the stream for queries coming up during rendering\n queryStream: queryStream.stream,\n }\n\n const dehydratedQueryClient = queryDehydrate(queryClient)\n if (dehydratedQueryClient.queries.length > 0) {\n dehydratedQueryClient.queries.forEach((query) => {\n sentQueries.add(query.queryHash)\n })\n dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient\n }\n\n return dehydratedRouter\n }\n\n const ogClientOptions = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...ogClientOptions,\n dehydrate: {\n shouldDehydrateQuery: () => true,\n ...ogClientOptions.dehydrate,\n },\n })\n\n unsubscribe = queryClient.getQueryCache().subscribe((event) => {\n // before rendering starts, we do not stream individual queries\n // instead we dehydrate the entire query client in router's dehydrate()\n // if attachRouterServerSsrUtils() has not been called yet, `router.serverSsr` will be undefined and we also do not stream\n if (!router.serverSsr?.isDehydrated()) {\n return\n }\n if (sentQueries.has(event.query.queryHash)) {\n return\n }\n // promise not yet set on the query, so we cannot stream it yet\n if (!event.query.promise) {\n return\n }\n if (queryStream.isClosed()) {\n console.warn(\n `tried to stream query ${event.query.queryHash} after stream was already closed`,\n )\n return\n }\n sentQueries.add(event.query.queryHash)\n queryStream.enqueue(\n queryDehydrate(queryClient, {\n shouldDehydrateQuery: (query) => {\n if (query.queryHash === event.query.queryHash) {\n return (\n ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true\n )\n }\n return false\n },\n }),\n )\n })\n // on the client\n } else {\n router.options.hydrate = async (dehydrated: DehydratedRouterQueryState) => {\n await ogHydrate?.(dehydrated)\n // hydrate the query client with the dehydrated data (if it was dehydrated on the server)\n if (dehydrated.dehydratedQueryClient) {\n queryHydrate(queryClient, dehydrated.dehydratedQueryClient)\n }\n\n // read the query stream and hydrate the queries as they come in\n const reader = dehydrated.queryStream.getReader()\n reader\n .read()\n .then(async function handle({ done, value }) {\n queryHydrate(queryClient, value)\n if (done) {\n return\n }\n const result = await reader.read()\n return handle(result)\n })\n .catch((err) => {\n console.error('Error reading query stream:', err)\n })\n }\n if (handleRedirects) {\n const ogMutationCacheConfig = queryClient.getMutationCache().config\n queryClient.getMutationCache().config = {\n ...ogMutationCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogMutationCacheConfig.onError?.(error, ...rest)\n },\n }\n\n const ogQueryCacheConfig = queryClient.getQueryCache().config\n queryClient.getQueryCache().config = {\n ...ogQueryCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogQueryCacheConfig.onError?.(error, ...rest)\n },\n }\n }\n }\n}\n\ntype PushableStream = {\n stream: ReadableStream\n enqueue: (chunk: unknown) => void\n close: () => void\n isClosed: () => boolean\n error: (err: unknown) => void\n}\n\nfunction createPushableStream(): PushableStream {\n let controllerRef: ReadableStreamDefaultController\n const stream = new ReadableStream({\n start(controller) {\n controllerRef = controller\n },\n })\n let _isClosed = false\n\n return {\n stream,\n enqueue: (chunk) => controllerRef.enqueue(chunk),\n close: () => {\n controllerRef.close()\n _isClosed = true\n },\n isClosed: () => _isClosed,\n error: (err: unknown) => controllerRef.error(err),\n }\n}\n"],"mappings":"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"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,138 +1,112 @@
|
|
|
1
1
|
import { dehydrate, hydrate } from "@tanstack/query-core";
|
|
2
2
|
import { isRedirect } from "@tanstack/router-core";
|
|
3
3
|
import { isServer } from "@tanstack/router-core/isServer";
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const ogMutationCacheConfig = queryClient.getMutationCache().config;
|
|
92
|
-
queryClient.getMutationCache().config = {
|
|
93
|
-
...ogMutationCacheConfig,
|
|
94
|
-
onError: (error, ...rest) => {
|
|
95
|
-
if (isRedirect(error)) {
|
|
96
|
-
error.options._fromLocation = router.state.location;
|
|
97
|
-
return router.navigate(router.resolveRedirect(error).options);
|
|
98
|
-
}
|
|
99
|
-
return ogMutationCacheConfig.onError?.(error, ...rest);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const ogQueryCacheConfig = queryClient.getQueryCache().config;
|
|
103
|
-
queryClient.getQueryCache().config = {
|
|
104
|
-
...ogQueryCacheConfig,
|
|
105
|
-
onError: (error, ...rest) => {
|
|
106
|
-
if (isRedirect(error)) {
|
|
107
|
-
error.options._fromLocation = router.state.location;
|
|
108
|
-
return router.navigate(router.resolveRedirect(error).options);
|
|
109
|
-
}
|
|
110
|
-
return ogQueryCacheConfig.onError?.(error, ...rest);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function setupCoreRouterSsrQueryIntegration({ router, queryClient, handleRedirects = true }) {
|
|
6
|
+
const ogHydrate = router.options.hydrate;
|
|
7
|
+
const ogDehydrate = router.options.dehydrate;
|
|
8
|
+
if (isServer ?? router.isServer) {
|
|
9
|
+
const sentQueries = /* @__PURE__ */ new Set();
|
|
10
|
+
const queryStream = createPushableStream();
|
|
11
|
+
let unsubscribe = void 0;
|
|
12
|
+
router.options.dehydrate = async () => {
|
|
13
|
+
router.serverSsr.onRenderFinished(() => {
|
|
14
|
+
queryStream.close();
|
|
15
|
+
unsubscribe?.();
|
|
16
|
+
unsubscribe = void 0;
|
|
17
|
+
});
|
|
18
|
+
const dehydratedRouter = {
|
|
19
|
+
...await ogDehydrate?.(),
|
|
20
|
+
queryStream: queryStream.stream
|
|
21
|
+
};
|
|
22
|
+
const dehydratedQueryClient = dehydrate(queryClient);
|
|
23
|
+
if (dehydratedQueryClient.queries.length > 0) {
|
|
24
|
+
dehydratedQueryClient.queries.forEach((query) => {
|
|
25
|
+
sentQueries.add(query.queryHash);
|
|
26
|
+
});
|
|
27
|
+
dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient;
|
|
28
|
+
}
|
|
29
|
+
return dehydratedRouter;
|
|
30
|
+
};
|
|
31
|
+
const ogClientOptions = queryClient.getDefaultOptions();
|
|
32
|
+
queryClient.setDefaultOptions({
|
|
33
|
+
...ogClientOptions,
|
|
34
|
+
dehydrate: {
|
|
35
|
+
shouldDehydrateQuery: () => true,
|
|
36
|
+
...ogClientOptions.dehydrate
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
unsubscribe = queryClient.getQueryCache().subscribe((event) => {
|
|
40
|
+
if (!router.serverSsr?.isDehydrated()) return;
|
|
41
|
+
if (sentQueries.has(event.query.queryHash)) return;
|
|
42
|
+
if (!event.query.promise) return;
|
|
43
|
+
if (queryStream.isClosed()) {
|
|
44
|
+
console.warn(`tried to stream query ${event.query.queryHash} after stream was already closed`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
sentQueries.add(event.query.queryHash);
|
|
48
|
+
queryStream.enqueue(dehydrate(queryClient, { shouldDehydrateQuery: (query) => {
|
|
49
|
+
if (query.queryHash === event.query.queryHash) return ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true;
|
|
50
|
+
return false;
|
|
51
|
+
} }));
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
router.options.hydrate = async (dehydrated) => {
|
|
55
|
+
await ogHydrate?.(dehydrated);
|
|
56
|
+
if (dehydrated.dehydratedQueryClient) hydrate(queryClient, dehydrated.dehydratedQueryClient);
|
|
57
|
+
const reader = dehydrated.queryStream.getReader();
|
|
58
|
+
reader.read().then(async function handle({ done, value }) {
|
|
59
|
+
hydrate(queryClient, value);
|
|
60
|
+
if (done) return;
|
|
61
|
+
return handle(await reader.read());
|
|
62
|
+
}).catch((err) => {
|
|
63
|
+
console.error("Error reading query stream:", err);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
if (handleRedirects) {
|
|
67
|
+
const ogMutationCacheConfig = queryClient.getMutationCache().config;
|
|
68
|
+
queryClient.getMutationCache().config = {
|
|
69
|
+
...ogMutationCacheConfig,
|
|
70
|
+
onError: (error, ...rest) => {
|
|
71
|
+
if (isRedirect(error)) {
|
|
72
|
+
error.options._fromLocation = router.state.location;
|
|
73
|
+
return router.navigate(router.resolveRedirect(error).options);
|
|
74
|
+
}
|
|
75
|
+
return ogMutationCacheConfig.onError?.(error, ...rest);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const ogQueryCacheConfig = queryClient.getQueryCache().config;
|
|
79
|
+
queryClient.getQueryCache().config = {
|
|
80
|
+
...ogQueryCacheConfig,
|
|
81
|
+
onError: (error, ...rest) => {
|
|
82
|
+
if (isRedirect(error)) {
|
|
83
|
+
error.options._fromLocation = router.state.location;
|
|
84
|
+
return router.navigate(router.resolveRedirect(error).options);
|
|
85
|
+
}
|
|
86
|
+
return ogQueryCacheConfig.onError?.(error, ...rest);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
115
91
|
}
|
|
116
92
|
function createPushableStream() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
error: (err) => controllerRef.error(err)
|
|
133
|
-
};
|
|
93
|
+
let controllerRef;
|
|
94
|
+
const stream = new ReadableStream({ start(controller) {
|
|
95
|
+
controllerRef = controller;
|
|
96
|
+
} });
|
|
97
|
+
let _isClosed = false;
|
|
98
|
+
return {
|
|
99
|
+
stream,
|
|
100
|
+
enqueue: (chunk) => controllerRef.enqueue(chunk),
|
|
101
|
+
close: () => {
|
|
102
|
+
controllerRef.close();
|
|
103
|
+
_isClosed = true;
|
|
104
|
+
},
|
|
105
|
+
isClosed: () => _isClosed,
|
|
106
|
+
error: (err) => controllerRef.error(err)
|
|
107
|
+
};
|
|
134
108
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//# sourceMappingURL=index.js.map
|
|
109
|
+
//#endregion
|
|
110
|
+
export { setupCoreRouterSsrQueryIntegration };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n dehydrate as queryDehydrate,\n hydrate as queryHydrate,\n} from '@tanstack/query-core'\nimport { isRedirect } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type {\n QueryClient,\n DehydratedState as QueryDehydratedState,\n} from '@tanstack/query-core'\n\nexport type RouterSsrQueryOptions<TRouter extends AnyRouter> = {\n router: TRouter\n queryClient: QueryClient\n\n /**\n * If `true`, the QueryClient will handle errors thrown by `redirect()` inside of mutations and queries.\n *\n * @default true\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction)\n */\n handleRedirects?: boolean\n}\n\ntype DehydratedRouterQueryState = {\n dehydratedQueryClient?: QueryDehydratedState\n queryStream: ReadableStream<QueryDehydratedState>\n}\n\nexport function setupCoreRouterSsrQueryIntegration<TRouter extends AnyRouter>({\n router,\n queryClient,\n handleRedirects = true,\n}: RouterSsrQueryOptions<TRouter>) {\n const ogHydrate = router.options.hydrate\n const ogDehydrate = router.options.dehydrate\n\n if (isServer ?? router.isServer) {\n const sentQueries = new Set<string>()\n const queryStream = createPushableStream()\n let unsubscribe: (() => void) | undefined = undefined\n router.options.dehydrate =\n async (): Promise<DehydratedRouterQueryState> => {\n router.serverSsr!.onRenderFinished(() => {\n queryStream.close()\n unsubscribe?.()\n unsubscribe = undefined\n })\n const ogDehydrated = await ogDehydrate?.()\n\n const dehydratedRouter = {\n ...ogDehydrated,\n // prepare the stream for queries coming up during rendering\n queryStream: queryStream.stream,\n }\n\n const dehydratedQueryClient = queryDehydrate(queryClient)\n if (dehydratedQueryClient.queries.length > 0) {\n dehydratedQueryClient.queries.forEach((query) => {\n sentQueries.add(query.queryHash)\n })\n dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient\n }\n\n return dehydratedRouter\n }\n\n const ogClientOptions = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...ogClientOptions,\n dehydrate: {\n shouldDehydrateQuery: () => true,\n ...ogClientOptions.dehydrate,\n },\n })\n\n unsubscribe = queryClient.getQueryCache().subscribe((event) => {\n // before rendering starts, we do not stream individual queries\n // instead we dehydrate the entire query client in router's dehydrate()\n // if attachRouterServerSsrUtils() has not been called yet, `router.serverSsr` will be undefined and we also do not stream\n if (!router.serverSsr?.isDehydrated()) {\n return\n }\n if (sentQueries.has(event.query.queryHash)) {\n return\n }\n // promise not yet set on the query, so we cannot stream it yet\n if (!event.query.promise) {\n return\n }\n if (queryStream.isClosed()) {\n console.warn(\n `tried to stream query ${event.query.queryHash} after stream was already closed`,\n )\n return\n }\n sentQueries.add(event.query.queryHash)\n queryStream.enqueue(\n queryDehydrate(queryClient, {\n shouldDehydrateQuery: (query) => {\n if (query.queryHash === event.query.queryHash) {\n return (\n ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true\n )\n }\n return false\n },\n }),\n )\n })\n // on the client\n } else {\n router.options.hydrate = async (dehydrated: DehydratedRouterQueryState) => {\n await ogHydrate?.(dehydrated)\n // hydrate the query client with the dehydrated data (if it was dehydrated on the server)\n if (dehydrated.dehydratedQueryClient) {\n queryHydrate(queryClient, dehydrated.dehydratedQueryClient)\n }\n\n // read the query stream and hydrate the queries as they come in\n const reader = dehydrated.queryStream.getReader()\n reader\n .read()\n .then(async function handle({ done, value }) {\n queryHydrate(queryClient, value)\n if (done) {\n return\n }\n const result = await reader.read()\n return handle(result)\n })\n .catch((err) => {\n console.error('Error reading query stream:', err)\n })\n }\n if (handleRedirects) {\n const ogMutationCacheConfig = queryClient.getMutationCache().config\n queryClient.getMutationCache().config = {\n ...ogMutationCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogMutationCacheConfig.onError?.(error, ...rest)\n },\n }\n\n const ogQueryCacheConfig = queryClient.getQueryCache().config\n queryClient.getQueryCache().config = {\n ...ogQueryCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogQueryCacheConfig.onError?.(error, ...rest)\n },\n }\n }\n }\n}\n\ntype PushableStream = {\n stream: ReadableStream\n enqueue: (chunk: unknown) => void\n close: () => void\n isClosed: () => boolean\n error: (err: unknown) => void\n}\n\nfunction createPushableStream(): PushableStream {\n let controllerRef: ReadableStreamDefaultController\n const stream = new ReadableStream({\n start(controller) {\n controllerRef = controller\n },\n })\n let _isClosed = false\n\n return {\n stream,\n enqueue: (chunk) => controllerRef.enqueue(chunk),\n close: () => {\n controllerRef.close()\n _isClosed = true\n },\n isClosed: () => _isClosed,\n error: (err: unknown) => controllerRef.error(err),\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import {\n dehydrate as queryDehydrate,\n hydrate as queryHydrate,\n} from '@tanstack/query-core'\nimport { isRedirect } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type {\n QueryClient,\n DehydratedState as QueryDehydratedState,\n} from '@tanstack/query-core'\n\nexport type RouterSsrQueryOptions<TRouter extends AnyRouter> = {\n router: TRouter\n queryClient: QueryClient\n\n /**\n * If `true`, the QueryClient will handle errors thrown by `redirect()` inside of mutations and queries.\n *\n * @default true\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction)\n */\n handleRedirects?: boolean\n}\n\ntype DehydratedRouterQueryState = {\n dehydratedQueryClient?: QueryDehydratedState\n queryStream: ReadableStream<QueryDehydratedState>\n}\n\nexport function setupCoreRouterSsrQueryIntegration<TRouter extends AnyRouter>({\n router,\n queryClient,\n handleRedirects = true,\n}: RouterSsrQueryOptions<TRouter>) {\n const ogHydrate = router.options.hydrate\n const ogDehydrate = router.options.dehydrate\n\n if (isServer ?? router.isServer) {\n const sentQueries = new Set<string>()\n const queryStream = createPushableStream()\n let unsubscribe: (() => void) | undefined = undefined\n router.options.dehydrate =\n async (): Promise<DehydratedRouterQueryState> => {\n router.serverSsr!.onRenderFinished(() => {\n queryStream.close()\n unsubscribe?.()\n unsubscribe = undefined\n })\n const ogDehydrated = await ogDehydrate?.()\n\n const dehydratedRouter = {\n ...ogDehydrated,\n // prepare the stream for queries coming up during rendering\n queryStream: queryStream.stream,\n }\n\n const dehydratedQueryClient = queryDehydrate(queryClient)\n if (dehydratedQueryClient.queries.length > 0) {\n dehydratedQueryClient.queries.forEach((query) => {\n sentQueries.add(query.queryHash)\n })\n dehydratedRouter.dehydratedQueryClient = dehydratedQueryClient\n }\n\n return dehydratedRouter\n }\n\n const ogClientOptions = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...ogClientOptions,\n dehydrate: {\n shouldDehydrateQuery: () => true,\n ...ogClientOptions.dehydrate,\n },\n })\n\n unsubscribe = queryClient.getQueryCache().subscribe((event) => {\n // before rendering starts, we do not stream individual queries\n // instead we dehydrate the entire query client in router's dehydrate()\n // if attachRouterServerSsrUtils() has not been called yet, `router.serverSsr` will be undefined and we also do not stream\n if (!router.serverSsr?.isDehydrated()) {\n return\n }\n if (sentQueries.has(event.query.queryHash)) {\n return\n }\n // promise not yet set on the query, so we cannot stream it yet\n if (!event.query.promise) {\n return\n }\n if (queryStream.isClosed()) {\n console.warn(\n `tried to stream query ${event.query.queryHash} after stream was already closed`,\n )\n return\n }\n sentQueries.add(event.query.queryHash)\n queryStream.enqueue(\n queryDehydrate(queryClient, {\n shouldDehydrateQuery: (query) => {\n if (query.queryHash === event.query.queryHash) {\n return (\n ogClientOptions.dehydrate?.shouldDehydrateQuery?.(query) ?? true\n )\n }\n return false\n },\n }),\n )\n })\n // on the client\n } else {\n router.options.hydrate = async (dehydrated: DehydratedRouterQueryState) => {\n await ogHydrate?.(dehydrated)\n // hydrate the query client with the dehydrated data (if it was dehydrated on the server)\n if (dehydrated.dehydratedQueryClient) {\n queryHydrate(queryClient, dehydrated.dehydratedQueryClient)\n }\n\n // read the query stream and hydrate the queries as they come in\n const reader = dehydrated.queryStream.getReader()\n reader\n .read()\n .then(async function handle({ done, value }) {\n queryHydrate(queryClient, value)\n if (done) {\n return\n }\n const result = await reader.read()\n return handle(result)\n })\n .catch((err) => {\n console.error('Error reading query stream:', err)\n })\n }\n if (handleRedirects) {\n const ogMutationCacheConfig = queryClient.getMutationCache().config\n queryClient.getMutationCache().config = {\n ...ogMutationCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogMutationCacheConfig.onError?.(error, ...rest)\n },\n }\n\n const ogQueryCacheConfig = queryClient.getQueryCache().config\n queryClient.getQueryCache().config = {\n ...ogQueryCacheConfig,\n onError: (error, ...rest) => {\n if (isRedirect(error)) {\n error.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(error).options)\n }\n\n return ogQueryCacheConfig.onError?.(error, ...rest)\n },\n }\n }\n }\n}\n\ntype PushableStream = {\n stream: ReadableStream\n enqueue: (chunk: unknown) => void\n close: () => void\n isClosed: () => boolean\n error: (err: unknown) => void\n}\n\nfunction createPushableStream(): PushableStream {\n let controllerRef: ReadableStreamDefaultController\n const stream = new ReadableStream({\n start(controller) {\n controllerRef = controller\n },\n })\n let _isClosed = false\n\n return {\n stream,\n enqueue: (chunk) => controllerRef.enqueue(chunk),\n close: () => {\n controllerRef.close()\n _isClosed = true\n },\n isClosed: () => _isClosed,\n error: (err: unknown) => controllerRef.error(err),\n }\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-ssr-query-core",
|
|
3
|
-
"version": "1.166.
|
|
3
|
+
"version": "1.166.9",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"node": ">=20.19"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@tanstack/router-core": ">=1.167.
|
|
52
|
+
"@tanstack/router-core": ">=1.167.2",
|
|
53
53
|
"@tanstack/query-core": ">=5.90.0",
|
|
54
54
|
"vite": "*"
|
|
55
55
|
},
|