@tanstack/router-core 0.0.1-beta.147 → 0.0.1-beta.148

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.147",
4
+ "version": "0.0.1-beta.148",
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.147"
46
+ "@tanstack/react-store": "0.0.1-beta.148"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
package/src/router.ts CHANGED
@@ -830,76 +830,84 @@ export class Router<
830
830
  ) => {
831
831
  this.cleanMatches()
832
832
 
833
+ if (!opts?.preload) {
834
+ resolvedMatches.forEach((match) => {
835
+ // Update each match with its latest url data
836
+ this.setRouteMatch(match.id, (s) => ({
837
+ ...s,
838
+ routeSearch: match.routeSearch,
839
+ search: match.search,
840
+ routeContext: match.routeContext,
841
+ context: match.context,
842
+ error: match.error,
843
+ paramsError: match.paramsError,
844
+ searchError: match.searchError,
845
+ params: match.params,
846
+ }))
847
+ })
848
+ }
849
+
833
850
  let firstBadMatchIndex: number | undefined
834
851
 
835
852
  // Check each match middleware to see if the route can be accessed
836
853
  try {
837
- await Promise.all(
838
- resolvedMatches.map(async (match, index) => {
839
- const route = this.getRoute(match.routeId)
854
+ for (const [index, match] of resolvedMatches.entries()) {
855
+ const route = this.getRoute(match.routeId)
840
856
 
841
- if (!opts?.preload) {
842
- // Update each match with its latest url data
843
- this.setRouteMatch(match.id, (s) => ({
844
- ...s,
845
- routeSearch: match.routeSearch,
846
- search: match.search,
847
- routeContext: match.routeContext,
848
- context: match.context,
849
- error: match.error,
850
- paramsError: match.paramsError,
851
- searchError: match.searchError,
852
- params: match.params,
853
- }))
857
+ const handleError = (
858
+ err: any,
859
+ handler: undefined | ((err: any) => void),
860
+ ) => {
861
+ firstBadMatchIndex = firstBadMatchIndex ?? index
862
+ handler = handler || route.options.onError
863
+
864
+ if (isRedirect(err)) {
865
+ throw err
854
866
  }
855
867
 
856
- const handleError = (
857
- err: any,
858
- handler: undefined | ((err: any) => void),
859
- ) => {
860
- firstBadMatchIndex = firstBadMatchIndex ?? index
861
- handler = handler || route.options.onError
868
+ try {
869
+ handler?.(err)
870
+ } catch (errorHandlerErr) {
871
+ err = errorHandlerErr
862
872
 
863
- if (isRedirect(err)) {
864
- throw err
873
+ if (isRedirect(errorHandlerErr)) {
874
+ throw errorHandlerErr
865
875
  }
876
+ }
866
877
 
867
- try {
868
- handler?.(err)
869
- } catch (errorHandlerErr) {
870
- err = errorHandlerErr
878
+ this.setRouteMatch(match.id, (s) => ({
879
+ ...s,
880
+ error: err,
881
+ status: 'error',
882
+ updatedAt: Date.now(),
883
+ }))
884
+ }
871
885
 
872
- if (isRedirect(errorHandlerErr)) {
873
- throw errorHandlerErr
874
- }
875
- }
886
+ if (match.paramsError) {
887
+ handleError(match.paramsError, route.options.onParseParamsError)
888
+ }
876
889
 
877
- this.setRouteMatch(match.id, (s) => ({
878
- ...s,
879
- error: err,
880
- status: 'error',
881
- updatedAt: Date.now(),
882
- }))
883
- }
890
+ if (match.searchError) {
891
+ handleError(match.searchError, route.options.onValidateSearchError)
892
+ }
884
893
 
885
- if (match.paramsError) {
886
- handleError(match.paramsError, route.options.onParseParamsError)
887
- }
894
+ let didError = false
888
895
 
889
- if (match.searchError) {
890
- handleError(match.searchError, route.options.onValidateSearchError)
891
- }
896
+ try {
897
+ await route.options.beforeLoad?.({
898
+ ...match,
899
+ preload: !!opts?.preload,
900
+ })
901
+ } catch (err) {
902
+ handleError(err, route.options.onBeforeLoadError)
903
+ didError = true
904
+ }
892
905
 
893
- try {
894
- await route.options.beforeLoad?.({
895
- ...match,
896
- preload: !!opts?.preload,
897
- })
898
- } catch (err) {
899
- handleError(err, route.options.onBeforeLoadError)
900
- }
901
- }),
902
- )
906
+ // If we errored, do not run the next matches' middleware
907
+ if (didError) {
908
+ break
909
+ }
910
+ }
903
911
  } catch (err) {
904
912
  if (!opts?.preload) {
905
913
  this.navigate(err as any)