@tanstack/react-query-next-experimental 5.94.4 → 5.94.5

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.
Files changed (53) hide show
  1. package/build/legacy/HydrationStreamProvider.cjs +118 -0
  2. package/build/legacy/HydrationStreamProvider.cjs.map +1 -0
  3. package/build/legacy/HydrationStreamProvider.d.cts +2 -0
  4. package/build/legacy/HydrationStreamProvider.d.ts +2 -0
  5. package/build/legacy/HydrationStreamProvider.js +84 -0
  6. package/build/legacy/HydrationStreamProvider.js.map +1 -0
  7. package/build/legacy/ReactQueryStreamedHydration.cjs +88 -0
  8. package/build/legacy/ReactQueryStreamedHydration.cjs.map +1 -0
  9. package/build/legacy/ReactQueryStreamedHydration.d.cts +1 -0
  10. package/build/legacy/ReactQueryStreamedHydration.d.ts +1 -0
  11. package/build/legacy/ReactQueryStreamedHydration.js +60 -0
  12. package/build/legacy/ReactQueryStreamedHydration.js.map +1 -0
  13. package/build/legacy/_tsup-dts-rollup.d.cts +124 -0
  14. package/build/legacy/_tsup-dts-rollup.d.ts +124 -0
  15. package/build/legacy/htmlescape.cjs +43 -0
  16. package/build/legacy/htmlescape.cjs.map +1 -0
  17. package/build/legacy/htmlescape.d.cts +2 -0
  18. package/build/legacy/htmlescape.d.ts +2 -0
  19. package/build/legacy/htmlescape.js +17 -0
  20. package/build/legacy/htmlescape.js.map +1 -0
  21. package/build/legacy/index.cjs +31 -0
  22. package/build/legacy/index.cjs.map +1 -0
  23. package/build/legacy/index.d.cts +1 -0
  24. package/build/legacy/index.d.ts +1 -0
  25. package/build/legacy/index.js +6 -0
  26. package/build/legacy/index.js.map +1 -0
  27. package/build/modern/HydrationStreamProvider.cjs +116 -0
  28. package/build/modern/HydrationStreamProvider.cjs.map +1 -0
  29. package/build/modern/HydrationStreamProvider.d.cts +2 -0
  30. package/build/modern/HydrationStreamProvider.d.ts +2 -0
  31. package/build/modern/HydrationStreamProvider.js +82 -0
  32. package/build/modern/HydrationStreamProvider.js.map +1 -0
  33. package/build/modern/ReactQueryStreamedHydration.cjs +86 -0
  34. package/build/modern/ReactQueryStreamedHydration.cjs.map +1 -0
  35. package/build/modern/ReactQueryStreamedHydration.d.cts +1 -0
  36. package/build/modern/ReactQueryStreamedHydration.d.ts +1 -0
  37. package/build/modern/ReactQueryStreamedHydration.js +58 -0
  38. package/build/modern/ReactQueryStreamedHydration.js.map +1 -0
  39. package/build/modern/_tsup-dts-rollup.d.cts +124 -0
  40. package/build/modern/_tsup-dts-rollup.d.ts +124 -0
  41. package/build/modern/htmlescape.cjs +43 -0
  42. package/build/modern/htmlescape.cjs.map +1 -0
  43. package/build/modern/htmlescape.d.cts +2 -0
  44. package/build/modern/htmlescape.d.ts +2 -0
  45. package/build/modern/htmlescape.js +17 -0
  46. package/build/modern/htmlescape.js.map +1 -0
  47. package/build/modern/index.cjs +31 -0
  48. package/build/modern/index.cjs.map +1 -0
  49. package/build/modern/index.d.cts +1 -0
  50. package/build/modern/index.d.ts +1 -0
  51. package/build/modern/index.js +6 -0
  52. package/build/modern/index.js.map +1 -0
  53. package/package.json +3 -3
