@tanstack/router-core 0.0.1-beta.178 → 0.0.1-beta.180
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/router.js +12 -11
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +12 -11
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +124 -124
- package/build/types/router.d.ts +1 -0
- package/build/umd/index.development.js +12 -11
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +15 -9
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -243,6 +243,7 @@ type LinkCurrentTargetElement = {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
export interface DehydratedRouterState {
|
|
246
|
+
matchIds: string[]
|
|
246
247
|
dehydratedMatches: DehydratedRouteMatch[]
|
|
247
248
|
}
|
|
248
249
|
|
|
@@ -298,6 +299,7 @@ export type RouterListener<TRouterEvent extends RouterEvent> = {
|
|
|
298
299
|
|
|
299
300
|
const visibilityChangeEvent = 'visibilitychange'
|
|
300
301
|
const focusEvent = 'focus'
|
|
302
|
+
const preloadWarning = 'Error preloading route! ☝️'
|
|
301
303
|
|
|
302
304
|
export class Router<
|
|
303
305
|
TRouteTree extends AnyRoute = AnyRoute,
|
|
@@ -1322,7 +1324,7 @@ export class Router<
|
|
|
1322
1324
|
if (preload) {
|
|
1323
1325
|
this.preloadRoute(nextOpts).catch((err) => {
|
|
1324
1326
|
console.warn(err)
|
|
1325
|
-
console.warn(
|
|
1327
|
+
console.warn(preloadWarning)
|
|
1326
1328
|
})
|
|
1327
1329
|
}
|
|
1328
1330
|
}
|
|
@@ -1330,7 +1332,7 @@ export class Router<
|
|
|
1330
1332
|
const handleTouchStart = (e: TouchEvent) => {
|
|
1331
1333
|
this.preloadRoute(nextOpts).catch((err) => {
|
|
1332
1334
|
console.warn(err)
|
|
1333
|
-
console.warn(
|
|
1335
|
+
console.warn(preloadWarning)
|
|
1334
1336
|
})
|
|
1335
1337
|
}
|
|
1336
1338
|
|
|
@@ -1346,7 +1348,7 @@ export class Router<
|
|
|
1346
1348
|
target.preloadTimeout = null
|
|
1347
1349
|
this.preloadRoute(nextOpts).catch((err) => {
|
|
1348
1350
|
console.warn(err)
|
|
1349
|
-
console.warn(
|
|
1351
|
+
console.warn(preloadWarning)
|
|
1350
1352
|
})
|
|
1351
1353
|
}, preloadDelay)
|
|
1352
1354
|
}
|
|
@@ -1377,6 +1379,7 @@ export class Router<
|
|
|
1377
1379
|
dehydrate = (): DehydratedRouter => {
|
|
1378
1380
|
return {
|
|
1379
1381
|
state: {
|
|
1382
|
+
matchIds: this.state.matchIds,
|
|
1380
1383
|
dehydratedMatches: this.state.matches.map((d) =>
|
|
1381
1384
|
pick(d, [
|
|
1382
1385
|
'fetchedAt',
|
|
@@ -1408,13 +1411,15 @@ export class Router<
|
|
|
1408
1411
|
const ctx = _ctx
|
|
1409
1412
|
this.dehydratedData = ctx.payload as any
|
|
1410
1413
|
this.options.hydrate?.(ctx.payload as any)
|
|
1411
|
-
const
|
|
1414
|
+
const dehydratedState = ctx.router.state
|
|
1412
1415
|
|
|
1413
1416
|
let matches = this.matchRoutes(
|
|
1414
1417
|
this.state.location.pathname,
|
|
1415
1418
|
this.state.location.search,
|
|
1416
1419
|
).map((match) => {
|
|
1417
|
-
const dehydratedMatch = dehydratedMatches.find(
|
|
1420
|
+
const dehydratedMatch = dehydratedState.dehydratedMatches.find(
|
|
1421
|
+
(d) => d.id === match.id,
|
|
1422
|
+
)
|
|
1418
1423
|
|
|
1419
1424
|
invariant(
|
|
1420
1425
|
dehydratedMatch,
|
|
@@ -1433,6 +1438,7 @@ export class Router<
|
|
|
1433
1438
|
this.__store.setState((s) => {
|
|
1434
1439
|
return {
|
|
1435
1440
|
...s,
|
|
1441
|
+
matchIds: dehydratedState.matchIds,
|
|
1436
1442
|
matches,
|
|
1437
1443
|
matchesById: this.#mergeMatches(s.matchesById, matches),
|
|
1438
1444
|
}
|
|
@@ -1456,10 +1462,10 @@ export class Router<
|
|
|
1456
1462
|
return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(
|
|
1457
1463
|
strKey,
|
|
1458
1464
|
)}"] = ${JSON.stringify(data)}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1465
|
+
;(() => {
|
|
1466
|
+
var el = document.getElementById('${id}')
|
|
1467
|
+
el.parentElement.removeChild(el)
|
|
1468
|
+
})()
|
|
1463
1469
|
</script>`
|
|
1464
1470
|
})
|
|
1465
1471
|
|