@tanstack/router-core 0.0.1-beta.51 → 0.0.1-beta.52
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/history.js +2 -7
- package/build/cjs/history.js.map +1 -1
- package/build/cjs/routeMatch.js +2 -2
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +12 -8
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +16 -17
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +151 -151
- package/build/types/index.d.ts +1 -0
- package/build/umd/index.development.js +16 -17
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/history.ts +2 -7
- package/src/routeMatch.ts +2 -2
- package/src/router.ts +15 -9
package/build/types/index.d.ts
CHANGED
|
@@ -320,6 +320,7 @@ declare class RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
|
|
|
320
320
|
params: TRouteInfo['allParams'];
|
|
321
321
|
pathname: string;
|
|
322
322
|
});
|
|
323
|
+
setLoaderData: (loaderData: TRouteInfo['routeLoaderData']) => void;
|
|
323
324
|
cancel: () => void;
|
|
324
325
|
load: (loaderOpts?: {
|
|
325
326
|
preload: true;
|
|
@@ -119,13 +119,8 @@
|
|
|
119
119
|
const getLocation = () => parseLocation(entries[index], currentState);
|
|
120
120
|
return createHistory({
|
|
121
121
|
getLocation,
|
|
122
|
-
listener:
|
|
123
|
-
|
|
124
|
-
// We might need to handle the hashchange event in the future
|
|
125
|
-
// window.addEventListener(hashChangeEvent, onUpdate)
|
|
126
|
-
return () => {
|
|
127
|
-
window.removeEventListener(popStateEvent, onUpdate);
|
|
128
|
-
};
|
|
122
|
+
listener: () => {
|
|
123
|
+
return () => {};
|
|
129
124
|
},
|
|
130
125
|
pushState: (path, state) => {
|
|
131
126
|
currentState = {
|
|
@@ -696,7 +691,7 @@
|
|
|
696
691
|
this.store.setState(s => s.status = 'success');
|
|
697
692
|
}
|
|
698
693
|
}
|
|
699
|
-
|
|
694
|
+
setLoaderData = loaderData => {
|
|
700
695
|
batch(() => {
|
|
701
696
|
this.store.setState(s => {
|
|
702
697
|
s.routeLoaderData = loaderData;
|
|
@@ -771,7 +766,7 @@
|
|
|
771
766
|
if (this.route.options.loader) {
|
|
772
767
|
const data = await this.router.loadMatchData(this);
|
|
773
768
|
if (latestPromise = checkLatest()) return latestPromise;
|
|
774
|
-
this
|
|
769
|
+
this.setLoaderData(data);
|
|
775
770
|
}
|
|
776
771
|
this.store.setState(s => {
|
|
777
772
|
s.error = undefined;
|
|
@@ -956,8 +951,7 @@
|
|
|
956
951
|
throw new Error('Failed to fetch match data');
|
|
957
952
|
};
|
|
958
953
|
class Router {
|
|
959
|
-
|
|
960
|
-
|
|
954
|
+
#unsubHistory;
|
|
961
955
|
startedLoadingAt = Date.now();
|
|
962
956
|
resolveNavigation = () => {};
|
|
963
957
|
constructor(options) {
|
|
@@ -989,9 +983,6 @@
|
|
|
989
983
|
if (!this.store.state.currentMatches.length) {
|
|
990
984
|
this.load();
|
|
991
985
|
}
|
|
992
|
-
const unsubHistory = this.history.listen(() => {
|
|
993
|
-
this.load(this.#parseLocation(this.store.state.latestLocation));
|
|
994
|
-
});
|
|
995
986
|
const visibilityChangeEvent = 'visibilitychange';
|
|
996
987
|
const focusEvent = 'focus';
|
|
997
988
|
|
|
@@ -1004,7 +995,6 @@
|
|
|
1004
995
|
window.addEventListener(focusEvent, this.#onFocus, false);
|
|
1005
996
|
}
|
|
1006
997
|
return () => {
|
|
1007
|
-
unsubHistory();
|
|
1008
998
|
if (window.removeEventListener) {
|
|
1009
999
|
// Be sure to unsubscribe if a new handler is set
|
|
1010
1000
|
|
|
@@ -1018,11 +1008,17 @@
|
|
|
1018
1008
|
update = opts => {
|
|
1019
1009
|
Object.assign(this.options, opts);
|
|
1020
1010
|
if (!this.history || this.options.history && this.options.history !== this.history) {
|
|
1021
|
-
|
|
1011
|
+
if (this.#unsubHistory) {
|
|
1012
|
+
this.#unsubHistory();
|
|
1013
|
+
}
|
|
1014
|
+
this.history = this.options.history ?? (isServer ? createMemoryHistory() : createBrowserHistory());
|
|
1022
1015
|
this.store.setState(s => {
|
|
1023
1016
|
s.latestLocation = this.#parseLocation();
|
|
1024
1017
|
s.currentLocation = s.latestLocation;
|
|
1025
1018
|
});
|
|
1019
|
+
this.#unsubHistory = this.history.listen(() => {
|
|
1020
|
+
this.load(this.#parseLocation(this.store.state.latestLocation));
|
|
1021
|
+
});
|
|
1026
1022
|
}
|
|
1027
1023
|
const {
|
|
1028
1024
|
basepath,
|
|
@@ -1536,7 +1532,10 @@
|
|
|
1536
1532
|
currentMatches.forEach((match, index) => {
|
|
1537
1533
|
const dehydratedMatch = dehydratedRouter.state.currentMatches[index];
|
|
1538
1534
|
invariant(dehydratedMatch && dehydratedMatch.id === match.id, 'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬');
|
|
1539
|
-
|
|
1535
|
+
match.store.setState(s => {
|
|
1536
|
+
Object.assign(s, dehydratedMatch.state);
|
|
1537
|
+
});
|
|
1538
|
+
match.setLoaderData(dehydratedMatch.state.routeLoaderData);
|
|
1540
1539
|
});
|
|
1541
1540
|
currentMatches.forEach(match => match.__validate());
|
|
1542
1541
|
Object.assign(s, {
|