@tanstack/react-router 0.0.1-beta.167 → 0.0.1-beta.168
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/build/cjs/{deferred.js → awaited.js} +8 -8
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/index.js +37 -633
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/react.js +644 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/scroll-restoration.js +2 -2
- package/build/cjs/scroll-restoration.js.map +1 -1
- package/build/esm/index.js +44 -44
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +158 -121
- package/build/types/index.d.ts +33 -28
- package/build/umd/index.development.js +66 -65
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +4 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/{deferred.tsx → awaited.tsx} +6 -6
- package/src/index.tsx +3 -1180
- package/src/react.tsx +1231 -0
- package/src/scroll-restoration.tsx +1 -1
- package/build/cjs/deferred.js.map +0 -1
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('
|
|
13
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.
|
|
15
|
-
})(this, (function (exports,
|
|
12
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('use-sync-external-store/shim/with-selector'), require('react')) :
|
|
13
|
+
typeof define === 'function' && define.amd ? define(['exports', 'use-sync-external-store/shim/with-selector', 'react'], factory) :
|
|
14
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.withSelector, global.React));
|
|
15
|
+
})(this, (function (exports, withSelector, React) { 'use strict';
|
|
16
16
|
|
|
17
17
|
function _interopNamespace(e) {
|
|
18
18
|
if (e && e.__esModule) return e;
|
|
@@ -34,21 +34,6 @@
|
|
|
34
34
|
|
|
35
35
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
36
36
|
|
|
37
|
-
function _extends() {
|
|
38
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
39
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
-
var source = arguments[i];
|
|
41
|
-
for (var key in source) {
|
|
42
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
43
|
-
target[key] = source[key];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return target;
|
|
48
|
-
};
|
|
49
|
-
return _extends.apply(this, arguments);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
37
|
/**
|
|
53
38
|
* @tanstack/store/src/index.ts
|
|
54
39
|
*
|
|
@@ -1233,8 +1218,8 @@
|
|
|
1233
1218
|
params: routeParams,
|
|
1234
1219
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
1235
1220
|
updatedAt: Date.now(),
|
|
1236
|
-
invalidAt:
|
|
1237
|
-
preloadInvalidAt:
|
|
1221
|
+
invalidAt: Infinity,
|
|
1222
|
+
preloadInvalidAt: Infinity,
|
|
1238
1223
|
routeSearch: {},
|
|
1239
1224
|
search: {},
|
|
1240
1225
|
status: hasLoaders ? 'pending' : 'success',
|
|
@@ -1317,7 +1302,6 @@
|
|
|
1317
1302
|
return matches;
|
|
1318
1303
|
};
|
|
1319
1304
|
loadMatches = async (resolvedMatches, opts) => {
|
|
1320
|
-
this.cleanMatches();
|
|
1321
1305
|
if (!opts?.preload) {
|
|
1322
1306
|
resolvedMatches.forEach(match => {
|
|
1323
1307
|
// Update each match with its latest route data
|
|
@@ -1330,10 +1314,12 @@
|
|
|
1330
1314
|
error: match.error,
|
|
1331
1315
|
paramsError: match.paramsError,
|
|
1332
1316
|
searchError: match.searchError,
|
|
1333
|
-
params: match.params
|
|
1317
|
+
params: match.params,
|
|
1318
|
+
preloadInvalidAt: 0
|
|
1334
1319
|
}));
|
|
1335
1320
|
});
|
|
1336
1321
|
}
|
|
1322
|
+
this.cleanMatches();
|
|
1337
1323
|
let firstBadMatchIndex;
|
|
1338
1324
|
|
|
1339
1325
|
// Check each match middleware to see if the route can be accessed
|
|
@@ -1469,6 +1455,7 @@
|
|
|
1469
1455
|
})());
|
|
1470
1456
|
});
|
|
1471
1457
|
await Promise.all(matchPromises);
|
|
1458
|
+
this.cleanMatches();
|
|
1472
1459
|
};
|
|
1473
1460
|
reload = () => {
|
|
1474
1461
|
return this.navigate({
|
|
@@ -1912,7 +1899,7 @@
|
|
|
1912
1899
|
const route = this.getRoute(match.routeId);
|
|
1913
1900
|
const updatedAt = opts?.updatedAt ?? Date.now();
|
|
1914
1901
|
const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
|
|
1915
|
-
const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ??
|
|
1902
|
+
const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
|
|
1916
1903
|
this.setRouteMatch(id, s => ({
|
|
1917
1904
|
...s,
|
|
1918
1905
|
error: undefined,
|
|
@@ -1923,7 +1910,6 @@
|
|
|
1923
1910
|
preloadInvalidAt,
|
|
1924
1911
|
invalidAt
|
|
1925
1912
|
}));
|
|
1926
|
-
if (this.state.matches.find(d => d.id === id)) ;
|
|
1927
1913
|
};
|
|
1928
1914
|
invalidate = async opts => {
|
|
1929
1915
|
if (opts?.matchId) {
|
|
@@ -2154,44 +2140,19 @@
|
|
|
2154
2140
|
return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
|
|
2155
2141
|
}
|
|
2156
2142
|
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
return
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
function useDeferred({
|
|
2173
|
-
promise
|
|
2174
|
-
}) {
|
|
2175
|
-
const router = useRouter();
|
|
2176
|
-
let state = promise.__deferredState;
|
|
2177
|
-
const key = `__TSR__DEFERRED__${state.uid}`;
|
|
2178
|
-
if (isDehydratedDeferred(promise)) {
|
|
2179
|
-
state = router.hydrateData(key);
|
|
2180
|
-
promise = Promise.resolve(state.data);
|
|
2181
|
-
promise.__deferredState = state;
|
|
2182
|
-
}
|
|
2183
|
-
if (state.status === 'pending') {
|
|
2184
|
-
throw promise;
|
|
2185
|
-
}
|
|
2186
|
-
if (state.status === 'error') {
|
|
2187
|
-
throw state.error;
|
|
2188
|
-
}
|
|
2189
|
-
router.dehydrateData(key, state);
|
|
2190
|
-
return [state.data];
|
|
2191
|
-
}
|
|
2192
|
-
function Deferred(props) {
|
|
2193
|
-
const awaited = useDeferred(props);
|
|
2194
|
-
return props.children(...awaited);
|
|
2143
|
+
function _extends() {
|
|
2144
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
2145
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
2146
|
+
var source = arguments[i];
|
|
2147
|
+
for (var key in source) {
|
|
2148
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2149
|
+
target[key] = source[key];
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
return target;
|
|
2154
|
+
};
|
|
2155
|
+
return _extends.apply(this, arguments);
|
|
2195
2156
|
}
|
|
2196
2157
|
|
|
2197
2158
|
Route.__onInit = route => {
|
|
@@ -2765,8 +2726,48 @@
|
|
|
2765
2726
|
return true;
|
|
2766
2727
|
}
|
|
2767
2728
|
|
|
2729
|
+
const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2730
|
+
function useScrollRestoration(options) {
|
|
2731
|
+
const router = useRouter();
|
|
2732
|
+
useLayoutEffect(() => {
|
|
2733
|
+
return watchScrollPositions(router, options);
|
|
2734
|
+
}, []);
|
|
2735
|
+
useLayoutEffect(() => {
|
|
2736
|
+
restoreScrollPositions(router, options);
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
function ScrollRestoration(props) {
|
|
2740
|
+
useScrollRestoration(props);
|
|
2741
|
+
return null;
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
function useAwaited({
|
|
2745
|
+
promise
|
|
2746
|
+
}) {
|
|
2747
|
+
const router = useRouter();
|
|
2748
|
+
let state = promise.__deferredState;
|
|
2749
|
+
const key = `__TSR__DEFERRED__${state.uid}`;
|
|
2750
|
+
if (isDehydratedDeferred(promise)) {
|
|
2751
|
+
state = router.hydrateData(key);
|
|
2752
|
+
promise = Promise.resolve(state.data);
|
|
2753
|
+
promise.__deferredState = state;
|
|
2754
|
+
}
|
|
2755
|
+
if (state.status === 'pending') {
|
|
2756
|
+
throw promise;
|
|
2757
|
+
}
|
|
2758
|
+
if (state.status === 'error') {
|
|
2759
|
+
throw state.error;
|
|
2760
|
+
}
|
|
2761
|
+
router.dehydrateData(key, state);
|
|
2762
|
+
return [state.data];
|
|
2763
|
+
}
|
|
2764
|
+
function Await(props) {
|
|
2765
|
+
const awaited = useAwaited(props);
|
|
2766
|
+
return props.children(...awaited);
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
exports.Await = Await;
|
|
2768
2770
|
exports.Block = Block;
|
|
2769
|
-
exports.Deferred = Deferred;
|
|
2770
2771
|
exports.ErrorComponent = ErrorComponent;
|
|
2771
2772
|
exports.FileRoute = FileRoute;
|
|
2772
2773
|
exports.Link = Link;
|
|
@@ -2819,8 +2820,8 @@
|
|
|
2819
2820
|
exports.trimPath = trimPath;
|
|
2820
2821
|
exports.trimPathLeft = trimPathLeft;
|
|
2821
2822
|
exports.trimPathRight = trimPathRight;
|
|
2823
|
+
exports.useAwaited = useAwaited;
|
|
2822
2824
|
exports.useBlocker = useBlocker;
|
|
2823
|
-
exports.useDeferred = useDeferred;
|
|
2824
2825
|
exports.useDehydrate = useDehydrate;
|
|
2825
2826
|
exports.useHydrate = useHydrate;
|
|
2826
2827
|
exports.useInjectHtml = useInjectHtml;
|