@tanstack/react-router 0.0.1-beta.205 → 0.0.1-beta.206

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/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.205",
4
+ "version": "0.0.1-beta.206",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -40,11 +40,9 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.16.7",
43
- "@gisatcz/cross-package-react-context": "^0.2.0",
44
- "@tanstack/react-router": "^0.0.1-beta.203",
45
43
  "tiny-invariant": "^1.3.1",
46
44
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.205"
45
+ "@tanstack/history": "0.0.1-beta.206"
48
46
  },
49
47
  "scripts": {
50
48
  "build": "rollup --config rollup.config.js"
@@ -528,7 +528,7 @@ export function RouterProvider<
528
528
  } = {},
529
529
  matches?: AnyRouteMatch[],
530
530
  ): ParsedLocation => {
531
- const from = state.location
531
+ const from = latestLocationRef.current
532
532
  const fromPathname = dest.from ?? from.pathname
533
533
 
534
534
  let pathname = resolvePathWithBase(fromPathname, `${dest.to ?? ''}`)
@@ -697,7 +697,7 @@ export function RouterProvider<
697
697
  async (next: ParsedLocation & CommitLocationOptions) => {
698
698
  if (navigateTimeoutRef.current) clearTimeout(navigateTimeoutRef.current)
699
699
 
700
- const isSameUrl = state.location.href === next.href
700
+ const isSameUrl = latestLocationRef.current.href === next.href
701
701
 
702
702
  // If the next urls are the same and we're not replacing,
703
703
  // do nothing
@@ -741,7 +741,7 @@ export function RouterProvider<
741
741
  )
742
742
 
743
743
  const buildAndCommitLocation = useStableCallback(
744
- <TRouteTree extends AnyRoute>({
744
+ ({
745
745
  replace,
746
746
  resetScroll,
747
747
  ...rest
@@ -844,7 +844,7 @@ export function RouterProvider<
844
844
  params: match.params,
845
845
  preload: !!preload,
846
846
  meta: parentMeta,
847
- location: state.location,
847
+ location: state.location, // TODO: This might need to be latestLocationRef.current...?
848
848
  })) ?? ({} as any)
849
849
 
850
850
  const meta = {
@@ -1158,21 +1158,21 @@ export function RouterProvider<
1158
1158
  const preloadDelay = userPreloadDelay ?? options.defaultPreloadDelay ?? 0
1159
1159
 
1160
1160
  // Compare path/hash for matches
1161
- const currentPathSplit = state.location.pathname.split('/')
1161
+ const currentPathSplit = latestLocationRef.current.pathname.split('/')
1162
1162
  const nextPathSplit = next.pathname.split('/')
1163
1163
  const pathIsFuzzyEqual = nextPathSplit.every(
1164
1164
  (d, i) => d === currentPathSplit[i],
1165
1165
  )
1166
1166
  // Combine the matches based on user options
1167
1167
  const pathTest = activeOptions?.exact
1168
- ? state.location.pathname === next.pathname
1168
+ ? latestLocationRef.current.pathname === next.pathname
1169
1169
  : pathIsFuzzyEqual
1170
1170
  const hashTest = activeOptions?.includeHash
1171
- ? state.location.hash === next.hash
1171
+ ? latestLocationRef.current.hash === next.hash
1172
1172
  : true
1173
1173
  const searchTest =
1174
1174
  activeOptions?.includeSearch ?? true
1175
- ? partialDeepEqual(state.location.search, next.search)
1175
+ ? partialDeepEqual(latestLocationRef.current.search, next.search)
1176
1176
  : true
1177
1177
 
1178
1178
  // The final "active" test
@@ -1252,12 +1252,16 @@ export function RouterProvider<
1252
1252
  },
1253
1253
  )
1254
1254
 
1255
+ const latestLocationRef = React.useRef(state.location)
1256
+
1255
1257
  React.useLayoutEffect(() => {
1256
1258
  const unsub = history.subscribe(() => {
1259
+ latestLocationRef.current = parseLocation(latestLocationRef.current)
1260
+
1257
1261
  React.startTransition(() => {
1258
1262
  setState((s) => ({
1259
1263
  ...s,
1260
- location: parseLocation(state.location),
1264
+ location: latestLocationRef.current,
1261
1265
  }))
1262
1266
  })
1263
1267
  })
@@ -1309,7 +1313,9 @@ export function RouterProvider<
1309
1313
  return false
1310
1314
  }
1311
1315
 
1312
- const baseLocation = opts?.pending ? state.location : state.resolvedLocation
1316
+ const baseLocation = opts?.pending
1317
+ ? latestLocationRef.current
1318
+ : state.resolvedLocation
1313
1319
 
1314
1320
  if (!baseLocation) {
1315
1321
  return false