@tanstack/react-query-next-experimental 5.91.0 → 5.94.4
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/package.json +9 -10
- package/build/legacy/HydrationStreamProvider.cjs +0 -119
- package/build/legacy/HydrationStreamProvider.cjs.map +0 -1
- package/build/legacy/HydrationStreamProvider.d.cts +0 -67
- package/build/legacy/HydrationStreamProvider.d.ts +0 -67
- package/build/legacy/HydrationStreamProvider.js +0 -85
- package/build/legacy/HydrationStreamProvider.js.map +0 -1
- package/build/legacy/ReactQueryStreamedHydration.cjs +0 -88
- package/build/legacy/ReactQueryStreamedHydration.cjs.map +0 -1
- package/build/legacy/ReactQueryStreamedHydration.d.cts +0 -22
- package/build/legacy/ReactQueryStreamedHydration.d.ts +0 -22
- package/build/legacy/ReactQueryStreamedHydration.js +0 -60
- package/build/legacy/ReactQueryStreamedHydration.js.map +0 -1
- package/build/legacy/htmlescape.cjs +0 -43
- package/build/legacy/htmlescape.cjs.map +0 -1
- package/build/legacy/htmlescape.d.cts +0 -4
- package/build/legacy/htmlescape.d.ts +0 -4
- package/build/legacy/htmlescape.js +0 -17
- package/build/legacy/htmlescape.js.map +0 -1
- package/build/legacy/index.cjs +0 -31
- package/build/legacy/index.cjs.map +0 -1
- package/build/legacy/index.d.cts +0 -5
- package/build/legacy/index.d.ts +0 -5
- package/build/legacy/index.js +0 -6
- package/build/legacy/index.js.map +0 -1
- package/build/modern/HydrationStreamProvider.cjs +0 -117
- package/build/modern/HydrationStreamProvider.cjs.map +0 -1
- package/build/modern/HydrationStreamProvider.d.cts +0 -67
- package/build/modern/HydrationStreamProvider.d.ts +0 -67
- package/build/modern/HydrationStreamProvider.js +0 -83
- package/build/modern/HydrationStreamProvider.js.map +0 -1
- package/build/modern/ReactQueryStreamedHydration.cjs +0 -86
- package/build/modern/ReactQueryStreamedHydration.cjs.map +0 -1
- package/build/modern/ReactQueryStreamedHydration.d.cts +0 -22
- package/build/modern/ReactQueryStreamedHydration.d.ts +0 -22
- package/build/modern/ReactQueryStreamedHydration.js +0 -58
- package/build/modern/ReactQueryStreamedHydration.js.map +0 -1
- package/build/modern/htmlescape.cjs +0 -43
- package/build/modern/htmlescape.cjs.map +0 -1
- package/build/modern/htmlescape.d.cts +0 -4
- package/build/modern/htmlescape.d.ts +0 -4
- package/build/modern/htmlescape.js +0 -17
- package/build/modern/htmlescape.js.map +0 -1
- package/build/modern/index.cjs +0 -31
- package/build/modern/index.cjs.map +0 -1
- package/build/modern/index.d.cts +0 -5
- package/build/modern/index.d.ts +0 -5
- package/build/modern/index.js +0 -6
- package/build/modern/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-next-experimental",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.94.4",
|
|
4
4
|
"description": "Hydration utils for React Query in the NextJs app directory",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/TanStack/query.git",
|
|
9
|
+
"url": "git+https://github.com/TanStack/query.git",
|
|
10
10
|
"directory": "packages/react-query-next-experimental"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://tanstack.com/query",
|
|
@@ -39,32 +39,31 @@
|
|
|
39
39
|
"!src/__tests__"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/react": "^19.
|
|
42
|
+
"@types/react": "^19.2.7",
|
|
43
43
|
"@vitejs/plugin-react": "^4.3.4",
|
|
44
44
|
"next": "^16.0.1",
|
|
45
45
|
"npm-run-all2": "^5.0.0",
|
|
46
|
-
"react": "^19.
|
|
47
|
-
"@tanstack/react-query": "5.
|
|
46
|
+
"react": "^19.2.1",
|
|
47
|
+
"@tanstack/react-query": "5.94.4"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"next": "^13 || ^14 || ^15 || ^16",
|
|
51
51
|
"react": "^18 || ^19",
|
|
52
|
-
"@tanstack/react-query": "^5.
|
|
52
|
+
"@tanstack/react-query": "^5.94.4"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"clean": "premove ./build ./coverage ./dist-ts",
|
|
56
56
|
"compile": "tsc --build",
|
|
57
57
|
"test:eslint": "eslint --concurrency=auto ./src",
|
|
58
58
|
"test:types": "npm-run-all --serial test:types:*",
|
|
59
|
-
"test:types:ts50": "node ../../node_modules/typescript50/lib/tsc.js --build tsconfig.legacy.json",
|
|
60
|
-
"test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build tsconfig.legacy.json",
|
|
61
|
-
"test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build tsconfig.legacy.json",
|
|
62
|
-
"test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build tsconfig.legacy.json",
|
|
63
59
|
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build tsconfig.legacy.json",
|
|
64
60
|
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build tsconfig.legacy.json",
|
|
65
61
|
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build tsconfig.legacy.json",
|
|
66
62
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build tsconfig.legacy.json",
|
|
63
|
+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --build tsconfig.legacy.json",
|
|
64
|
+
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --build tsconfig.legacy.json",
|
|
67
65
|
"test:types:tscurrent": "tsc --build",
|
|
66
|
+
"test:types:ts60": "node ../../node_modules/typescript60/lib/tsc.js --build",
|
|
68
67
|
"test:build": "publint --strict && attw --pack",
|
|
69
68
|
"build": "tsup --tsconfig tsconfig.prod.json"
|
|
70
69
|
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/HydrationStreamProvider.tsx
|
|
32
|
-
var HydrationStreamProvider_exports = {};
|
|
33
|
-
__export(HydrationStreamProvider_exports, {
|
|
34
|
-
createHydrationStreamProvider: () => createHydrationStreamProvider
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(HydrationStreamProvider_exports);
|
|
37
|
-
var import_react_query = require("@tanstack/react-query");
|
|
38
|
-
var import_navigation = require("next/navigation");
|
|
39
|
-
var React = __toESM(require("react"), 1);
|
|
40
|
-
var import_htmlescape = require("./htmlescape.cjs");
|
|
41
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
-
var serializedSymbol = Symbol("serialized");
|
|
43
|
-
function createHydrationStreamProvider() {
|
|
44
|
-
const context = React.createContext(
|
|
45
|
-
null
|
|
46
|
-
);
|
|
47
|
-
function UseClientHydrationStreamProvider(props) {
|
|
48
|
-
var _a;
|
|
49
|
-
const id = `__RQ${React.useId()}`;
|
|
50
|
-
const idJSON = (0, import_htmlescape.htmlEscapeJsonString)(JSON.stringify(id));
|
|
51
|
-
const [transformer] = React.useState(
|
|
52
|
-
() => props.transformer ?? {
|
|
53
|
-
// noop
|
|
54
|
-
serialize: (obj) => obj,
|
|
55
|
-
deserialize: (obj) => obj
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
const [stream] = React.useState(() => {
|
|
59
|
-
if (!import_react_query.isServer) {
|
|
60
|
-
return {
|
|
61
|
-
push() {
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return [];
|
|
66
|
-
});
|
|
67
|
-
const count = React.useRef(0);
|
|
68
|
-
(0, import_navigation.useServerInsertedHTML)(() => {
|
|
69
|
-
var _a2;
|
|
70
|
-
stream.push(...((_a2 = props.onFlush) == null ? void 0 : _a2.call(props)) ?? []);
|
|
71
|
-
if (!stream.length) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const serializedCacheArgs = stream.map((entry) => transformer.serialize(entry)).map((entry) => JSON.stringify(entry)).join(",");
|
|
75
|
-
stream.length = 0;
|
|
76
|
-
const html = [
|
|
77
|
-
`window[${idJSON}] = window[${idJSON}] || [];`,
|
|
78
|
-
`window[${idJSON}].push(${(0, import_htmlescape.htmlEscapeJsonString)(serializedCacheArgs)});`
|
|
79
|
-
];
|
|
80
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
81
|
-
"script",
|
|
82
|
-
{
|
|
83
|
-
nonce: props.nonce,
|
|
84
|
-
dangerouslySetInnerHTML: {
|
|
85
|
-
__html: html.join("")
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
count.current++
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
if (!import_react_query.isServer) {
|
|
92
|
-
const win = window;
|
|
93
|
-
if (!((_a = win[id]) == null ? void 0 : _a.initialized)) {
|
|
94
|
-
const onEntries = (...serializedEntries) => {
|
|
95
|
-
const entries = serializedEntries.map(
|
|
96
|
-
(serialized) => transformer.deserialize(serialized)
|
|
97
|
-
);
|
|
98
|
-
props.onEntries(entries);
|
|
99
|
-
};
|
|
100
|
-
const winStream = win[id] ?? [];
|
|
101
|
-
onEntries(...winStream);
|
|
102
|
-
win[id] = {
|
|
103
|
-
initialized: true,
|
|
104
|
-
push: onEntries
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(context.Provider, { value: { stream, id }, children: props.children });
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
Provider: UseClientHydrationStreamProvider,
|
|
112
|
-
context
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 && (module.exports = {
|
|
117
|
-
createHydrationStreamProvider
|
|
118
|
-
});
|
|
119
|
-
//# sourceMappingURL=HydrationStreamProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/HydrationStreamProvider.tsx"],"sourcesContent":["'use client'\n\nimport { isServer } from '@tanstack/react-query'\nimport { useServerInsertedHTML } from 'next/navigation'\nimport * as React from 'react'\nimport { htmlEscapeJsonString } from './htmlescape'\n\nconst serializedSymbol = Symbol('serialized')\n\ninterface DataTransformer {\n serialize: (object: any) => any\n deserialize: (object: any) => any\n}\n\ntype Serialized<TData> = unknown & {\n [serializedSymbol]: TData\n}\n\ninterface TypedDataTransformer<TData> {\n serialize: (obj: TData) => Serialized<TData>\n deserialize: (obj: Serialized<TData>) => TData\n}\n\ninterface HydrationStreamContext<TShape> {\n id: string\n stream: {\n /**\n * **Server method**\n * Push a new entry to the stream\n * Will be ignored on the client\n */\n push: (...shape: Array<TShape>) => void\n }\n}\n\nexport interface HydrationStreamProviderProps<TShape> {\n children: React.ReactNode\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string\n}\n\nexport function createHydrationStreamProvider<TShape>() {\n const context = React.createContext<HydrationStreamContext<TShape>>(\n null as any,\n )\n /**\n\n * 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes\n * - This means that we might have some new entries in the cache that needs to be flushed\n * - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`\n * 2. (Happens in browser) In `useEffect()`:\n * - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries\n * - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received\n **/\n function UseClientHydrationStreamProvider(props: {\n children: React.ReactNode\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string\n }) {\n // unique id for the cache provider\n const id = `__RQ${React.useId()}`\n const idJSON = htmlEscapeJsonString(JSON.stringify(id))\n\n const [transformer] = React.useState(\n () =>\n (props.transformer ?? {\n // noop\n serialize: (obj: any) => obj,\n deserialize: (obj: any) => obj,\n }) as unknown as TypedDataTransformer<TShape>,\n )\n\n // <server stuff>\n const [stream] = React.useState<Array<TShape>>(() => {\n if (!isServer) {\n return {\n push() {\n // no-op on the client\n },\n } as unknown as Array<TShape>\n }\n return []\n })\n const count = React.useRef(0)\n useServerInsertedHTML(() => {\n // This only happens on the server\n stream.push(...(props.onFlush?.() ?? []))\n\n if (!stream.length) {\n return null\n }\n // console.log(`pushing ${stream.length} entries`)\n const serializedCacheArgs = stream\n .map((entry) => transformer.serialize(entry))\n .map((entry) => JSON.stringify(entry))\n .join(',')\n\n // Flush stream\n // eslint-disable-next-line react-hooks/immutability\n stream.length = 0\n\n const html: Array<string> = [\n `window[${idJSON}] = window[${idJSON}] || [];`,\n `window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`,\n ]\n return (\n <script\n key={count.current++}\n nonce={props.nonce}\n dangerouslySetInnerHTML={{\n __html: html.join(''),\n }}\n />\n )\n })\n // </server stuff>\n\n // <client stuff>\n // Setup and run the onEntries handler on the client only, but do it during\n // the initial render so children have access to the data immediately\n // This is important to avoid the client suspending during the initial render\n // if the data has not yet been hydrated.\n if (!isServer) {\n const win = window as any\n if (!win[id]?.initialized) {\n // Client: consume cache:\n const onEntries = (...serializedEntries: Array<Serialized<TShape>>) => {\n const entries = serializedEntries.map((serialized) =>\n transformer.deserialize(serialized),\n )\n props.onEntries(entries)\n }\n\n const winStream: Array<Serialized<TShape>> = win[id] ?? []\n\n onEntries(...winStream)\n\n // eslint-disable-next-line react-hooks/immutability\n win[id] = {\n initialized: true,\n push: onEntries,\n }\n }\n }\n // </client stuff>\n\n return (\n <context.Provider value={{ stream, id }}>\n {props.children}\n </context.Provider>\n )\n }\n\n return {\n Provider: UseClientHydrationStreamProvider,\n context,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAyB;AACzB,wBAAsC;AACtC,YAAuB;AACvB,wBAAqC;AAuI7B;AArIR,IAAM,mBAAmB,OAAO,YAAY;AAmDrC,SAAS,gCAAwC;AACtD,QAAM,UAAgB;AAAA,IACpB;AAAA,EACF;AAUA,WAAS,iCAAiC,OAqBvC;AA5FL;AA8FI,UAAM,KAAK,OAAa,YAAM,CAAC;AAC/B,UAAM,aAAS,wCAAqB,KAAK,UAAU,EAAE,CAAC;AAEtD,UAAM,CAAC,WAAW,IAAU;AAAA,MAC1B,MACG,MAAM,eAAe;AAAA;AAAA,QAEpB,WAAW,CAAC,QAAa;AAAA,QACzB,aAAa,CAAC,QAAa;AAAA,MAC7B;AAAA,IACJ;AAGA,UAAM,CAAC,MAAM,IAAU,eAAwB,MAAM;AACnD,UAAI,CAAC,6BAAU;AACb,eAAO;AAAA,UACL,OAAO;AAAA,UAEP;AAAA,QACF;AAAA,MACF;AACA,aAAO,CAAC;AAAA,IACV,CAAC;AACD,UAAM,QAAc,aAAO,CAAC;AAC5B,iDAAsB,MAAM;AAtHhC,UAAAA;AAwHM,aAAO,KAAK,KAAIA,MAAA,MAAM,YAAN,gBAAAA,IAAA,gBAAqB,CAAC,CAAE;AAExC,UAAI,CAAC,OAAO,QAAQ;AAClB,eAAO;AAAA,MACT;AAEA,YAAM,sBAAsB,OACzB,IAAI,CAAC,UAAU,YAAY,UAAU,KAAK,CAAC,EAC3C,IAAI,CAAC,UAAU,KAAK,UAAU,KAAK,CAAC,EACpC,KAAK,GAAG;AAIX,aAAO,SAAS;AAEhB,YAAM,OAAsB;AAAA,QAC1B,UAAU,MAAM,cAAc,MAAM;AAAA,QACpC,UAAU,MAAM,cAAU,wCAAqB,mBAAmB,CAAC;AAAA,MACrE;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,OAAO,MAAM;AAAA,UACb,yBAAyB;AAAA,YACvB,QAAQ,KAAK,KAAK,EAAE;AAAA,UACtB;AAAA;AAAA,QAJK,MAAM;AAAA,MAKb;AAAA,IAEJ,CAAC;AAQD,QAAI,CAAC,6BAAU;AACb,YAAM,MAAM;AACZ,UAAI,GAAC,SAAI,EAAE,MAAN,mBAAS,cAAa;AAEzB,cAAM,YAAY,IAAI,sBAAiD;AACrE,gBAAM,UAAU,kBAAkB;AAAA,YAAI,CAAC,eACrC,YAAY,YAAY,UAAU;AAAA,UACpC;AACA,gBAAM,UAAU,OAAO;AAAA,QACzB;AAEA,cAAM,YAAuC,IAAI,EAAE,KAAK,CAAC;AAEzD,kBAAU,GAAG,SAAS;AAGtB,YAAI,EAAE,IAAI;AAAA,UACR,aAAa;AAAA,UACb,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,WACE,4CAAC,QAAQ,UAAR,EAAiB,OAAO,EAAE,QAAQ,GAAG,GACnC,gBAAM,UACT;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;","names":["_a"]}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
interface DataTransformer {
|
|
5
|
-
serialize: (object: any) => any;
|
|
6
|
-
deserialize: (object: any) => any;
|
|
7
|
-
}
|
|
8
|
-
interface HydrationStreamContext<TShape> {
|
|
9
|
-
id: string;
|
|
10
|
-
stream: {
|
|
11
|
-
/**
|
|
12
|
-
* **Server method**
|
|
13
|
-
* Push a new entry to the stream
|
|
14
|
-
* Will be ignored on the client
|
|
15
|
-
*/
|
|
16
|
-
push: (...shape: Array<TShape>) => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
interface HydrationStreamProviderProps<TShape> {
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
/**
|
|
22
|
-
* Optional transformer to serialize/deserialize the data
|
|
23
|
-
* Example devalue, superjson et al
|
|
24
|
-
*/
|
|
25
|
-
transformer?: DataTransformer;
|
|
26
|
-
/**
|
|
27
|
-
* **Client method**
|
|
28
|
-
* Called in the browser when new entries are received
|
|
29
|
-
*/
|
|
30
|
-
onEntries: (entries: Array<TShape>) => void;
|
|
31
|
-
/**
|
|
32
|
-
* **Server method**
|
|
33
|
-
* onFlush is called on the server when the cache is flushed
|
|
34
|
-
*/
|
|
35
|
-
onFlush?: () => Array<TShape>;
|
|
36
|
-
/**
|
|
37
|
-
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
38
|
-
*/
|
|
39
|
-
nonce?: string;
|
|
40
|
-
}
|
|
41
|
-
declare function createHydrationStreamProvider<TShape>(): {
|
|
42
|
-
Provider: (props: {
|
|
43
|
-
children: React.ReactNode;
|
|
44
|
-
/**
|
|
45
|
-
* Optional transformer to serialize/deserialize the data
|
|
46
|
-
* Example devalue, superjson et al
|
|
47
|
-
*/
|
|
48
|
-
transformer?: DataTransformer;
|
|
49
|
-
/**
|
|
50
|
-
* **Client method**
|
|
51
|
-
* Called in the browser when new entries are received
|
|
52
|
-
*/
|
|
53
|
-
onEntries: (entries: Array<TShape>) => void;
|
|
54
|
-
/**
|
|
55
|
-
* **Server method**
|
|
56
|
-
* onFlush is called on the server when the cache is flushed
|
|
57
|
-
*/
|
|
58
|
-
onFlush?: () => Array<TShape>;
|
|
59
|
-
/**
|
|
60
|
-
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
61
|
-
*/
|
|
62
|
-
nonce?: string;
|
|
63
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
64
|
-
context: React.Context<HydrationStreamContext<TShape>>;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { type HydrationStreamProviderProps, createHydrationStreamProvider };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
interface DataTransformer {
|
|
5
|
-
serialize: (object: any) => any;
|
|
6
|
-
deserialize: (object: any) => any;
|
|
7
|
-
}
|
|
8
|
-
interface HydrationStreamContext<TShape> {
|
|
9
|
-
id: string;
|
|
10
|
-
stream: {
|
|
11
|
-
/**
|
|
12
|
-
* **Server method**
|
|
13
|
-
* Push a new entry to the stream
|
|
14
|
-
* Will be ignored on the client
|
|
15
|
-
*/
|
|
16
|
-
push: (...shape: Array<TShape>) => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
interface HydrationStreamProviderProps<TShape> {
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
/**
|
|
22
|
-
* Optional transformer to serialize/deserialize the data
|
|
23
|
-
* Example devalue, superjson et al
|
|
24
|
-
*/
|
|
25
|
-
transformer?: DataTransformer;
|
|
26
|
-
/**
|
|
27
|
-
* **Client method**
|
|
28
|
-
* Called in the browser when new entries are received
|
|
29
|
-
*/
|
|
30
|
-
onEntries: (entries: Array<TShape>) => void;
|
|
31
|
-
/**
|
|
32
|
-
* **Server method**
|
|
33
|
-
* onFlush is called on the server when the cache is flushed
|
|
34
|
-
*/
|
|
35
|
-
onFlush?: () => Array<TShape>;
|
|
36
|
-
/**
|
|
37
|
-
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
38
|
-
*/
|
|
39
|
-
nonce?: string;
|
|
40
|
-
}
|
|
41
|
-
declare function createHydrationStreamProvider<TShape>(): {
|
|
42
|
-
Provider: (props: {
|
|
43
|
-
children: React.ReactNode;
|
|
44
|
-
/**
|
|
45
|
-
* Optional transformer to serialize/deserialize the data
|
|
46
|
-
* Example devalue, superjson et al
|
|
47
|
-
*/
|
|
48
|
-
transformer?: DataTransformer;
|
|
49
|
-
/**
|
|
50
|
-
* **Client method**
|
|
51
|
-
* Called in the browser when new entries are received
|
|
52
|
-
*/
|
|
53
|
-
onEntries: (entries: Array<TShape>) => void;
|
|
54
|
-
/**
|
|
55
|
-
* **Server method**
|
|
56
|
-
* onFlush is called on the server when the cache is flushed
|
|
57
|
-
*/
|
|
58
|
-
onFlush?: () => Array<TShape>;
|
|
59
|
-
/**
|
|
60
|
-
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
61
|
-
*/
|
|
62
|
-
nonce?: string;
|
|
63
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
64
|
-
context: React.Context<HydrationStreamContext<TShape>>;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { type HydrationStreamProviderProps, createHydrationStreamProvider };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/HydrationStreamProvider.tsx
|
|
4
|
-
import { isServer } from "@tanstack/react-query";
|
|
5
|
-
import { useServerInsertedHTML } from "next/navigation";
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import { htmlEscapeJsonString } from "./htmlescape.js";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
var serializedSymbol = Symbol("serialized");
|
|
10
|
-
function createHydrationStreamProvider() {
|
|
11
|
-
const context = React.createContext(
|
|
12
|
-
null
|
|
13
|
-
);
|
|
14
|
-
function UseClientHydrationStreamProvider(props) {
|
|
15
|
-
var _a;
|
|
16
|
-
const id = `__RQ${React.useId()}`;
|
|
17
|
-
const idJSON = htmlEscapeJsonString(JSON.stringify(id));
|
|
18
|
-
const [transformer] = React.useState(
|
|
19
|
-
() => props.transformer ?? {
|
|
20
|
-
// noop
|
|
21
|
-
serialize: (obj) => obj,
|
|
22
|
-
deserialize: (obj) => obj
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
const [stream] = React.useState(() => {
|
|
26
|
-
if (!isServer) {
|
|
27
|
-
return {
|
|
28
|
-
push() {
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return [];
|
|
33
|
-
});
|
|
34
|
-
const count = React.useRef(0);
|
|
35
|
-
useServerInsertedHTML(() => {
|
|
36
|
-
var _a2;
|
|
37
|
-
stream.push(...((_a2 = props.onFlush) == null ? void 0 : _a2.call(props)) ?? []);
|
|
38
|
-
if (!stream.length) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const serializedCacheArgs = stream.map((entry) => transformer.serialize(entry)).map((entry) => JSON.stringify(entry)).join(",");
|
|
42
|
-
stream.length = 0;
|
|
43
|
-
const html = [
|
|
44
|
-
`window[${idJSON}] = window[${idJSON}] || [];`,
|
|
45
|
-
`window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`
|
|
46
|
-
];
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
"script",
|
|
49
|
-
{
|
|
50
|
-
nonce: props.nonce,
|
|
51
|
-
dangerouslySetInnerHTML: {
|
|
52
|
-
__html: html.join("")
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
count.current++
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
if (!isServer) {
|
|
59
|
-
const win = window;
|
|
60
|
-
if (!((_a = win[id]) == null ? void 0 : _a.initialized)) {
|
|
61
|
-
const onEntries = (...serializedEntries) => {
|
|
62
|
-
const entries = serializedEntries.map(
|
|
63
|
-
(serialized) => transformer.deserialize(serialized)
|
|
64
|
-
);
|
|
65
|
-
props.onEntries(entries);
|
|
66
|
-
};
|
|
67
|
-
const winStream = win[id] ?? [];
|
|
68
|
-
onEntries(...winStream);
|
|
69
|
-
win[id] = {
|
|
70
|
-
initialized: true,
|
|
71
|
-
push: onEntries
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return /* @__PURE__ */ jsx(context.Provider, { value: { stream, id }, children: props.children });
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
Provider: UseClientHydrationStreamProvider,
|
|
79
|
-
context
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export {
|
|
83
|
-
createHydrationStreamProvider
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=HydrationStreamProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/HydrationStreamProvider.tsx"],"sourcesContent":["'use client'\n\nimport { isServer } from '@tanstack/react-query'\nimport { useServerInsertedHTML } from 'next/navigation'\nimport * as React from 'react'\nimport { htmlEscapeJsonString } from './htmlescape'\n\nconst serializedSymbol = Symbol('serialized')\n\ninterface DataTransformer {\n serialize: (object: any) => any\n deserialize: (object: any) => any\n}\n\ntype Serialized<TData> = unknown & {\n [serializedSymbol]: TData\n}\n\ninterface TypedDataTransformer<TData> {\n serialize: (obj: TData) => Serialized<TData>\n deserialize: (obj: Serialized<TData>) => TData\n}\n\ninterface HydrationStreamContext<TShape> {\n id: string\n stream: {\n /**\n * **Server method**\n * Push a new entry to the stream\n * Will be ignored on the client\n */\n push: (...shape: Array<TShape>) => void\n }\n}\n\nexport interface HydrationStreamProviderProps<TShape> {\n children: React.ReactNode\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string\n}\n\nexport function createHydrationStreamProvider<TShape>() {\n const context = React.createContext<HydrationStreamContext<TShape>>(\n null as any,\n )\n /**\n\n * 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes\n * - This means that we might have some new entries in the cache that needs to be flushed\n * - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`\n * 2. (Happens in browser) In `useEffect()`:\n * - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries\n * - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received\n **/\n function UseClientHydrationStreamProvider(props: {\n children: React.ReactNode\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string\n }) {\n // unique id for the cache provider\n const id = `__RQ${React.useId()}`\n const idJSON = htmlEscapeJsonString(JSON.stringify(id))\n\n const [transformer] = React.useState(\n () =>\n (props.transformer ?? {\n // noop\n serialize: (obj: any) => obj,\n deserialize: (obj: any) => obj,\n }) as unknown as TypedDataTransformer<TShape>,\n )\n\n // <server stuff>\n const [stream] = React.useState<Array<TShape>>(() => {\n if (!isServer) {\n return {\n push() {\n // no-op on the client\n },\n } as unknown as Array<TShape>\n }\n return []\n })\n const count = React.useRef(0)\n useServerInsertedHTML(() => {\n // This only happens on the server\n stream.push(...(props.onFlush?.() ?? []))\n\n if (!stream.length) {\n return null\n }\n // console.log(`pushing ${stream.length} entries`)\n const serializedCacheArgs = stream\n .map((entry) => transformer.serialize(entry))\n .map((entry) => JSON.stringify(entry))\n .join(',')\n\n // Flush stream\n // eslint-disable-next-line react-hooks/immutability\n stream.length = 0\n\n const html: Array<string> = [\n `window[${idJSON}] = window[${idJSON}] || [];`,\n `window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`,\n ]\n return (\n <script\n key={count.current++}\n nonce={props.nonce}\n dangerouslySetInnerHTML={{\n __html: html.join(''),\n }}\n />\n )\n })\n // </server stuff>\n\n // <client stuff>\n // Setup and run the onEntries handler on the client only, but do it during\n // the initial render so children have access to the data immediately\n // This is important to avoid the client suspending during the initial render\n // if the data has not yet been hydrated.\n if (!isServer) {\n const win = window as any\n if (!win[id]?.initialized) {\n // Client: consume cache:\n const onEntries = (...serializedEntries: Array<Serialized<TShape>>) => {\n const entries = serializedEntries.map((serialized) =>\n transformer.deserialize(serialized),\n )\n props.onEntries(entries)\n }\n\n const winStream: Array<Serialized<TShape>> = win[id] ?? []\n\n onEntries(...winStream)\n\n // eslint-disable-next-line react-hooks/immutability\n win[id] = {\n initialized: true,\n push: onEntries,\n }\n }\n }\n // </client stuff>\n\n return (\n <context.Provider value={{ stream, id }}>\n {props.children}\n </context.Provider>\n )\n }\n\n return {\n Provider: UseClientHydrationStreamProvider,\n context,\n }\n}\n"],"mappings":";;;AAEA,SAAS,gBAAgB;AACzB,SAAS,6BAA6B;AACtC,YAAY,WAAW;AACvB,SAAS,4BAA4B;AAuI7B;AArIR,IAAM,mBAAmB,OAAO,YAAY;AAmDrC,SAAS,gCAAwC;AACtD,QAAM,UAAgB;AAAA,IACpB;AAAA,EACF;AAUA,WAAS,iCAAiC,OAqBvC;AA5FL;AA8FI,UAAM,KAAK,OAAa,YAAM,CAAC;AAC/B,UAAM,SAAS,qBAAqB,KAAK,UAAU,EAAE,CAAC;AAEtD,UAAM,CAAC,WAAW,IAAU;AAAA,MAC1B,MACG,MAAM,eAAe;AAAA;AAAA,QAEpB,WAAW,CAAC,QAAa;AAAA,QACzB,aAAa,CAAC,QAAa;AAAA,MAC7B;AAAA,IACJ;AAGA,UAAM,CAAC,MAAM,IAAU,eAAwB,MAAM;AACnD,UAAI,CAAC,UAAU;AACb,eAAO;AAAA,UACL,OAAO;AAAA,UAEP;AAAA,QACF;AAAA,MACF;AACA,aAAO,CAAC;AAAA,IACV,CAAC;AACD,UAAM,QAAc,aAAO,CAAC;AAC5B,0BAAsB,MAAM;AAtHhC,UAAAA;AAwHM,aAAO,KAAK,KAAIA,MAAA,MAAM,YAAN,gBAAAA,IAAA,gBAAqB,CAAC,CAAE;AAExC,UAAI,CAAC,OAAO,QAAQ;AAClB,eAAO;AAAA,MACT;AAEA,YAAM,sBAAsB,OACzB,IAAI,CAAC,UAAU,YAAY,UAAU,KAAK,CAAC,EAC3C,IAAI,CAAC,UAAU,KAAK,UAAU,KAAK,CAAC,EACpC,KAAK,GAAG;AAIX,aAAO,SAAS;AAEhB,YAAM,OAAsB;AAAA,QAC1B,UAAU,MAAM,cAAc,MAAM;AAAA,QACpC,UAAU,MAAM,UAAU,qBAAqB,mBAAmB,CAAC;AAAA,MACrE;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,OAAO,MAAM;AAAA,UACb,yBAAyB;AAAA,YACvB,QAAQ,KAAK,KAAK,EAAE;AAAA,UACtB;AAAA;AAAA,QAJK,MAAM;AAAA,MAKb;AAAA,IAEJ,CAAC;AAQD,QAAI,CAAC,UAAU;AACb,YAAM,MAAM;AACZ,UAAI,GAAC,SAAI,EAAE,MAAN,mBAAS,cAAa;AAEzB,cAAM,YAAY,IAAI,sBAAiD;AACrE,gBAAM,UAAU,kBAAkB;AAAA,YAAI,CAAC,eACrC,YAAY,YAAY,UAAU;AAAA,UACpC;AACA,gBAAM,UAAU,OAAO;AAAA,QACzB;AAEA,cAAM,YAAuC,IAAI,EAAE,KAAK,CAAC;AAEzD,kBAAU,GAAG,SAAS;AAGtB,YAAI,EAAE,IAAI;AAAA,UACR,aAAa;AAAA,UACb,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,WACE,oBAAC,QAAQ,UAAR,EAAiB,OAAO,EAAE,QAAQ,GAAG,GACnC,gBAAM,UACT;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;","names":["_a"]}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/ReactQueryStreamedHydration.tsx
|
|
32
|
-
var ReactQueryStreamedHydration_exports = {};
|
|
33
|
-
__export(ReactQueryStreamedHydration_exports, {
|
|
34
|
-
ReactQueryStreamedHydration: () => ReactQueryStreamedHydration
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(ReactQueryStreamedHydration_exports);
|
|
37
|
-
var import_react_query = require("@tanstack/react-query");
|
|
38
|
-
var React = __toESM(require("react"), 1);
|
|
39
|
-
var import_HydrationStreamProvider = require("./HydrationStreamProvider.cjs");
|
|
40
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
-
var stream = (0, import_HydrationStreamProvider.createHydrationStreamProvider)();
|
|
42
|
-
function ReactQueryStreamedHydration(props) {
|
|
43
|
-
const queryClient = (0, import_react_query.useQueryClient)(props.queryClient);
|
|
44
|
-
const [trackedKeys] = React.useState(() => /* @__PURE__ */ new Set());
|
|
45
|
-
if (import_react_query.isServer) {
|
|
46
|
-
queryClient.getQueryCache().subscribe((event) => {
|
|
47
|
-
switch (event.type) {
|
|
48
|
-
case "added":
|
|
49
|
-
case "updated":
|
|
50
|
-
trackedKeys.add(event.query.queryHash);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
|
-
stream.Provider,
|
|
56
|
-
{
|
|
57
|
-
onFlush: () => {
|
|
58
|
-
var _a, _b, _c;
|
|
59
|
-
const shouldDehydrate = ((_b = (_a = props.options) == null ? void 0 : _a.dehydrate) == null ? void 0 : _b.shouldDehydrateQuery) ?? import_react_query.defaultShouldDehydrateQuery;
|
|
60
|
-
const dehydratedState = (0, import_react_query.dehydrate)(queryClient, {
|
|
61
|
-
...(_c = props.options) == null ? void 0 : _c.dehydrate,
|
|
62
|
-
shouldDehydrateQuery(query) {
|
|
63
|
-
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
trackedKeys.clear();
|
|
67
|
-
if (!dehydratedState.queries.length) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
return [dehydratedState];
|
|
71
|
-
},
|
|
72
|
-
onEntries: (entries) => {
|
|
73
|
-
var _a;
|
|
74
|
-
for (const hydratedState of entries) {
|
|
75
|
-
(0, import_react_query.hydrate)(queryClient, hydratedState, (_a = props.options) == null ? void 0 : _a.hydrate);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
transformer: props.transformer,
|
|
79
|
-
nonce: props.nonce,
|
|
80
|
-
children: props.children
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
ReactQueryStreamedHydration
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=ReactQueryStreamedHydration.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n isServer,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n nonce?: string\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (isServer) {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n nonce={props.nonce}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAMO;AACP,YAAuB;AACvB,qCAA8C;AAgD1C;AAvCJ,IAAM,aAAS,8DAA+C;AAOvD,SAAS,4BAA4B,OASzC;AACD,QAAM,kBAAc,mCAAe,MAAM,WAAW;AAKpD,QAAM,CAAC,WAAW,IAAU,eAAS,MAAM,oBAAI,IAAY,CAAC;AAG5D,MAAI,6BAAU;AAEZ,gBAAY,cAAc,EAAE,UAAU,CAAC,UAAU;AAC/C,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AAAA,QACL,KAAK;AAEH,sBAAY,IAAI,MAAM,MAAM,SAAS;AAAA,MACzC;AAAA,IACF,CAAC;AAAA,EACH;AAGA,SACE;AAAA,IAAC,OAAO;AAAA,IAAP;AAAA,MAEC,SAAS,MAAM;AA5DrB;AAgEQ,cAAM,oBACJ,iBAAM,YAAN,mBAAe,cAAf,mBAA0B,yBAC1B;AAEF,cAAM,sBAAkB,8BAAU,aAAa;AAAA,UAC7C,IAAG,WAAM,YAAN,mBAAe;AAAA,UAClB,qBAAqB,OAAO;AAC1B,mBAAO,YAAY,IAAI,MAAM,SAAS,KAAK,gBAAgB,KAAK;AAAA,UAClE;AAAA,QACF,CAAC;AACD,oBAAY,MAAM;AAElB,YAAI,CAAC,gBAAgB,QAAQ,QAAQ;AACnC,iBAAO,CAAC;AAAA,QACV;AAEA,eAAO,CAAC,eAAe;AAAA,MACzB;AAAA,MAEA,WAAW,CAAC,YAAY;AAnF9B;AAoFQ,mBAAW,iBAAiB,SAAS;AACnC,0CAAQ,aAAa,gBAAe,WAAM,YAAN,mBAAe,OAAO;AAAA,QAC5D;AAAA,MACF;AAAA,MAEA,aAAa,MAAM;AAAA,MACnB,OAAO,MAAM;AAAA,MAEZ,gBAAM;AAAA;AAAA,EACT;AAEJ;","names":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { HydrationStreamProviderProps } from './HydrationStreamProvider.cjs';
|
|
4
|
-
import { QueryClient, HydrateOptions, DehydrateOptions, DehydratedState } from '@tanstack/react-query';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This component is responsible for:
|
|
8
|
-
* - hydrating the query client on the server
|
|
9
|
-
* - dehydrating the query client on the server
|
|
10
|
-
*/
|
|
11
|
-
declare function ReactQueryStreamedHydration(props: {
|
|
12
|
-
children: React.ReactNode;
|
|
13
|
-
queryClient?: QueryClient;
|
|
14
|
-
nonce?: string;
|
|
15
|
-
options?: {
|
|
16
|
-
hydrate?: HydrateOptions;
|
|
17
|
-
dehydrate?: DehydrateOptions;
|
|
18
|
-
};
|
|
19
|
-
transformer?: HydrationStreamProviderProps<DehydratedState>['transformer'];
|
|
20
|
-
}): react_jsx_runtime.JSX.Element;
|
|
21
|
-
|
|
22
|
-
export { ReactQueryStreamedHydration };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { HydrationStreamProviderProps } from './HydrationStreamProvider.js';
|
|
4
|
-
import { QueryClient, HydrateOptions, DehydrateOptions, DehydratedState } from '@tanstack/react-query';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This component is responsible for:
|
|
8
|
-
* - hydrating the query client on the server
|
|
9
|
-
* - dehydrating the query client on the server
|
|
10
|
-
*/
|
|
11
|
-
declare function ReactQueryStreamedHydration(props: {
|
|
12
|
-
children: React.ReactNode;
|
|
13
|
-
queryClient?: QueryClient;
|
|
14
|
-
nonce?: string;
|
|
15
|
-
options?: {
|
|
16
|
-
hydrate?: HydrateOptions;
|
|
17
|
-
dehydrate?: DehydrateOptions;
|
|
18
|
-
};
|
|
19
|
-
transformer?: HydrationStreamProviderProps<DehydratedState>['transformer'];
|
|
20
|
-
}): react_jsx_runtime.JSX.Element;
|
|
21
|
-
|
|
22
|
-
export { ReactQueryStreamedHydration };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/ReactQueryStreamedHydration.tsx
|
|
4
|
-
import {
|
|
5
|
-
defaultShouldDehydrateQuery,
|
|
6
|
-
dehydrate,
|
|
7
|
-
hydrate,
|
|
8
|
-
isServer,
|
|
9
|
-
useQueryClient
|
|
10
|
-
} from "@tanstack/react-query";
|
|
11
|
-
import * as React from "react";
|
|
12
|
-
import { createHydrationStreamProvider } from "./HydrationStreamProvider.js";
|
|
13
|
-
import { jsx } from "react/jsx-runtime";
|
|
14
|
-
var stream = createHydrationStreamProvider();
|
|
15
|
-
function ReactQueryStreamedHydration(props) {
|
|
16
|
-
const queryClient = useQueryClient(props.queryClient);
|
|
17
|
-
const [trackedKeys] = React.useState(() => /* @__PURE__ */ new Set());
|
|
18
|
-
if (isServer) {
|
|
19
|
-
queryClient.getQueryCache().subscribe((event) => {
|
|
20
|
-
switch (event.type) {
|
|
21
|
-
case "added":
|
|
22
|
-
case "updated":
|
|
23
|
-
trackedKeys.add(event.query.queryHash);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return /* @__PURE__ */ jsx(
|
|
28
|
-
stream.Provider,
|
|
29
|
-
{
|
|
30
|
-
onFlush: () => {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
const shouldDehydrate = ((_b = (_a = props.options) == null ? void 0 : _a.dehydrate) == null ? void 0 : _b.shouldDehydrateQuery) ?? defaultShouldDehydrateQuery;
|
|
33
|
-
const dehydratedState = dehydrate(queryClient, {
|
|
34
|
-
...(_c = props.options) == null ? void 0 : _c.dehydrate,
|
|
35
|
-
shouldDehydrateQuery(query) {
|
|
36
|
-
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
trackedKeys.clear();
|
|
40
|
-
if (!dehydratedState.queries.length) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
return [dehydratedState];
|
|
44
|
-
},
|
|
45
|
-
onEntries: (entries) => {
|
|
46
|
-
var _a;
|
|
47
|
-
for (const hydratedState of entries) {
|
|
48
|
-
hydrate(queryClient, hydratedState, (_a = props.options) == null ? void 0 : _a.hydrate);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
transformer: props.transformer,
|
|
52
|
-
nonce: props.nonce,
|
|
53
|
-
children: props.children
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
58
|
-
ReactQueryStreamedHydration
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=ReactQueryStreamedHydration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n isServer,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n nonce?: string\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (isServer) {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n nonce={props.nonce}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,YAAY,WAAW;AACvB,SAAS,qCAAqC;AAgD1C;AAvCJ,IAAM,SAAS,8BAA+C;AAOvD,SAAS,4BAA4B,OASzC;AACD,QAAM,cAAc,eAAe,MAAM,WAAW;AAKpD,QAAM,CAAC,WAAW,IAAU,eAAS,MAAM,oBAAI,IAAY,CAAC;AAG5D,MAAI,UAAU;AAEZ,gBAAY,cAAc,EAAE,UAAU,CAAC,UAAU;AAC/C,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AAAA,QACL,KAAK;AAEH,sBAAY,IAAI,MAAM,MAAM,SAAS;AAAA,MACzC;AAAA,IACF,CAAC;AAAA,EACH;AAGA,SACE;AAAA,IAAC,OAAO;AAAA,IAAP;AAAA,MAEC,SAAS,MAAM;AA5DrB;AAgEQ,cAAM,oBACJ,iBAAM,YAAN,mBAAe,cAAf,mBAA0B,yBAC1B;AAEF,cAAM,kBAAkB,UAAU,aAAa;AAAA,UAC7C,IAAG,WAAM,YAAN,mBAAe;AAAA,UAClB,qBAAqB,OAAO;AAC1B,mBAAO,YAAY,IAAI,MAAM,SAAS,KAAK,gBAAgB,KAAK;AAAA,UAClE;AAAA,QACF,CAAC;AACD,oBAAY,MAAM;AAElB,YAAI,CAAC,gBAAgB,QAAQ,QAAQ;AACnC,iBAAO,CAAC;AAAA,QACV;AAEA,eAAO,CAAC,eAAe;AAAA,MACzB;AAAA,MAEA,WAAW,CAAC,YAAY;AAnF9B;AAoFQ,mBAAW,iBAAiB,SAAS;AACnC,kBAAQ,aAAa,gBAAe,WAAM,YAAN,mBAAe,OAAO;AAAA,QAC5D;AAAA,MACF;AAAA,MAEA,aAAa,MAAM;AAAA,MACnB,OAAO,MAAM;AAAA,MAEZ,gBAAM;AAAA;AAAA,EACT;AAEJ;","names":[]}
|