@tanstack/react-router 0.0.1-beta.277 → 0.0.1-beta.279

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.
@@ -942,13 +942,14 @@
942
942
  invariant(routeId, `Could not find routeId for matchId "${matchId}". Please file an issue!`);
943
943
  const route = router.routesById[routeId];
944
944
  const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
945
+ const pendingElement = PendingComponent ? /*#__PURE__*/React__namespace.createElement(PendingComponent, null) : null;
945
946
  const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent ?? ErrorComponent;
946
947
  const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? PendingComponent ?? route.options.component?.preload ?? route.options.pendingComponent?.preload ?? route.options.errorComponent?.preload ? React__namespace.Suspense : SafeFragment;
947
948
  const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
948
949
  return /*#__PURE__*/React__namespace.createElement(matchContext.Provider, {
949
950
  value: matchId
950
951
  }, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
951
- fallback: PendingComponent
952
+ fallback: pendingElement
952
953
  }, /*#__PURE__*/React__namespace.createElement(ResolvedCatchBoundary, {
953
954
  getResetKey: () => router.state.resolvedLocation.state?.key,
954
955
  errorComponent: routeErrorComponent,
@@ -957,7 +958,7 @@
957
958
  }
958
959
  }, /*#__PURE__*/React__namespace.createElement(MatchInner, {
959
960
  matchId: matchId,
960
- pendingElement: PendingComponent
961
+ pendingElement: pendingElement
961
962
  }))));
962
963
  }
963
964
  function MatchInner({
@@ -977,7 +978,7 @@
977
978
  }
978
979
  if (match.status === 'pending') {
979
980
  if (match.showPending) {
980
- return pendingElement || null;
981
+ return pendingElement;
981
982
  }
982
983
  throw match.loadPromise;
983
984
  }
@@ -1007,6 +1008,9 @@
1007
1008
  });
1008
1009
  });
1009
1010
  function useMatchRoute() {
1011
+ useRouterState({
1012
+ select: s => [s.location, s.resolvedLocation]
1013
+ });
1010
1014
  const {
1011
1015
  matchRoute
1012
1016
  } = useRouter();
@@ -2088,7 +2092,10 @@
2088
2092
  while (parsed.length > 1 && parsed[0]?.value === '/') {
2089
2093
  parsed.shift();
2090
2094
  }
2091
- const score = parsed.map(d => {
2095
+ const scores = parsed.map(d => {
2096
+ if (d.value === '/') {
2097
+ return 0.75;
2098
+ }
2092
2099
  if (d.type === 'param') {
2093
2100
  return 0.5;
2094
2101
  }
@@ -2102,38 +2109,31 @@
2102
2109
  trimmed,
2103
2110
  parsed,
2104
2111
  index: i,
2105
- score
2112
+ scores
2106
2113
  });
2107
2114
  });
2108
2115
  this.flatRoutes = scoredRoutes.sort((a, b) => {
2109
- let isIndex = a.trimmed === '/' ? 1 : b.trimmed === '/' ? -1 : 0;
2110
- if (isIndex !== 0) return isIndex;
2111
- const length = Math.min(a.score.length, b.score.length);
2112
-
2113
- // Sort by length of score
2114
- if (a.score.length !== b.score.length) {
2115
- return b.score.length - a.score.length;
2116
- }
2116
+ const minLength = Math.min(a.scores.length, b.scores.length);
2117
2117
 
2118
2118
  // Sort by min available score
2119
- for (let i = 0; i < length; i++) {
2120
- if (a.score[i] !== b.score[i]) {
2121
- return b.score[i] - a.score[i];
2119
+ for (let i = 0; i < minLength; i++) {
2120
+ if (a.scores[i] !== b.scores[i]) {
2121
+ return b.scores[i] - a.scores[i];
2122
2122
  }
2123
2123
  }
2124
2124
 
2125
+ // Sort by length of score
2126
+ if (a.scores.length !== b.scores.length) {
2127
+ return b.scores.length - a.scores.length;
2128
+ }
2129
+
2125
2130
  // Sort by min available parsed value
2126
- for (let i = 0; i < length; i++) {
2131
+ for (let i = 0; i < minLength; i++) {
2127
2132
  if (a.parsed[i].value !== b.parsed[i].value) {
2128
2133
  return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
2129
2134
  }
2130
2135
  }
2131
2136
 
2132
- // Sort by length of trimmed full path
2133
- if (a.trimmed !== b.trimmed) {
2134
- return a.trimmed > b.trimmed ? 1 : -1;
2135
- }
2136
-
2137
2137
  // Sort by original index
2138
2138
  return a.index - b.index;
2139
2139
  }).map((d, i) => {
@@ -2538,9 +2538,9 @@
2538
2538
  let latestPromise;
2539
2539
  let firstBadMatchIndex;
2540
2540
  const updateMatch = match => {
2541
- const isPreload = this.state.preloadMatches.find(d => d.id === match.id);
2541
+ // const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
2542
2542
  const isPending = this.state.pendingMatches?.find(d => d.id === match.id);
2543
- const matchesKey = isPreload ? 'preloadMatches' : isPending ? 'pendingMatches' : 'matches';
2543
+ const matchesKey = preload ? 'preloadMatches' : isPending ? 'pendingMatches' : 'matches';
2544
2544
  this.__store.setState(s => ({
2545
2545
  ...s,
2546
2546
  [matchesKey]: s[matchesKey]?.map(d => d.id === match.id ? match : d)