@tanstack/react-query-persist-client 4.0.2 → 4.0.8

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.
@@ -15,7 +15,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
15
15
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
16
16
  var React = require('react');
17
17
  var persist = require('./persist.js');
18
- var index = require('../../react-query/build/esm/index.js');
18
+ var reactQuery = require('@tanstack/react-query');
19
19
 
20
20
  function _interopNamespace(e) {
21
21
  if (e && e.__esModule) return e;
@@ -72,9 +72,9 @@ const PersistQueryClientProvider = ({
72
72
  unsubscribe();
73
73
  };
74
74
  }, [client]);
75
- return /*#__PURE__*/React__namespace.createElement(index.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
75
+ return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
76
76
  client: client
77
- }, props), /*#__PURE__*/React__namespace.createElement(index.IsRestoringProvider, {
77
+ }, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
78
78
  value: isRestoring
79
79
  }, children));
80
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","sources":["../../../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { persistQueryClient, PersistQueryClientOptions } from './persist'\nimport {\n QueryClientProvider,\n QueryClientProviderProps,\n IsRestoringProvider,\n} from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MADyC;EAEzCC,QAFyC;EAGzCC,cAHyC;EAIzCC,SAJyC;EAKzC,GAAGC,KAAAA;AALsC,CAAD,KAMU;EAClD,MAAM,CAACC,WAAD,EAAcC,cAAd,CAAA,GAAgCC,gBAAK,CAACC,QAAN,CAAe,IAAf,CAAtC,CAAA;AACA,EAAA,MAAMC,IAAI,GAAGF,gBAAK,CAACG,MAAN,CAAa;IAAER,cAAF;AAAkBC,IAAAA,SAAAA;AAAlB,GAAb,CAAb,CAAA;EAEAI,gBAAK,CAACI,SAAN,CAAgB,MAAM;IACpBF,IAAI,CAACG,OAAL,GAAe;MAAEV,cAAF;AAAkBC,MAAAA,SAAAA;KAAjC,CAAA;GADF,CAAA,CAAA;EAIAI,gBAAK,CAACI,SAAN,CAAgB,MAAM;IACpB,IAAIE,OAAO,GAAG,KAAd,CAAA;IACAP,cAAc,CAAC,IAAD,CAAd,CAAA;AACA,IAAA,MAAM,CAACQ,WAAD,EAAcC,OAAd,CAAyBC,GAAAA,0BAAkB,CAAC,EAChD,GAAGP,IAAI,CAACG,OAAL,CAAaV,cADgC;AAEhDe,MAAAA,WAAW,EAAEjB,MAAAA;AAFmC,KAAD,CAAjD,CAAA;IAKAe,OAAO,CAACG,IAAR,CAAa,MAAM;MACjB,IAAI,CAACL,OAAL,EAAc;QACZJ,IAAI,CAACG,OAAL,CAAaT,SAAb,oBAAAM,IAAI,CAACG,OAAL,CAAaT,SAAb,EAAA,CAAA;QACAG,cAAc,CAAC,KAAD,CAAd,CAAA;AACD,OAAA;KAJH,CAAA,CAAA;AAOA,IAAA,OAAO,MAAM;AACXO,MAAAA,OAAO,GAAG,IAAV,CAAA;MACAC,WAAW,EAAA,CAAA;KAFb,CAAA;GAfF,EAmBG,CAACd,MAAD,CAnBH,CAAA,CAAA;AAqBA,EAAA,oBACEO,+BAACY,yBAAD,EAAAC,oCAAA,CAAA;AAAqB,IAAA,MAAM,EAAEpB,MAAAA;GAAYI,EAAAA,KAAzC,CACE,eAAAG,gBAAA,CAAA,aAAA,CAACc,yBAAD,EAAA;AAAqB,IAAA,KAAK,EAAEhB,WAAAA;GAAcJ,EAAAA,QAA1C,CADF,CADF,CAAA;AAKD;;;;"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","sources":["../../../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { persistQueryClient, PersistQueryClientOptions } from './persist'\nimport {\n QueryClientProvider,\n QueryClientProviderProps,\n IsRestoringProvider,\n} from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAMA,0BAA0B,GAAG,CAAC;EACzCC,MADyC;EAEzCC,QAFyC;EAGzCC,cAHyC;EAIzCC,SAJyC;EAKzC,GAAGC,KAAAA;AALsC,CAAD,KAMU;EAClD,MAAM,CAACC,WAAD,EAAcC,cAAd,CAAA,GAAgCC,gBAAK,CAACC,QAAN,CAAe,IAAf,CAAtC,CAAA;AACA,EAAA,MAAMC,IAAI,GAAGF,gBAAK,CAACG,MAAN,CAAa;IAAER,cAAF;AAAkBC,IAAAA,SAAAA;AAAlB,GAAb,CAAb,CAAA;EAEAI,gBAAK,CAACI,SAAN,CAAgB,MAAM;IACpBF,IAAI,CAACG,OAAL,GAAe;MAAEV,cAAF;AAAkBC,MAAAA,SAAAA;KAAjC,CAAA;GADF,CAAA,CAAA;EAIAI,gBAAK,CAACI,SAAN,CAAgB,MAAM;IACpB,IAAIE,OAAO,GAAG,KAAd,CAAA;IACAP,cAAc,CAAC,IAAD,CAAd,CAAA;AACA,IAAA,MAAM,CAACQ,WAAD,EAAcC,OAAd,CAAyBC,GAAAA,0BAAkB,CAAC,EAChD,GAAGP,IAAI,CAACG,OAAL,CAAaV,cADgC;AAEhDe,MAAAA,WAAW,EAAEjB,MAAAA;AAFmC,KAAD,CAAjD,CAAA;IAKAe,OAAO,CAACG,IAAR,CAAa,MAAM;MACjB,IAAI,CAACL,OAAL,EAAc;QACZJ,IAAI,CAACG,OAAL,CAAaT,SAAb,oBAAAM,IAAI,CAACG,OAAL,CAAaT,SAAb,EAAA,CAAA;QACAG,cAAc,CAAC,KAAD,CAAd,CAAA;AACD,OAAA;KAJH,CAAA,CAAA;AAOA,IAAA,OAAO,MAAM;AACXO,MAAAA,OAAO,GAAG,IAAV,CAAA;MACAC,WAAW,EAAA,CAAA;KAFb,CAAA;GAfF,EAmBG,CAACd,MAAD,CAnBH,CAAA,CAAA;AAqBA,EAAA,oBACEO,+BAACY,8BAAD,EAAAC,oCAAA,CAAA;AAAqB,IAAA,MAAM,EAAEpB,MAAAA;GAAYI,EAAAA,KAAzC,CACE,eAAAG,gBAAA,CAAA,aAAA,CAACc,8BAAD,EAAA;AAAqB,IAAA,KAAK,EAAEhB,WAAAA;GAAcJ,EAAAA,QAA1C,CADF,CADF,CAAA;AAKD;;;;"}
@@ -9,7 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import 'use-sync-external-store/shim';
12
+ import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query';
13
13
 
