@tanstack/react-query-next-experimental 5.91.0 → 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 (29) hide show
  1. package/build/legacy/HydrationStreamProvider.cjs +0 -1
  2. package/build/legacy/HydrationStreamProvider.cjs.map +1 -1
  3. package/build/legacy/HydrationStreamProvider.d.cts +2 -67
  4. package/build/legacy/HydrationStreamProvider.d.ts +2 -67
  5. package/build/legacy/HydrationStreamProvider.js +0 -1
  6. package/build/legacy/HydrationStreamProvider.js.map +1 -1
  7. package/build/legacy/ReactQueryStreamedHydration.d.cts +1 -22
  8. package/build/legacy/ReactQueryStreamedHydration.d.ts +1 -22
  9. package/build/legacy/_tsup-dts-rollup.d.cts +124 -0
  10. package/build/legacy/_tsup-dts-rollup.d.ts +124 -0
  11. package/build/legacy/htmlescape.d.cts +2 -4
  12. package/build/legacy/htmlescape.d.ts +2 -4
  13. package/build/legacy/index.d.cts +1 -5
  14. package/build/legacy/index.d.ts +1 -5
  15. package/build/modern/HydrationStreamProvider.cjs +0 -1
  16. package/build/modern/HydrationStreamProvider.cjs.map +1 -1
  17. package/build/modern/HydrationStreamProvider.d.cts +2 -67
  18. package/build/modern/HydrationStreamProvider.d.ts +2 -67
  19. package/build/modern/HydrationStreamProvider.js +0 -1
  20. package/build/modern/HydrationStreamProvider.js.map +1 -1
  21. package/build/modern/ReactQueryStreamedHydration.d.cts +1 -22
  22. package/build/modern/ReactQueryStreamedHydration.d.ts +1 -22
  23. package/build/modern/_tsup-dts-rollup.d.cts +124 -0
  24. package/build/modern/_tsup-dts-rollup.d.ts +124 -0
  25. package/build/modern/htmlescape.d.cts +2 -4
  26. package/build/modern/htmlescape.d.ts +2 -4
  27. package/build/modern/index.d.cts +1 -5
  28. package/build/modern/index.d.ts +1 -5
  29. package/package.json +9 -10
@@ -39,7 +39,6 @@ var import_navigation = require("next/navigation");
39
39
  var React = __toESM(require("react"), 1);
40
40
  var import_htmlescape = require("./htmlescape.cjs");
41
41
  var import_jsx_runtime = require("react/jsx-runtime");