@@ -0,0 +1,118 @@
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
+ function createHydrationStreamProvider() {
43
+ const context = React.createContext(
44
+ null
45
+ );
46
+ function UseClientHydrationStreamProvider(props) {
47
+ var _a;
48
+ const id = `__RQ${React.useId()}`;
49
+ const idJSON = (0, import_htmlescape.htmlEscapeJsonString)(JSON.stringify(id));
50
+ const [transformer] = React.useState(
51
+ () => props.transformer ?? {
52
+ // noop
53
+ serialize: (obj) => obj,
54
+ deserialize: (obj) => obj
55
+ }
56
+ );
57
+ const [stream] = React.useState(() => {
58
+ if (!import_react_query.isServer) {
59
+ return {
60
+ push() {
61
+ }
62
+ };
63
+ }
64
+ return [];
65
+ });
66
+ const count = React.useRef(0);
67
+ (0, import_navigation.useServerInsertedHTML)(() => {
68
+ var _a2;
69
+ stream.push(...((_a2 = props.onFlush) == null ? void 0 : _a2.call(props)) ?? []);
70
+ if (!stream.length) {
71
+ return null;
72
+ }
73
+ const serializedCacheArgs = stream.map((entry) => transformer.serialize(entry)).map((entry) => JSON.stringify(entry)).join(",");
74
+ stream.length = 0;
75
+ const html = [
76
+ `window[${idJSON}] = window[${idJSON}] || [];`,
77
+ `window[${idJSON}].push(${(0, import_htmlescape.htmlEscapeJsonString)(serializedCacheArgs)});`
78
+ ];
79
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
80
+ "script",
81
+ {
82
+ nonce: props.nonce,
83
+ dangerouslySetInnerHTML: {
84
+ __html: html.join("")
85
+ }
86
+ },
87
+ count.current++
88
+ );
89
+ });
90
+ if (!import_react_query.isServer) {
91
+ const win = window;
92
+ if (!((_a = win[id]) == null ? void 0 : _a.initialized)) {
93
+ const onEntries = (...serializedEntries) => {
94
+ const entries = serializedEntries.map(
95
+ (serialized) => transformer.deserialize(serialized)
96
+ );
97
+ props.onEntries(entries);
98
+ };
99
+ const winStream = win[id] ?? [];
100
+ onEntries(...winStream);
101
+ win[id] = {
102
+ initialized: true,
103
+ push: onEntries
104
+ };
105
+ }
106
+ }
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(context.Provider, { value: { stream, id }, children: props.children });
108
+ }
109
+ return {
110
+ Provider: UseClientHydrationStreamProvider,
111
+ context
112
+ };
113
+ }
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ createHydrationStreamProvider
117
+ });
118
+ //# sourceMappingURL=HydrationStreamProvider.cjs.map
@@ -0,0 +1 @@
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;AAlFD,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"]}
@@ -0,0 +1,2 @@
1
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.cjs';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.js';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.js';
@@ -0,0 +1,84 @@
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
+ function createHydrationStreamProvider() {
10
+ const context = React.createContext(
11
+ null
12
+ );
13
+ function UseClientHydrationStreamProvider(props) {
14
+ var _a;
15
+ const id = `__RQ${React.useId()}`;
16
+ const idJSON = htmlEscapeJsonString(JSON.stringify(id));
17
+ const [transformer] = React.useState(
18
+ () => props.transformer ?? {
19
+ // noop
20
+ serialize: (obj) => obj,
21
+ deserialize: (obj) => obj
22
+ }
23
+ );
24
+ const [stream] = React.useState(() => {
25
+ if (!isServer) {
26
+ return {
27
+ push() {
28
+ }
29
+ };
30
+ }
31
+ return [];
32
+ });
33
+ const count = React.useRef(0);
34
+ useServerInsertedHTML(() => {
35
+ var _a2;
36
+ stream.push(...((_a2 = props.onFlush) == null ? void 0 : _a2.call(props)) ?? []);
37
+ if (!stream.length) {
38
+ return null;
39
+ }
40
+ const serializedCacheArgs = stream.map((entry) => transformer.serialize(entry)).map((entry) => JSON.stringify(entry)).join(",");
41
+ stream.length = 0;
42
+ const html = [
43
+ `window[${idJSON}] = window[${idJSON}] || [];`,
44
+ `window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`
45
+ ];
46
+ return /* @__PURE__ */ jsx(
47
+ "script",
48
+ {
49
+ nonce: props.nonce,
50
+ dangerouslySetInnerHTML: {
51
+ __html: html.join("")
52
+ }
53
+ },
54
+ count.current++
55
+ );
56
+ });
57
+ if (!isServer) {
58
+ const win = window;
59
+ if (!((_a = win[id]) == null ? void 0 : _a.initialized)) {
60
+ const onEntries = (...serializedEntries) => {
61
+ const entries = serializedEntries.map(
62
+ (serialized) => transformer.deserialize(serialized)
63
+ );
64
+ props.onEntries(entries);
65
+ };
66
+ const winStream = win[id] ?? [];
67
+ onEntries(...winStream);
68
+ win[id] = {
69
+ initialized: true,
70
+ push: onEntries
71
+ };
72
+ }
73
+ }
74
+ return /* @__PURE__ */ jsx(context.Provider, { value: { stream, id }, children: props.children });
75
+ }
76
+ return {
77
+ Provider: UseClientHydrationStreamProvider,
78
+ context
79
+ };
80
+ }
81
+ export {
82
+ createHydrationStreamProvider
83
+ };
84
+ //# sourceMappingURL=HydrationStreamProvider.js.map
@@ -0,0 +1 @@
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;AAlFD,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"]}
@@ -0,0 +1,88 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1 @@
1
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.js';
@@ -0,0 +1,60 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,124 @@
1
+ import type { DehydratedState } from '@tanstack/react-query';
2
+ import type { DehydrateOptions } from '@tanstack/react-query';
3
+ import type { HydrateOptions } from '@tanstack/react-query';
4
+ import { JSX } from 'react/jsx-runtime';
5
+ import { Options } from 'tsup';
6
+ import type { QueryClient } from '@tanstack/react-query';
7
+ import * as React_2 from 'react';
8
+ import { UserConfig } from 'vite';
9
+
10
+ export declare function createHydrationStreamProvider<TShape>(): {
11
+ Provider: (props: {
12
+ children: React_2.ReactNode;
13
+ /**
14
+ * Optional transformer to serialize/deserialize the data
15
+ * Example devalue, superjson et al
16
+ */
17
+ transformer?: DataTransformer;
18
+ /**
19
+ * **Client method**
20
+ * Called in the browser when new entries are received
21
+ */
22
+ onEntries: (entries: Array<TShape>) => void;
23
+ /**
24
+ * **Server method**
25
+ * onFlush is called on the server when the cache is flushed
26
+ */
27
+ onFlush?: () => Array<TShape>;
28
+ /**
29
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
30
+ */
31
+ nonce?: string;
32
+ }) => JSX.Element;
33
+ context: React_2.Context<HydrationStreamContext<TShape>>;
34
+ };
35
+
36
+ declare interface DataTransformer {
37
+ serialize: (object: any) => any;
38
+ deserialize: (object: any) => any;
39
+ }
40
+
41
+ export declare const default_alias: any[];
42
+
43
+ export declare const default_alias_1: any[];
44
+
45
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
46
+
47
+ export declare const default_alias_3: UserConfig;
48
+
49
+ export declare const ESCAPE_REGEX: RegExp;
50
+
51
+ export declare function htmlEscapeJsonString(str: string): string;
52
+
53
+ declare interface HydrationStreamContext<TShape> {
54
+ id: string;
55
+ stream: {
56
+ /**
57
+ * **Server method**
58
+ * Push a new entry to the stream
59
+ * Will be ignored on the client
60
+ */
61
+ push: (...shape: Array<TShape>) => void;
62
+ };
63
+ }
64
+
65
+ export declare interface HydrationStreamProviderProps<TShape> {
66
+ children: React_2.ReactNode;
67
+ /**
68
+ * Optional transformer to serialize/deserialize the data
69
+ * Example devalue, superjson et al
70
+ */
71
+ transformer?: DataTransformer;
72
+ /**
73
+ * **Client method**
74
+ * Called in the browser when new entries are received
75
+ */
76
+ onEntries: (entries: Array<TShape>) => void;
77
+ /**
78
+ * **Server method**
79
+ * onFlush is called on the server when the cache is flushed
80
+ */
81
+ onFlush?: () => Array<TShape>;
82
+ /**
83
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
84
+ */
85
+ nonce?: string;
86
+ }
87
+
88
+ /**
89
+ * @param {Object} opts - Options for building configurations.
90
+ * @param {string[]} opts.entry - The entry array.
91
+ * @returns {import('tsup').Options}
92
+ */
93
+ export declare function legacyConfig(opts: {
94
+ entry: string[];
95
+ }): Options;
96
+
97
+ /**
98
+ * @param {Object} opts - Options for building configurations.
99
+ * @param {string[]} opts.entry - The entry array.
100
+ * @returns {import('tsup').Options}
101
+ */
102
+ export declare function modernConfig(opts: {
103
+ entry: string[];
104
+ }): Options;
105
+
106
+ /**
107
+ * This component is responsible for:
108
+ * - hydrating the query client on the server
109
+ * - dehydrating the query client on the server
110
+ */
111
+ declare function ReactQueryStreamedHydration(props: {
112
+ children: React_2.ReactNode;
113
+ queryClient?: QueryClient;
114
+ nonce?: string;
115
+ options?: {
116
+ hydrate?: HydrateOptions;
117
+ dehydrate?: DehydrateOptions;
118
+ };
119
+ transformer?: HydrationStreamProviderProps<DehydratedState>['transformer'];
120
+ }): JSX.Element;
121
+ export { ReactQueryStreamedHydration }
122
+ export { ReactQueryStreamedHydration as ReactQueryStreamedHydration_alias_1 }
123
+
124
+ export { }
@@ -0,0 +1,124 @@
1
+ import type { DehydratedState } from '@tanstack/react-query';
2
+ import type { DehydrateOptions } from '@tanstack/react-query';
3
+ import type { HydrateOptions } from '@tanstack/react-query';
4
+ import { JSX } from 'react/jsx-runtime';
5
+ import { Options } from 'tsup';
6
+ import type { QueryClient } from '@tanstack/react-query';
7
+ import * as React_2 from 'react';
8
+ import { UserConfig } from 'vite';
9
+
10
+ export declare function createHydrationStreamProvider<TShape>(): {
11
+ Provider: (props: {
12
+ children: React_2.ReactNode;
13
+ /**
14
+ * Optional transformer to serialize/deserialize the data
15
+ * Example devalue, superjson et al
16
+ */
17
+ transformer?: DataTransformer;
18
+ /**
19
+ * **Client method**
20
+ * Called in the browser when new entries are received
21
+ */
22
+ onEntries: (entries: Array<TShape>) => void;
23
+ /**
24
+ * **Server method**
25
+ * onFlush is called on the server when the cache is flushed
26
+ */
27
+ onFlush?: () => Array<TShape>;
28
+ /**
29
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
30
+ */
31
+ nonce?: string;
32
+ }) => JSX.Element;
33
+ context: React_2.Context<HydrationStreamContext<TShape>>;
34
+ };
35
+
36
+ declare interface DataTransformer {
37
+ serialize: (object: any) => any;
38
+ deserialize: (object: any) => any;
39
+ }
40
+
41
+ export declare const default_alias: any[];
42
+
43
+ export declare const default_alias_1: any[];
44
+
45
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
46
+
47
+ export declare const default_alias_3: UserConfig;
48
+
49
+ export declare const ESCAPE_REGEX: RegExp;
50
+
51
+ export declare function htmlEscapeJsonString(str: string): string;
52
+
53
+ declare interface HydrationStreamContext<TShape> {
54
+ id: string;
55
+ stream: {
56
+ /**
57
+ * **Server method**
58
+ * Push a new entry to the stream
59
+ * Will be ignored on the client
60
+ */
61
+ push: (...shape: Array<TShape>) => void;
62
+ };
63
+ }
64
+
65
+ export declare interface HydrationStreamProviderProps<TShape> {
66
+ children: React_2.ReactNode;
67
+ /**
68
+ * Optional transformer to serialize/deserialize the data
69
+ * Example devalue, superjson et al
70
+ */
71
+ transformer?: DataTransformer;
72
+ /**
73
+ * **Client method**
74
+ * Called in the browser when new entries are received
75
+ */
76
+ onEntries: (entries: Array<TShape>) => void;
77
+ /**
78
+ * **Server method**
79
+ * onFlush is called on the server when the cache is flushed
80
+ */
81
+ onFlush?: () => Array<TShape>;
82
+ /**
83
+ * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
84
+ */
85
+ nonce?: string;
86
+ }
87
+
88
+ /**
89
+ * @param {Object} opts - Options for building configurations.
90
+ * @param {string[]} opts.entry - The entry array.
91
+ * @returns {import('tsup').Options}
92
+ */
93
+ export declare function legacyConfig(opts: {
94
+ entry: string[];
95
+ }): Options;
96
+
97
+ /**
98
+ * @param {Object} opts - Options for building configurations.
99
+ * @param {string[]} opts.entry - The entry array.
100
+ * @returns {import('tsup').Options}
101
+ */
102
+ export declare function modernConfig(opts: {
103
+ entry: string[];
104
+ }): Options;
105
+
106
+ /**
107
+ * This component is responsible for:
108
+ * - hydrating the query client on the server
109
+ * - dehydrating the query client on the server
110
+ */
111
+ declare function ReactQueryStreamedHydration(props: {
112
+ children: React_2.ReactNode;
113
+ queryClient?: QueryClient;
114
+ nonce?: string;
115
+ options?: {
116
+ hydrate?: HydrateOptions;
117
+ dehydrate?: DehydrateOptions;
118
+ };
119
+ transformer?: HydrationStreamProviderProps<DehydratedState>['transformer'];
120
+ }): JSX.Element;
121
+ export { ReactQueryStreamedHydration }
122
+ export { ReactQueryStreamedHydration as ReactQueryStreamedHydration_alias_1 }
123
+
124
+ export { }