14
14
  /**
15
15
  * query-core
@@ -21,7 +21,7 @@ import 'use-sync-external-store/shim';
21
21
  *
22
22
  * @license MIT
23
23
  */
24
- class Subscribable$1 {
24
+ class Subscribable {
25
25
  constructor() {
26
26
  this.listeners = [];
27
27
  this.subscribe = this.subscribe.bind(this);
@@ -50,16 +50,16 @@ class Subscribable$1 {
50
50
 
51
51
  // TYPES
52
52
  // UTILS
53
- const isServer$1 = typeof window === 'undefined';
53
+ const isServer = typeof window === 'undefined';
54
54
 
55
- class FocusManager$1 extends Subscribable$1 {
55
+ class FocusManager extends Subscribable {
56
56
  constructor() {
57
57
  super();
58
58
 
59
59
  this.setup = onFocus => {
60
60
  // addEventListener does not exist in React Native, but window does
61
61
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
62
- if (!isServer$1 && window.addEventListener) {
62
+ if (!isServer && window.addEventListener) {
63
63
  const listener = () => onFocus(); // Listen to visibillitychange and focus
64
64
 
65
65
 
@@ -131,16 +131,16 @@ class FocusManager$1 extends Subscribable$1 {
131
131
  }
132
132
 
133
133
  }
134
- new FocusManager$1();
134
+ new FocusManager();
135
135
 
136
- class OnlineManager$1 extends Subscribable$1 {
136
+ class OnlineManager extends Subscribable {
137
137
  constructor() {
138
138
  super();
139
139
 
140
140
  this.setup = onOnline => {
141
141
  // addEventListener does not exist in React Native, but window does
142
142
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
143
- if (!isServer$1 && window.addEventListener) {
143
+ if (!isServer && window.addEventListener) {
144
144
  const listener = () => onOnline(); // Listen to online
145
145
 
146
146
 
@@ -211,7 +211,7 @@ class OnlineManager$1 extends Subscribable$1 {
211
211
  }
212
212
 
213
213
  }
214
- new OnlineManager$1();
214
+ new OnlineManager();
215
215
 
216
216
  // TYPES
217
217
  // FUNCTIONS
@@ -423,266 +423,6 @@ function _extends() {
423
423
  return _extends.apply(this, arguments);
424
424
  }
425
425
 
426
- /**
427
- * react-query
428
- *
429
- * Copyright (c) TanStack
430
- *
431
- * This source code is licensed under the MIT license found in the
432
- * LICENSE.md file in the root directory of this source tree.
433
- *
434
- * @license MIT
435
- */
436
-
437
- /**
438
- * query-core
439
- *
440
- * Copyright (c) TanStack
441
- *
442
- * This source code is licensed under the MIT license found in the
443
- * LICENSE.md file in the root directory of this source tree.
444
- *
445
- * @license MIT
446
- */
447
- class Subscribable {
448
- constructor() {
449
- this.listeners = [];
450
- this.subscribe = this.subscribe.bind(this);
451
- }
452
-
453
- subscribe(listener) {
454
- this.listeners.push(listener);
455
- this.onSubscribe();
456
- return () => {
457
- this.listeners = this.listeners.filter(x => x !== listener);
458
- this.onUnsubscribe();
459
- };
460
- }
461
-
462
- hasListeners() {
463
- return this.listeners.length > 0;
464
- }
465
-
466
- onSubscribe() {// Do nothing
467
- }
468
-
469
- onUnsubscribe() {// Do nothing
470
- }
471
-
472
- }
473
-
474
- // TYPES
475
- // UTILS
476
- const isServer = typeof window === 'undefined';
477
-
478
- class FocusManager extends Subscribable {
479
- constructor() {
480
- super();
481
-
482
- this.setup = onFocus => {
483
- // addEventListener does not exist in React Native, but window does
484
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
485
- if (!isServer && window.addEventListener) {
486
- const listener = () => onFocus(); // Listen to visibillitychange and focus
487
-
488
-
489
- window.addEventListener('visibilitychange', listener, false);
490
- window.addEventListener('focus', listener, false);
491
- return () => {
492
- // Be sure to unsubscribe if a new handler is set
493
- window.removeEventListener('visibilitychange', listener);
494
- window.removeEventListener('focus', listener);
495
- };
496
- }
497
- };
498
- }
499
-
500
- onSubscribe() {
501
- if (!this.cleanup) {
502
- this.setEventListener(this.setup);
503
- }
504
- }
505
-
506
- onUnsubscribe() {
507
- if (!this.hasListeners()) {
508
- var _this$cleanup;
509
-
510
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
511
- this.cleanup = undefined;
512
- }
513
- }
514
-
515
- setEventListener(setup) {
516
- var _this$cleanup2;
517
-
518
- this.setup = setup;
519
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
520
- this.cleanup = setup(focused => {
521
- if (typeof focused === 'boolean') {
522
- this.setFocused(focused);
523
- } else {
524
- this.onFocus();
525
- }
526
- });
527
- }
528
-
529
- setFocused(focused) {
530
- this.focused = focused;
531
-
532
- if (focused) {
533
- this.onFocus();
534
- }
535
- }
536
-
537
- onFocus() {
538
- this.listeners.forEach(listener => {
539
- listener();
540
- });
541
- }
542
-
543
- isFocused() {
544
- if (typeof this.focused === 'boolean') {
545
- return this.focused;
546
- } // document global can be unavailable in react native
547
-
548
-
549
- if (typeof document === 'undefined') {
550
- return true;
551
- }
552
-
553
- return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
554
- }
555
-
556
- }
557
- new FocusManager();
558
-
559
- class OnlineManager extends Subscribable {
560
- constructor() {
561
- super();
562
-
563
- this.setup = onOnline => {
564
- // addEventListener does not exist in React Native, but window does
565
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
566
- if (!isServer && window.addEventListener) {
567
- const listener = () => onOnline(); // Listen to online
568
-
569
-
570
- window.addEventListener('online', listener, false);
571
- window.addEventListener('offline', listener, false);
572
- return () => {
573
- // Be sure to unsubscribe if a new handler is set
574
- window.removeEventListener('online', listener);
575
- window.removeEventListener('offline', listener);
576
- };
577
- }
578
- };
579
- }
580
-
581
- onSubscribe() {
582
- if (!this.cleanup) {
583
- this.setEventListener(this.setup);
584
- }
585
- }
586
-
587
- onUnsubscribe() {
588
- if (!this.hasListeners()) {
589
- var _this$cleanup;
590
-
591
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
592
- this.cleanup = undefined;
593
- }
594
- }
595
-
596
- setEventListener(setup) {
597
- var _this$cleanup2;
598
-
599
- this.setup = setup;
600
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
601
- this.cleanup = setup(online => {
602
- if (typeof online === 'boolean') {
603
- this.setOnline(online);
604
- } else {
605
- this.onOnline();
606
- }
607
- });
608
- }
609
-
610
- setOnline(online) {
611
- this.online = online;
612
-
613
- if (online) {
614
- this.onOnline();
615
- }
616
- }
617
-
618
- onOnline() {
619
- this.listeners.forEach(listener => {
620
- listener();
621
- });
622
- }
623
-
624
- isOnline() {
625
- if (typeof this.online === 'boolean') {
626
- return this.online;
627
- }
628
-
629
- if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
630
- return true;
631
- }
632
-
633
- return navigator.onLine;
634
- }
635
-
636
- }
637
- new OnlineManager();
638
-
639
- const defaultContext = /*#__PURE__*/React.createContext(undefined);
640
- const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
641
- // Otherwise, if contextSharing is on, we share the first and at least one
642
- // instance of the context across the window
643
- // to ensure that if React Query is used across
644
- // different bundles or microfrontends they will
645
- // all use the same **instance** of context, regardless
646
- // of module scoping.
647
-
648
- function getQueryClientContext(context, contextSharing) {
649
- if (context) {
650
- return context;
651
- }
652
-
653
- if (contextSharing && typeof window !== 'undefined') {
654
- if (!window.ReactQueryClientContext) {
655
- window.ReactQueryClientContext = defaultContext;
656
- }
657
-
658
- return window.ReactQueryClientContext;
659
- }
660
-
661
- return defaultContext;
662
- }
663
- const QueryClientProvider = ({
664
- client,
665
- children,
666
- context,
667
- contextSharing = false
668
- }) => {
669
- React.useEffect(() => {
670
- client.mount();
671
- return () => {
672
- client.unmount();
673
- };
674
- }, [client]);
675
- const Context = getQueryClientContext(context, contextSharing);
676
- return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
677
- value: !context && contextSharing
678
- }, /*#__PURE__*/React.createElement(Context.Provider, {
679
- value: client
680
- }, children));
681
- };
682
-
683
- const IsRestoringContext = /*#__PURE__*/React.createContext(false);
684
- const IsRestoringProvider = IsRestoringContext.Provider;
685
-
686
426
  const PersistQueryClientProvider = ({
687
427
  client,
688
428
  children,