42
- var serializedSymbol = Symbol("serialized");
43
42
  function createHydrationStreamProvider() {
44
43
  const context = React.createContext(
45
44
  null
@@ -1 +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;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
+ {"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"]}
@@ -1,67 +1,2 @@
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
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.cjs';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.cjs';
@@ -1,67 +1,2 @@
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
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.js';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.js';
@@ -6,7 +6,6 @@ import { useServerInsertedHTML } from "next/navigation";
6
6
  import * as React from "react";
7
7
  import { htmlEscapeJsonString } from "./htmlescape.js";
8
8
  import { jsx } from "react/jsx-runtime";
9
- var serializedSymbol = Symbol("serialized");
10
9
  function createHydrationStreamProvider() {
11
10
  const context = React.createContext(
12
11
  null
@@ -1 +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;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
+ {"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"]}
@@ -1,22 +1 @@
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
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.cjs';
@@ -1,22 +1 @@
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
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.js';
@@ -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 { }
@@ -1,4 +1,2 @@
1
- declare const ESCAPE_REGEX: RegExp;
2
- declare function htmlEscapeJsonString(str: string): string;
3
-
4
- export { ESCAPE_REGEX, htmlEscapeJsonString };
1
+ export { htmlEscapeJsonString } from './_tsup-dts-rollup.cjs';
2
+ export { ESCAPE_REGEX } from './_tsup-dts-rollup.cjs';
@@ -1,4 +1,2 @@
1
- declare const ESCAPE_REGEX: RegExp;
2
- declare function htmlEscapeJsonString(str: string): string;
3
-
4
- export { ESCAPE_REGEX, htmlEscapeJsonString };
1
+ export { htmlEscapeJsonString } from './_tsup-dts-rollup.js';
2
+ export { ESCAPE_REGEX } from './_tsup-dts-rollup.js';
@@ -1,5 +1 @@
1
- export { ReactQueryStreamedHydration } from './ReactQueryStreamedHydration.cjs';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import './HydrationStreamProvider.cjs';
5
- import '@tanstack/react-query';
1
+ export { ReactQueryStreamedHydration_alias_1 as ReactQueryStreamedHydration } from './_tsup-dts-rollup.cjs';
@@ -1,5 +1 @@
1
- export { ReactQueryStreamedHydration } from './ReactQueryStreamedHydration.js';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import './HydrationStreamProvider.js';
5
- import '@tanstack/react-query';
1
+ export { ReactQueryStreamedHydration_alias_1 as ReactQueryStreamedHydration } from './_tsup-dts-rollup.js';
@@ -39,7 +39,6 @@ var import_navigation = require("next/navigation");
39
39
  var React = __toESM(require("react"), 1);
40
40
  var import_htmlescape = require("./htmlescape.cjs");
41
41
  var import_jsx_runtime = require("react/jsx-runtime");
42
- var serializedSymbol = Symbol("serialized");
43
42
  function createHydrationStreamProvider() {
44
43
  const context = React.createContext(
45
44
  null
@@ -1 +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;AArIR,IAAM,mBAAmB,OAAO,YAAY;AAmDrC,SAAS,gCAAwC;AACtD,QAAM,UAAgB;AAAA,IACpB;AAAA,EACF;AAUA,WAAS,iCAAiC,OAqBvC;AAED,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;AAE1B,aAAO,KAAK,GAAI,MAAM,UAAU,KAAK,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,CAAC,IAAI,EAAE,GAAG,aAAa;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":[]}
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;AAED,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;AAE1B,aAAO,KAAK,GAAI,MAAM,UAAU,KAAK,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,CAAC,IAAI,EAAE,GAAG,aAAa;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":[]}
@@ -1,67 +1,2 @@
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
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.cjs';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.cjs';
@@ -1,67 +1,2 @@
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
+ export { createHydrationStreamProvider } from './_tsup-dts-rollup.js';
2
+ export { HydrationStreamProviderProps } from './_tsup-dts-rollup.js';
@@ -6,7 +6,6 @@ import { useServerInsertedHTML } from "next/navigation";
6
6
  import * as React from "react";
7
7
  import { htmlEscapeJsonString } from "./htmlescape.js";
8
8
  import { jsx } from "react/jsx-runtime";
9
- var serializedSymbol = Symbol("serialized");
10
9
  function createHydrationStreamProvider() {
11
10
  const context = React.createContext(
12
11
  null
@@ -1 +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;AArIR,IAAM,mBAAmB,OAAO,YAAY;AAmDrC,SAAS,gCAAwC;AACtD,QAAM,UAAgB;AAAA,IACpB;AAAA,EACF;AAUA,WAAS,iCAAiC,OAqBvC;AAED,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;AAE1B,aAAO,KAAK,GAAI,MAAM,UAAU,KAAK,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,CAAC,IAAI,EAAE,GAAG,aAAa;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":[]}
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;AAED,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;AAE1B,aAAO,KAAK,GAAI,MAAM,UAAU,KAAK,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,CAAC,IAAI,EAAE,GAAG,aAAa;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":[]}
@@ -1,22 +1 @@
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
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.cjs';
@@ -1,22 +1 @@
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
+ export { ReactQueryStreamedHydration } from './_tsup-dts-rollup.js';
@@ -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 { }
@@ -1,4 +1,2 @@
1
- declare const ESCAPE_REGEX: RegExp;
2
- declare function htmlEscapeJsonString(str: string): string;
3
-
4
- export { ESCAPE_REGEX, htmlEscapeJsonString };
1
+ export { htmlEscapeJsonString } from './_tsup-dts-rollup.cjs';
2
+ export { ESCAPE_REGEX } from './_tsup-dts-rollup.cjs';
@@ -1,4 +1,2 @@
1
- declare const ESCAPE_REGEX: RegExp;
2
- declare function htmlEscapeJsonString(str: string): string;
3
-
4
- export { ESCAPE_REGEX, htmlEscapeJsonString };
1
+ export { htmlEscapeJsonString } from './_tsup-dts-rollup.js';
2
+ export { ESCAPE_REGEX } from './_tsup-dts-rollup.js';
@@ -1,5 +1 @@
1
- export { ReactQueryStreamedHydration } from './ReactQueryStreamedHydration.cjs';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import './HydrationStreamProvider.cjs';
5
- import '@tanstack/react-query';
1
+ export { ReactQueryStreamedHydration_alias_1 as ReactQueryStreamedHydration } from './_tsup-dts-rollup.cjs';
@@ -1,5 +1 @@
1
- export { ReactQueryStreamedHydration } from './ReactQueryStreamedHydration.js';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import './HydrationStreamProvider.js';
5
- import '@tanstack/react-query';
1
+ export { ReactQueryStreamedHydration_alias_1 as ReactQueryStreamedHydration } from './_tsup-dts-rollup.js';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-next-experimental",
3
- "version": "5.91.0",
3
+ "version": "5.94.5",
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.0.1",
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.0.0",
47
- "@tanstack/react-query": "5.90.8"
46
+ "react": "^19.2.1",
47
+ "@tanstack/react-query": "5.94.5"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "next": "^13 || ^14 || ^15 || ^16",
51
51
  "react": "^18 || ^19",
52
- "@tanstack/react-query": "^5.90.8"
52
+ "@tanstack/react-query": "^5.94.5"
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
  }