@tanstack/react-query-next-experimental 5.0.0-alpha.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/build/lib/HydrationStreamProvider.cjs +120 -0
- package/build/lib/HydrationStreamProvider.cjs.map +1 -0
- package/build/lib/HydrationStreamProvider.d.ts +57 -0
- package/build/lib/HydrationStreamProvider.d.ts.map +1 -0
- package/build/lib/HydrationStreamProvider.js +99 -0
- package/build/lib/HydrationStreamProvider.js.map +1 -0
- package/build/lib/HydrationStreamProvider.legacy.cjs +125 -0
- package/build/lib/HydrationStreamProvider.legacy.cjs.map +1 -0
- package/build/lib/HydrationStreamProvider.legacy.js +104 -0
- package/build/lib/HydrationStreamProvider.legacy.js.map +1 -0
- package/build/lib/ReactQueryStreamedHydration.cjs +89 -0
- package/build/lib/ReactQueryStreamedHydration.cjs.map +1 -0
- package/build/lib/ReactQueryStreamedHydration.d.ts +18 -0
- package/build/lib/ReactQueryStreamedHydration.d.ts.map +1 -0
- package/build/lib/ReactQueryStreamedHydration.js +68 -0
- package/build/lib/ReactQueryStreamedHydration.js.map +1 -0
- package/build/lib/ReactQueryStreamedHydration.legacy.cjs +91 -0
- package/build/lib/ReactQueryStreamedHydration.legacy.cjs.map +1 -0
- package/build/lib/ReactQueryStreamedHydration.legacy.js +70 -0
- package/build/lib/ReactQueryStreamedHydration.legacy.js.map +1 -0
- package/build/lib/index.cjs +8 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +2 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.legacy.cjs +8 -0
- package/build/lib/index.legacy.cjs.map +1 -0
- package/build/lib/index.legacy.js +2 -0
- package/build/lib/index.legacy.js.map +1 -0
- package/package.json +57 -0
- package/src/HydrationStreamProvider.tsx +184 -0
- package/src/ReactQueryStreamedHydration.tsx +93 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var reactQuery = require('@tanstack/react-query');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var HydrationStreamProvider = require('./HydrationStreamProvider.cjs');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
+
|
|
27
|
+
const stream = HydrationStreamProvider.createHydrationStreamProvider();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This component is responsible for:
|
|
31
|
+
* - hydrating the query client on the server
|
|
32
|
+
* - dehydrating the query client on the server
|
|
33
|
+
*/
|
|
34
|
+
function ReactQueryStreamedHydration(props) {
|
|
35
|
+
const queryClient = reactQuery.useQueryClient(props.queryClient);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* We need to track which queries were added/updated during the render
|
|
39
|
+
*/
|
|
40
|
+
const [trackedKeys] = React__namespace.useState(() => new Set());
|
|
41
|
+
|
|
42
|
+
// <server only>
|
|
43
|
+
if (typeof window === 'undefined') {
|
|
44
|
+
// Do we need to care about unsubscribing? I don't think so to be honest
|
|
45
|
+
queryClient.getQueryCache().subscribe(event => {
|
|
46
|
+
switch (event.type) {
|
|
47
|
+
case 'added':
|
|
48
|
+
case 'updated':
|
|
49
|
+
// console.log('tracking', event.query.queryHash, 'b/c of a', event.type)
|
|
50
|
+
trackedKeys.add(event.query.queryHash);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// </server only>
|
|
55
|
+
|
|
56
|
+
return /*#__PURE__*/React__namespace.createElement(stream.Provider, {
|
|
57
|
+
// Happens on server:
|
|
58
|
+
onFlush: () => {
|
|
59
|
+
/**
|
|
60
|
+
* Dehydrated state of the client where we only include the queries that were added/updated since the last flush
|
|
61
|
+
*/
|
|
62
|
+
const shouldDehydrate = props.options?.dehydrate?.shouldDehydrateQuery ?? reactQuery.defaultShouldDehydrateQuery;
|
|
63
|
+
const dehydratedState = reactQuery.dehydrate(queryClient, {
|
|
64
|
+
...props.options?.dehydrate,
|
|
65
|
+
shouldDehydrateQuery(query) {
|
|
66
|
+
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
trackedKeys.clear();
|
|
70
|
+
if (!dehydratedState.queries.length) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
return [dehydratedState];
|
|
74
|
+
}
|
|
75
|
+
// Happens in browser:
|
|
76
|
+
,
|
|
77
|
+
onEntries: entries => {
|
|
78
|
+
for (const hydratedState of entries) {
|
|
79
|
+
reactQuery.hydrate(queryClient, hydratedState, props.options?.hydrate);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Handle BigInts etc using superjson
|
|
83
|
+
,
|
|
84
|
+
transformer: props.transformer
|
|
85
|
+
}, props.children);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.ReactQueryStreamedHydration = ReactQueryStreamedHydration;
|
|
89
|
+
//# sourceMappingURL=ReactQueryStreamedHydration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactQueryStreamedHydration.cjs","sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport type {\n DehydratedState,\n DehydrateOptions,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (typeof window === 'undefined') {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;AAEA;AACA;AACA;AACA;AACA;AACO;AASL;;AAEA;AACF;AACA;AACE;;AAEA;AACA;AACE;;;AAGI;AACA;AACE;;AAEJ;AACF;AACF;AACA;;AAEA;AAEI;;AAEE;AACR;AACA;;AAKQ;AACE;;AAEE;AACF;AACF;;AAGA;AACE;AACF;;AAGF;AACA;AAAA;;AAEE;;AAEA;AACF;AACA;AAAA;;;AAMN;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DehydratedState, DehydrateOptions, HydrateOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { HydrationStreamProviderProps } from './HydrationStreamProvider';
|
|
4
|
+
/**
|
|
5
|
+
* This component is responsible for:
|
|
6
|
+
* - hydrating the query client on the server
|
|
7
|
+
* - dehydrating the query client on the server
|
|
8
|
+
*/
|
|
9
|
+
export declare function ReactQueryStreamedHydration(props: {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
queryClient?: QueryClient;
|
|
12
|
+
options?: {
|
|
13
|
+
hydrate?: HydrateOptions;
|
|
14
|
+
dehydrate?: DehydrateOptions;
|
|
15
|
+
};
|
|
16
|
+
transformer?: HydrationStreamProviderProps<DehydratedState>['transformer'];
|
|
17
|
+
}): React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=ReactQueryStreamedHydration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactQueryStreamedHydration.d.ts","sourceRoot":"","sources":["../../src/ReactQueryStreamedHydration.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,WAAW,EACZ,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAK7E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,cAAc,CAAA;QACxB,SAAS,CAAC,EAAE,gBAAgB,CAAA;KAC7B,CAAA;IACD,WAAW,CAAC,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAC,aAAa,CAAC,CAAA;CAC3E,qBA2DA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useQueryClient, defaultShouldDehydrateQuery, dehydrate, hydrate } from '@tanstack/react-query';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { createHydrationStreamProvider } from './HydrationStreamProvider.js';
|
|
5
|
+
|
|
6
|
+
const stream = createHydrationStreamProvider();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This component is responsible for:
|
|
10
|
+
* - hydrating the query client on the server
|
|
11
|
+
* - dehydrating the query client on the server
|
|
12
|
+
*/
|
|
13
|
+
function ReactQueryStreamedHydration(props) {
|
|
14
|
+
const queryClient = useQueryClient(props.queryClient);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* We need to track which queries were added/updated during the render
|
|
18
|
+
*/
|
|
19
|
+
const [trackedKeys] = React.useState(() => new Set());
|
|
20
|
+
|
|
21
|
+
// <server only>
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
// Do we need to care about unsubscribing? I don't think so to be honest
|
|
24
|
+
queryClient.getQueryCache().subscribe(event => {
|
|
25
|
+
switch (event.type) {
|
|
26
|
+
case 'added':
|
|
27
|
+
case 'updated':
|
|
28
|
+
// console.log('tracking', event.query.queryHash, 'b/c of a', event.type)
|
|
29
|
+
trackedKeys.add(event.query.queryHash);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// </server only>
|
|
34
|
+
|
|
35
|
+
return /*#__PURE__*/React.createElement(stream.Provider, {
|
|
36
|
+
// Happens on server:
|
|
37
|
+
onFlush: () => {
|
|
38
|
+
/**
|
|
39
|
+
* Dehydrated state of the client where we only include the queries that were added/updated since the last flush
|
|
40
|
+
*/
|
|
41
|
+
const shouldDehydrate = props.options?.dehydrate?.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
|
|
42
|
+
const dehydratedState = dehydrate(queryClient, {
|
|
43
|
+
...props.options?.dehydrate,
|
|
44
|
+
shouldDehydrateQuery(query) {
|
|
45
|
+
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
trackedKeys.clear();
|
|
49
|
+
if (!dehydratedState.queries.length) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return [dehydratedState];
|
|
53
|
+
}
|
|
54
|
+
// Happens in browser:
|
|
55
|
+
,
|
|
56
|
+
onEntries: entries => {
|
|
57
|
+
for (const hydratedState of entries) {
|
|
58
|
+
hydrate(queryClient, hydratedState, props.options?.hydrate);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Handle BigInts etc using superjson
|
|
62
|
+
,
|
|
63
|
+
transformer: props.transformer
|
|
64
|
+
}, props.children);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { ReactQueryStreamedHydration };
|
|
68
|
+
//# sourceMappingURL=ReactQueryStreamedHydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactQueryStreamedHydration.js","sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport type {\n DehydratedState,\n DehydrateOptions,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (typeof window === 'undefined') {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"names":[],"mappings":";;;;;AAkBA;;AAEA;AACA;AACA;AACA;AACA;AACO;AASL;;AAEA;AACF;AACA;AACE;;AAEA;AACA;AACE;;;AAGI;AACA;AACE;;AAEJ;AACF;AACF;AACA;;AAEA;AAEI;;AAEE;AACR;AACA;;AAKQ;AACE;;AAEE;AACF;AACF;;AAGA;AACE;AACF;;AAGF;AACA;AAAA;;AAEE;;AAEA;AACF;AACA;AAAA;;;AAMN;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var reactQuery = require('@tanstack/react-query');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var HydrationStreamProvider = require('./HydrationStreamProvider.legacy.cjs');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
+
|
|
27
|
+
const stream = HydrationStreamProvider.createHydrationStreamProvider();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This component is responsible for:
|
|
31
|
+
* - hydrating the query client on the server
|
|
32
|
+
* - dehydrating the query client on the server
|
|
33
|
+
*/
|
|
34
|
+
function ReactQueryStreamedHydration(props) {
|
|
35
|
+
const queryClient = reactQuery.useQueryClient(props.queryClient);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* We need to track which queries were added/updated during the render
|
|
39
|
+
*/
|
|
40
|
+
const [trackedKeys] = React__namespace.useState(() => new Set());
|
|
41
|
+
|
|
42
|
+
// <server only>
|
|
43
|
+
if (typeof window === 'undefined') {
|
|
44
|
+
// Do we need to care about unsubscribing? I don't think so to be honest
|
|
45
|
+
queryClient.getQueryCache().subscribe(event => {
|
|
46
|
+
switch (event.type) {
|
|
47
|
+
case 'added':
|
|
48
|
+
case 'updated':
|
|
49
|
+
// console.log('tracking', event.query.queryHash, 'b/c of a', event.type)
|
|
50
|
+
trackedKeys.add(event.query.queryHash);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// </server only>
|
|
55
|
+
|
|
56
|
+
return /*#__PURE__*/React__namespace.createElement(stream.Provider, {
|
|
57
|
+
// Happens on server:
|
|
58
|
+
onFlush: () => {
|
|
59
|
+
var _props$options$dehydr, _props$options, _props$options$dehydr2, _props$options2;
|
|
60
|
+
/**
|
|
61
|
+
* Dehydrated state of the client where we only include the queries that were added/updated since the last flush
|
|
62
|
+
*/
|
|
63
|
+
const shouldDehydrate = (_props$options$dehydr = (_props$options = props.options) == null ? void 0 : (_props$options$dehydr2 = _props$options.dehydrate) == null ? void 0 : _props$options$dehydr2.shouldDehydrateQuery) != null ? _props$options$dehydr : reactQuery.defaultShouldDehydrateQuery;
|
|
64
|
+
const dehydratedState = reactQuery.dehydrate(queryClient, {
|
|
65
|
+
...((_props$options2 = props.options) == null ? void 0 : _props$options2.dehydrate),
|
|
66
|
+
shouldDehydrateQuery(query) {
|
|
67
|
+
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
trackedKeys.clear();
|
|
71
|
+
if (!dehydratedState.queries.length) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return [dehydratedState];
|
|
75
|
+
}
|
|
76
|
+
// Happens in browser:
|
|
77
|
+
,
|
|
78
|
+
onEntries: entries => {
|
|
79
|
+
for (const hydratedState of entries) {
|
|
80
|
+
var _props$options3;
|
|
81
|
+
reactQuery.hydrate(queryClient, hydratedState, (_props$options3 = props.options) == null ? void 0 : _props$options3.hydrate);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Handle BigInts etc using superjson
|
|
85
|
+
,
|
|
86
|
+
transformer: props.transformer
|
|
87
|
+
}, props.children);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.ReactQueryStreamedHydration = ReactQueryStreamedHydration;
|
|
91
|
+
//# sourceMappingURL=ReactQueryStreamedHydration.legacy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactQueryStreamedHydration.legacy.cjs","sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport type {\n DehydratedState,\n DehydrateOptions,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (typeof window === 'undefined') {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"names":["hydrate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;AAEA;AACA;AACA;AACA;AACA;AACO;AASL;;AAEA;AACF;AACA;AACE;;AAEA;AACA;AACE;;;AAGI;AACA;AACE;;AAEJ;AACF;AACF;AACA;;AAEA;AAEI;;AACe;AACb;AACR;AACA;;AAKQ;;;AAGI;AACF;AACF;;AAGA;AACE;AACF;;AAGF;AACA;AAAA;;AAEE;AAAqC;AACnCA;AACF;AACF;AACA;AAAA;;;AAMN;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useQueryClient, defaultShouldDehydrateQuery, dehydrate, hydrate } from '@tanstack/react-query';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { createHydrationStreamProvider } from './HydrationStreamProvider.legacy.js';
|
|
5
|
+
|
|
6
|
+
const stream = createHydrationStreamProvider();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This component is responsible for:
|
|
10
|
+
* - hydrating the query client on the server
|
|
11
|
+
* - dehydrating the query client on the server
|
|
12
|
+
*/
|
|
13
|
+
function ReactQueryStreamedHydration(props) {
|
|
14
|
+
const queryClient = useQueryClient(props.queryClient);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* We need to track which queries were added/updated during the render
|
|
18
|
+
*/
|
|
19
|
+
const [trackedKeys] = React.useState(() => new Set());
|
|
20
|
+
|
|
21
|
+
// <server only>
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
// Do we need to care about unsubscribing? I don't think so to be honest
|
|
24
|
+
queryClient.getQueryCache().subscribe(event => {
|
|
25
|
+
switch (event.type) {
|
|
26
|
+
case 'added':
|
|
27
|
+
case 'updated':
|
|
28
|
+
// console.log('tracking', event.query.queryHash, 'b/c of a', event.type)
|
|
29
|
+
trackedKeys.add(event.query.queryHash);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// </server only>
|
|
34
|
+
|
|
35
|
+
return /*#__PURE__*/React.createElement(stream.Provider, {
|
|
36
|
+
// Happens on server:
|
|
37
|
+
onFlush: () => {
|
|
38
|
+
var _props$options$dehydr, _props$options, _props$options$dehydr2, _props$options2;
|
|
39
|
+
/**
|
|
40
|
+
* Dehydrated state of the client where we only include the queries that were added/updated since the last flush
|
|
41
|
+
*/
|
|
42
|
+
const shouldDehydrate = (_props$options$dehydr = (_props$options = props.options) == null ? void 0 : (_props$options$dehydr2 = _props$options.dehydrate) == null ? void 0 : _props$options$dehydr2.shouldDehydrateQuery) != null ? _props$options$dehydr : defaultShouldDehydrateQuery;
|
|
43
|
+
const dehydratedState = dehydrate(queryClient, {
|
|
44
|
+
...((_props$options2 = props.options) == null ? void 0 : _props$options2.dehydrate),
|
|
45
|
+
shouldDehydrateQuery(query) {
|
|
46
|
+
return trackedKeys.has(query.queryHash) && shouldDehydrate(query);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
trackedKeys.clear();
|
|
50
|
+
if (!dehydratedState.queries.length) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return [dehydratedState];
|
|
54
|
+
}
|
|
55
|
+
// Happens in browser:
|
|
56
|
+
,
|
|
57
|
+
onEntries: entries => {
|
|
58
|
+
for (const hydratedState of entries) {
|
|
59
|
+
var _props$options3;
|
|
60
|
+
hydrate(queryClient, hydratedState, (_props$options3 = props.options) == null ? void 0 : _props$options3.hydrate);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Handle BigInts etc using superjson
|
|
64
|
+
,
|
|
65
|
+
transformer: props.transformer
|
|
66
|
+
}, props.children);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { ReactQueryStreamedHydration };
|
|
70
|
+
//# sourceMappingURL=ReactQueryStreamedHydration.legacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactQueryStreamedHydration.legacy.js","sources":["../../src/ReactQueryStreamedHydration.tsx"],"sourcesContent":["'use client'\n\nimport type {\n DehydratedState,\n DehydrateOptions,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/react-query'\nimport {\n defaultShouldDehydrateQuery,\n dehydrate,\n hydrate,\n useQueryClient,\n} from '@tanstack/react-query'\nimport * as React from 'react'\nimport type { HydrationStreamProviderProps } from './HydrationStreamProvider'\nimport { createHydrationStreamProvider } from './HydrationStreamProvider'\n\nconst stream = createHydrationStreamProvider<DehydratedState>()\n\n/**\n * This component is responsible for:\n * - hydrating the query client on the server\n * - dehydrating the query client on the server\n */\nexport function ReactQueryStreamedHydration(props: {\n children: React.ReactNode\n queryClient?: QueryClient\n options?: {\n hydrate?: HydrateOptions\n dehydrate?: DehydrateOptions\n }\n transformer?: HydrationStreamProviderProps<DehydratedState>['transformer']\n}) {\n const queryClient = useQueryClient(props.queryClient)\n\n /**\n * We need to track which queries were added/updated during the render\n */\n const [trackedKeys] = React.useState(() => new Set<string>())\n\n // <server only>\n if (typeof window === 'undefined') {\n // Do we need to care about unsubscribing? I don't think so to be honest\n queryClient.getQueryCache().subscribe((event) => {\n switch (event.type) {\n case 'added':\n case 'updated':\n // console.log('tracking', event.query.queryHash, 'b/c of a', event.type)\n trackedKeys.add(event.query.queryHash)\n }\n })\n }\n // </server only>\n\n return (\n <stream.Provider\n // Happens on server:\n onFlush={() => {\n /**\n * Dehydrated state of the client where we only include the queries that were added/updated since the last flush\n */\n const shouldDehydrate =\n props.options?.dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const dehydratedState = dehydrate(queryClient, {\n ...props.options?.dehydrate,\n shouldDehydrateQuery(query) {\n return trackedKeys.has(query.queryHash) && shouldDehydrate(query)\n },\n })\n trackedKeys.clear()\n\n if (!dehydratedState.queries.length) {\n return []\n }\n\n return [dehydratedState]\n }}\n // Happens in browser:\n onEntries={(entries) => {\n for (const hydratedState of entries) {\n hydrate(queryClient, hydratedState, props.options?.hydrate)\n }\n }}\n // Handle BigInts etc using superjson\n transformer={props.transformer}\n >\n {props.children}\n </stream.Provider>\n )\n}\n"],"names":["hydrate"],"mappings":";;;;;AAkBA;;AAEA;AACA;AACA;AACA;AACA;AACO;AASL;;AAEA;AACF;AACA;AACE;;AAEA;AACA;AACE;;;AAGI;AACA;AACE;;AAEJ;AACF;AACF;AACA;;AAEA;AAEI;;AACe;AACb;AACR;AACA;;AAKQ;;;AAGI;AACF;AACF;;AAGA;AACE;AACF;;AAGF;AACA;AAAA;;AAEE;AAAqC;AACnCA;AACF;AACF;AACA;AAAA;;;AAMN;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.legacy.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.legacy.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/react-query-next-experimental",
|
|
3
|
+
"version": "5.0.0-alpha.80",
|
|
4
|
+
"description": "Hydration utils for React Query in the NextJs app directory",
|
|
5
|
+
"author": "tannerlinsley",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "tanstack/query",
|
|
8
|
+
"homepage": "https://tanstack.com/query",
|
|
9
|
+
"funding": {
|
|
10
|
+
"type": "github",
|
|
11
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"types": "build/lib/index.d.ts",
|
|
15
|
+
"main": "build/lib/index.legacy.cjs",
|
|
16
|
+
"module": "build/lib/index.legacy.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./build/lib/index.d.ts",
|
|
20
|
+
"import": "./build/lib/index.js",
|
|
21
|
+
"require": "./build/lib/index.cjs",
|
|
22
|
+
"default": "./build/lib/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"files": [
|
|
28
|
+
"build/lib/*",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "^18.2.4",
|
|
33
|
+
"@types/react-dom": "^18.2.4",
|
|
34
|
+
"next": "^13.4.6",
|
|
35
|
+
"react": "^18.2.0",
|
|
36
|
+
"react-dom": "^18.2.0",
|
|
37
|
+
"react-error-boundary": "^3.1.4",
|
|
38
|
+
"@tanstack/react-query": "5.0.0-alpha.71"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"next": "^13.0.0",
|
|
42
|
+
"react": "^18.0.0",
|
|
43
|
+
"react-dom": "^18.0.0",
|
|
44
|
+
"@tanstack/react-query": "5.0.0-alpha.71"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rimraf ./build && rimraf ./coverage",
|
|
48
|
+
"test:eslint": "eslint --ext .ts,.tsx ./src",
|
|
49
|
+
"test:types": "tsc --noEmit",
|
|
50
|
+
"test:lib": "vitest run --coverage --passWithNoTests",
|
|
51
|
+
"test:lib:dev": "pnpm run test:lib --watch",
|
|
52
|
+
"test:build": "publint --strict",
|
|
53
|
+
"build": "pnpm build:rollup && pnpm build:types",
|
|
54
|
+
"build:rollup": "rollup --config rollup.config.js",
|
|
55
|
+
"build:types": "tsc --emitDeclarationOnly"
|
|
56
|
+
}
|
|
57
|
+
}
|