@tanstack/router-core 0.0.1-beta.181 → 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 +24 -23
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +24 -23
- 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 +24 -23
- 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 +32 -26
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
createMemoryHistory,
|
|
57
57
|
RouterHistory,
|
|
58
58
|
} from './history'
|
|
59
|
+
import warning from 'tiny-warning'
|
|
59
60
|
|
|
60
61
|
//
|
|
61
62
|
|
|
@@ -204,6 +205,8 @@ export interface RouterState<
|
|
|
204
205
|
pendingMatchIds: string[]
|
|
205
206
|
matches: RouteMatch<TRouteTree>[]
|
|
206
207
|
pendingMatches: RouteMatch<TRouteTree>[]
|
|
208
|
+
renderedMatchIds: string[]
|
|
209
|
+
renderedMatches: RouteMatch<TRouteTree>[]
|
|
207
210
|
location: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
208
211
|
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
209
212
|
lastUpdated: number
|
|
@@ -371,6 +374,21 @@ export class Router<
|
|
|
371
374
|
})
|
|
372
375
|
}
|
|
373
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
|
+
|
|
374
392
|
next.isFetching = [...next.matches, ...next.pendingMatches].some(
|
|
375
393
|
(d) => d.isFetching,
|
|
376
394
|
)
|
|
@@ -665,24 +683,10 @@ export class Router<
|
|
|
665
683
|
prevMatchesById: Record<string, RouteMatch<TRouteTree>>,
|
|
666
684
|
nextMatches: AnyRouteMatch[],
|
|
667
685
|
): Record<string, RouteMatch<TRouteTree>> => {
|
|
668
|
-
|
|
686
|
+
return {
|
|
669
687
|
...prevMatchesById,
|
|
688
|
+
...Object.fromEntries(nextMatches.map((match) => [match.id, match])),
|
|
670
689
|
}
|
|
671
|
-
|
|
672
|
-
let hadNew = false
|
|
673
|
-
|
|
674
|
-
nextMatches.forEach((match) => {
|
|
675
|
-
if (!nextMatchesById[match.id]) {
|
|
676
|
-
hadNew = true
|
|
677
|
-
nextMatchesById[match.id] = match
|
|
678
|
-
}
|
|
679
|
-
})
|
|
680
|
-
|
|
681
|
-
if (!hadNew) {
|
|
682
|
-
return prevMatchesById
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
return nextMatchesById
|
|
686
690
|
}
|
|
687
691
|
|
|
688
692
|
getRoute = (id: string): Route => {
|
|
@@ -892,16 +896,20 @@ export class Router<
|
|
|
892
896
|
? route.options.validateSearch.parse
|
|
893
897
|
: route.options.validateSearch
|
|
894
898
|
|
|
895
|
-
|
|
899
|
+
let routeSearch = validator?.(parentSearchInfo.search) ?? {}
|
|
896
900
|
|
|
897
|
-
|
|
901
|
+
let search = {
|
|
898
902
|
...parentSearchInfo.search,
|
|
899
903
|
...routeSearch,
|
|
900
904
|
}
|
|
901
905
|
|
|
906
|
+
routeSearch = replaceEqualDeep(match.routeSearch, routeSearch)
|
|
907
|
+
search = replaceEqualDeep(match.search, search)
|
|
908
|
+
|
|
902
909
|
return {
|
|
903
|
-
routeSearch
|
|
904
|
-
search
|
|
910
|
+
routeSearch,
|
|
911
|
+
search,
|
|
912
|
+
searchDidChange: match.routeSearch !== routeSearch,
|
|
905
913
|
}
|
|
906
914
|
} catch (err: any) {
|
|
907
915
|
match.searchError = new SearchParamError(err.message, {
|
|
@@ -1721,7 +1729,6 @@ export class Router<
|
|
|
1721
1729
|
location: BuildNextOptions & { replace?: boolean; resetScroll?: boolean },
|
|
1722
1730
|
) => {
|
|
1723
1731
|
const next = this.buildNext(location)
|
|
1724
|
-
const id = '' + Date.now() + Math.random()
|
|
1725
1732
|
|
|
1726
1733
|
if (this.navigateTimeout) clearTimeout(this.navigateTimeout)
|
|
1727
1734
|
|
|
@@ -1741,10 +1748,7 @@ export class Router<
|
|
|
1741
1748
|
next.hash ? `#${next.hash}` : ''
|
|
1742
1749
|
}`
|
|
1743
1750
|
|
|
1744
|
-
this.history[nextAction === 'push' ? 'push' : 'replace'](href,
|
|
1745
|
-
id,
|
|
1746
|
-
...next.state,
|
|
1747
|
-
})
|
|
1751
|
+
this.history[nextAction === 'push' ? 'push' : 'replace'](href, next.state)
|
|
1748
1752
|
|
|
1749
1753
|
this.resetNextScroll = location.resetScroll ?? true
|
|
1750
1754
|
|
|
@@ -1761,7 +1765,7 @@ export class Router<
|
|
|
1761
1765
|
) => {
|
|
1762
1766
|
this.__store.setState((prev) => {
|
|
1763
1767
|
if (!prev.matchesById[id]) {
|
|
1764
|
-
|
|
1768
|
+
return prev
|
|
1765
1769
|
}
|
|
1766
1770
|
|
|
1767
1771
|
return {
|
|
@@ -1862,6 +1866,8 @@ function getInitialRouterState(): RouterState<any> {
|
|
|
1862
1866
|
pendingMatchIds: [],
|
|
1863
1867
|
matches: [],
|
|
1864
1868
|
pendingMatches: [],
|
|
1869
|
+
renderedMatchIds: [],
|
|
1870
|
+
renderedMatches: [],
|
|
1865
1871
|
lastUpdated: Date.now(),
|
|
1866
1872
|
}
|
|
1867
1873
|
}
|