@tanstack/router-core 0.0.1-beta.182 → 0.0.1-beta.183
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 +23 -22
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +23 -22
- 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 +2 -0
- package/build/umd/index.development.js +23 -22
- 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 +30 -25
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -205,6 +205,8 @@ export interface RouterState<
|
|
|
205
205
|
pendingMatchIds: string[]
|
|
206
206
|
matches: RouteMatch<TRouteTree>[]
|
|
207
207
|
pendingMatches: RouteMatch<TRouteTree>[]
|
|
208
|
+
renderedMatchIds: string[]
|
|
209
|
+
renderedMatches: RouteMatch<TRouteTree>[]
|
|
208
210
|
location: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
209
211
|
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
210
212
|
lastUpdated: number
|
|
@@ -372,6 +374,21 @@ export class Router<
|
|
|
372
374
|
})
|
|
373
375
|
}
|
|
374
376
|
|
|
377
|
+
if (matchesByIdChanged || matchesChanged || pendingMatchesChanged) {
|
|
378
|
+
const hasPendingComponent = next.pendingMatches.some((d) => {
|
|
379
|
+
const route = this.getRoute(d.routeId as any)
|
|
380
|
+
return !!route?.options.pendingComponent
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
next.renderedMatchIds = hasPendingComponent
|
|
384
|
+
? next.pendingMatchIds
|
|
385
|
+
: next.matchIds
|
|
386
|
+
|
|
387
|
+
next.renderedMatches = next.renderedMatchIds.map((id) => {
|
|
388
|
+
return next.matchesById[id] as any
|
|
389
|
+
})
|
|
390
|
+
}
|
|
391
|
+
|
|
375
392
|
next.isFetching = [...next.matches, ...next.pendingMatches].some(
|
|
376
393
|
(d) => d.isFetching,
|
|
377
394
|
)
|
|
@@ -666,24 +683,10 @@ export class Router<
|
|
|
666
683
|
prevMatchesById: Record<string, RouteMatch<TRouteTree>>,
|
|
667
684
|
nextMatches: AnyRouteMatch[],
|
|
668
685
|
): Record<string, RouteMatch<TRouteTree>> => {
|
|
669
|
-
|
|
686
|
+
return {
|
|
670
687
|
...prevMatchesById,
|
|
688
|
+
...Object.fromEntries(nextMatches.map((match) => [match.id, match])),
|
|
671
689
|
}
|
|
672
|
-
|
|
673
|
-
let hadNew = false
|
|
674
|
-
|
|
675
|
-
nextMatches.forEach((match) => {
|
|
676
|
-
if (!nextMatchesById[match.id]) {
|
|
677
|
-
hadNew = true
|
|
678
|
-
nextMatchesById[match.id] = match
|
|
679
|
-
}
|
|
680
|
-
})
|
|
681
|
-
|
|
682
|
-
if (!hadNew) {
|
|
683
|
-
return prevMatchesById
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
return nextMatchesById
|
|
687
690
|
}
|
|
688
691
|
|
|
689
692
|
getRoute = (id: string): Route => {
|
|
@@ -893,16 +896,20 @@ export class Router<
|
|
|
893
896
|
? route.options.validateSearch.parse
|
|
894
897
|
: route.options.validateSearch
|
|
895
898
|
|
|
896
|
-
|
|
899
|
+
let routeSearch = validator?.(parentSearchInfo.search) ?? {}
|
|
897
900
|
|
|
898
|
-
|
|
901
|
+
let search = {
|
|
899
902
|
...parentSearchInfo.search,
|
|
900
903
|
...routeSearch,
|
|
901
904
|
}
|
|
902
905
|
|
|
906
|
+
routeSearch = replaceEqualDeep(match.routeSearch, routeSearch)
|
|
907
|
+
search = replaceEqualDeep(match.search, search)
|
|
908
|
+
|
|
903
909
|
return {
|
|
904
|
-
routeSearch
|
|
905
|
-
search
|
|
910
|
+
routeSearch,
|
|
911
|
+
search,
|
|
912
|
+
searchDidChange: match.routeSearch !== routeSearch,
|
|
906
913
|
}
|
|
907
914
|
} catch (err: any) {
|
|
908
915
|
match.searchError = new SearchParamError(err.message, {
|
|
@@ -1722,7 +1729,6 @@ export class Router<
|
|
|
1722
1729
|
location: BuildNextOptions & { replace?: boolean; resetScroll?: boolean },
|
|
1723
1730
|
) => {
|
|
1724
1731
|
const next = this.buildNext(location)
|
|
1725
|
-
const id = '' + Date.now() + Math.random()
|
|
1726
1732
|
|
|
1727
1733
|
if (this.navigateTimeout) clearTimeout(this.navigateTimeout)
|
|
1728
1734
|
|
|
@@ -1742,10 +1748,7 @@ export class Router<
|
|
|
1742
1748
|
next.hash ? `#${next.hash}` : ''
|
|
1743
1749
|
}`
|
|
1744
1750
|
|
|
1745
|
-
this.history[nextAction === 'push' ? 'push' : 'replace'](href,
|
|
1746
|
-
id,
|
|
1747
|
-
...next.state,
|
|
1748
|
-
})
|
|
1751
|
+
this.history[nextAction === 'push' ? 'push' : 'replace'](href, next.state)
|
|
1749
1752
|
|
|
1750
1753
|
this.resetNextScroll = location.resetScroll ?? true
|
|
1751
1754
|
|
|
@@ -1863,6 +1866,8 @@ function getInitialRouterState(): RouterState<any> {
|
|
|
1863
1866
|
pendingMatchIds: [],
|
|
1864
1867
|
matches: [],
|
|
1865
1868
|
pendingMatches: [],
|
|
1869
|
+
renderedMatchIds: [],
|
|
1870
|
+
renderedMatches: [],
|
|
1866
1871
|
lastUpdated: Date.now(),
|
|
1867
1872
|
}
|
|
1868
1873
|
}
|