@tanstack/router-core 0.0.1-beta.160 → 0.0.1-beta.161

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.160",
4
+ "version": "0.0.1-beta.161",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -43,7 +43,7 @@
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@gisatcz/cross-package-react-context": "^0.2.0",
46
- "@tanstack/react-store": "0.0.1-beta.160"
46
+ "@tanstack/react-store": "0.0.1-beta.161"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
package/src/router.ts CHANGED
@@ -292,10 +292,6 @@ export class Router<
292
292
 
293
293
  const next = this.__store.state
294
294
 
295
- console.log(
296
- Object.values(next.matchesById).find((d) => d.status === 'error'),
297
- )
298
-
299
295
  const matchesByIdChanged = prev.matchesById !== next.matchesById
300
296
  let matchesChanged
301
297
  let pendingMatchesChanged
@@ -869,7 +865,6 @@ export class Router<
869
865
  }
870
866
  }
871
867
 
872
- console.log('set error')
873
868
  this.setRouteMatch(match.id, (s) => ({
874
869
  ...s,
875
870
  error: err,
@@ -936,19 +931,18 @@ export class Router<
936
931
  : undefined
937
932
  }
938
933
 
939
- const load = async () => {
940
- let latestPromise
941
-
942
- const handleError = (err: any) => {
943
- if (isRedirect(err)) {
944
- if (!opts?.preload) {
945
- this.navigate(err as any)
946
- }
947
- return true
934
+ const handleIfRedirect = (err: any) => {
935
+ if (isRedirect(err)) {
936
+ if (!opts?.preload) {
937
+ this.navigate(err as any)
948
938
  }
949
-
950
- return false
939
+ return true
951
940
  }
941
+ return false
942
+ }
943
+
944
+ const load = async () => {
945
+ let latestPromise
952
946
 
953
947
  try {
954
948
  const componentsPromise = Promise.all(
@@ -975,44 +969,58 @@ export class Router<
975
969
 
976
970
  this.setRouteMatchData(match.id, () => loader, opts)
977
971
  } catch (loaderError) {
972
+ let latestError = loaderError
978
973
  if ((latestPromise = checkLatest())) return await latestPromise
979
- handleError(loaderError)
980
-
981
- let error = loaderError
974
+ if (handleIfRedirect(loaderError)) return
975
+
976
+ if (route.options.onLoadError) {
977
+ try {
978
+ route.options.onLoadError(loaderError)
979
+ } catch (onLoadError) {
980
+ latestError = onLoadError
981
+ if (handleIfRedirect(onLoadError)) return
982
+ }
983
+ }
982
984
 
983
- try {
984
- if (route.options.onLoadError) {
985
- route.options.onLoadError?.(loaderError)
986
- } else {
987
- route.options.onError?.(loaderError)
985
+ if (
986
+ (!route.options.onLoadError || latestError !== loaderError) &&
987
+ route.options.onError
988
+ ) {
989
+ try {
990
+ route.options.onError(latestError)
991
+ } catch (onErrorError) {
992
+ if (handleIfRedirect(onErrorError)) return
988
993
  }
989
- } catch (errorHandlerErr) {
990
- error = errorHandlerErr
991
- handleError(error)
992
994
  }
993
995
 
994
- console.log('set error')
995
996
  this.setRouteMatch(match.id, (s) => ({
996
997
  ...s,
997
- error: error,
998
+ error: loaderError,
998
999
  status: 'error',
999
1000
  isFetching: false,
1000
1001
  updatedAt: Date.now(),
1001
1002
  }))
1002
- console.log(this.getRouteMatch(match.id)?.status)
1003
1003
  }
1004
1004
  }
1005
1005
 
1006
- const loadPromise = load()
1006
+ let loadPromise: Promise<void> | undefined
1007
1007
 
1008
- this.setRouteMatch(match.id, (s) => ({
1009
- ...s,
1010
- status: s.status !== 'success' ? 'pending' : s.status,
1011
- isFetching: true,
1012
- loadPromise,
1013
- fetchedAt,
1014
- invalid: false,
1015
- }))
1008
+ this.__store.batch(() => {
1009
+ this.setRouteMatch(match.id, (s) => ({
1010
+ ...s,
1011
+ // status: s.status !== 'success' ? 'pending' : s.status,
1012
+ isFetching: true,
1013
+ fetchedAt,
1014
+ invalid: false,
1015
+ }))
1016
+
1017
+ loadPromise = load()
1018
+
1019
+ this.setRouteMatch(match.id, (s) => ({
1020
+ ...s,
1021
+ loadPromise,
1022
+ }))
1023
+ })
1016
1024
 
1017
1025
  await loadPromise
1018
1026
  })(),
@@ -1655,7 +1663,6 @@ export class Router<
1655
1663
  this.options.defaultMaxAge ??
1656
1664
  Infinity)
1657
1665
 
1658
- console.log('set success')
1659
1666
  this.setRouteMatch(id, (s) => ({
1660
1667
  ...s,
1661
1668
  error: undefined,