Skip to content

Commit 028589a

Browse files
committed
chore(hydration): move hydration to its own entrypoint
1 parent aaee4c5 commit 028589a

File tree

9 files changed

+82
-11
lines changed

9 files changed

+82
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ yarn-debug.log*
2525
yarn-error.log*
2626
.history
2727
size-plugin.json
28+
stats-hydration.json
29+
stats-react.json
2830
stats.html
2931
.vscode/settings.json

hydration.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if (process.env.NODE_ENV === 'production') {
2+
module.exports = require('./dist/hydration/react-query-hydration.production.min.js')
3+
} else {
4+
module.exports = require('./dist/hydration/react-query-hydration.development.js')
5+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:dev": "jest --watch",
2020
"test:ci": "jest && yarn dtslint",
2121
"test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
22-
"build": "NODE_ENV=production rollup -c",
22+
"build": "NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json stats-hydration.json",
2323
"now-build": "yarn && cd www && yarn && yarn build",
2424
"start": "rollup -c -w",
2525
"release": "yarn publish",

rollup.config.js

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const globals = {
1414
}
1515

1616
const inputSrc = 'src/react/index.js'
17+
const hydrationSrc = 'src/hydration/index.js'
1718

1819
export default [
1920
{
@@ -66,7 +67,66 @@ export default [
6667
externalDeps(),
6768
terser(),
6869
size(),
69-
visualizer(),
70+
visualizer({
71+
filename: 'stats-react.json',
72+
json: true,
73+
}),
74+
],
75+
},
76+
{
77+
input: hydrationSrc,
78+
output: {
79+
file: 'dist/hydration/react-query-hydration.mjs',
80+
format: 'es',
81+
sourcemap: true,
82+
},
83+
external,
84+
plugins: [resolve(), babel(), commonJS(), externalDeps()],
85+
},
86+
{
87+
input: hydrationSrc,
88+
output: {
89+
file: 'dist/hydration/react-query-hydration.min.mjs',
90+
format: 'es',
91+
sourcemap: true,
92+
},
93+
external,
94+
plugins: [resolve(), babel(), commonJS(), externalDeps(), terser()],
95+
},
96+
{
97+
input: hydrationSrc,
98+
output: {
99+
name: 'ReactQueryHydration',
100+
file: 'dist/hydration/react-query-hydration.development.js',
101+
format: 'umd',
102+
sourcemap: true,
103+
globals,
104+
},
105+
external,
106+
plugins: [resolve(), babel(), commonJS(), externalDeps()],
107+
},
108+
{
109+
input: hydrationSrc,
110+
output: {
111+
name: 'ReactQueryHydration',
112+
file: 'dist/hydration/react-query-hydration.production.min.js',
113+
format: 'umd',
114+
sourcemap: true,
115+
globals,
116+
},
117+
external,
118+
plugins: [
119+
replace({ 'process.env.NODE_ENV': `"production"`, delimiters: ['', ''] }),
120+
resolve(),
121+
babel(),
122+
commonJS(),
123+
externalDeps(),
124+
terser(),
125+
size(),
126+
visualizer({
127+
filename: 'stats-hydration.json',
128+
json: true,
129+
}),
70130
],
71131
},
72132
]

src/core/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { noop, stableStringify, identity, deepEqual } from './utils'
22

3+
export const DEFAULT_STALE_TIME = 0
4+
export const DEFAULT_CACHE_TIME = 5 * 60 * 1000
5+
36
export const DEFAULT_CONFIG = {
47
shared: {
58
suspense: false,
@@ -11,8 +14,8 @@ export const DEFAULT_CONFIG = {
1114
enabled: true,
1215
retry: 3,
1316
retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000),
14-
staleTime: 0,
15-
cacheTime: 5 * 60 * 1000,
17+
staleTime: DEFAULT_STALE_TIME,
18+
cacheTime: DEFAULT_CACHE_TIME,
1619
refetchOnWindowFocus: true,
1720
refetchInterval: false,
1821
queryFnParamsFilter: identity,

src/core/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ export {
99
setConsole,
1010
deepIncludes,
1111
} from './utils'
12-
export { dehydrateQuery, dehydrate, hydrate } from './hydration'

src/core/hydration.js renamed to src/hydration/hydration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { statusSuccess, isServer } from './utils'
2-
import { defaultConfigRef } from './config'
1+
import { DEFAULT_STALE_TIME, DEFAULT_CACHE_TIME } from '../core/config'
2+
import { statusSuccess, isServer } from '../core/utils'
33

44
export function dehydrateQuery(query) {
55
const dehydratedQuery = {}
@@ -10,10 +10,10 @@ export function dehydrateQuery(query) {
1010
// in the html-payload, but not consume it on the initial render.
1111
// We still schedule stale and garbage collection right away, which means
1212
// we need to specifically include staleTime and cacheTime in dehydration.
13-
if (query.config.staleTime !== defaultConfigRef.current.queries.staleTime) {
13+
if (query.config.staleTime !== DEFAULT_STALE_TIME) {
1414
dehydratedQuery.staleTime = query.config.staleTime
1515
}
16-
if (query.config.cacheTime !== defaultConfigRef.current.queries.cacheTime) {
16+
if (query.config.cacheTime !== DEFAULT_CACHE_TIME) {
1717
dehydratedQuery.cacheTime = query.config.cacheTime
1818
}
1919
if (query.state.data !== undefined) {

src/hydration/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { dehydrateQuery, dehydrate, hydrate } from './hydration'

src/core/tests/hydration.test.js renamed to src/hydration/tests/hydration.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { sleep } from './utils'
2-
import { makeQueryCache, dehydrate, hydrate } from '../'
1+
import { sleep } from '../../core/tests/utils'
2+
import { makeQueryCache } from '../../core'
3+
import { dehydrate, hydrate } from '../hydration'
34

45
describe('dehydration and rehydration', () => {
56
test('should work with serializeable values', async () => {

0 commit comments

Comments
 (0)