Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/react-start/hmr/tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async function waitForRouteLoaderCrumb(
async function waitForRouteRemovalReload(page: Page) {
await page.waitForFunction(() => {
const router = (window as any).__TSR_ROUTER__
const match = router?.stores?.activeMatchesSnapshot
const match = router?.stores?.matches
?.get()
?.find((entry: any) => entry.routeId === '/child')

Expand Down
12 changes: 6 additions & 6 deletions packages/react-router/src/Match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Match = React.memo(function MatchImpl({
const router = useRouter()

if (isServer ?? router.isServer) {
const match = router.stores.activeMatchStoresById.get(matchId)?.get()
const match = router.stores.matchStores.get(matchId)?.get()
if (!match) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
Expand Down Expand Up @@ -64,7 +64,7 @@ export const Match = React.memo(function MatchImpl({
// The matchId prop is stable for this component's lifetime (set by Outlet),
// and reconcileMatchPool reuses stores for the same matchId.

const matchStore = router.stores.activeMatchStoresById.get(matchId)
const matchStore = router.stores.matchStores.get(matchId)
if (!matchStore) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
Expand Down Expand Up @@ -278,7 +278,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
}

if (isServer ?? router.isServer) {
const match = router.stores.activeMatchStoresById.get(matchId)?.get()
const match = router.stores.matchStores.get(matchId)?.get()
if (!match) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
Expand Down Expand Up @@ -357,7 +357,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
return out
}

const matchStore = router.stores.activeMatchStoresById.get(matchId)
const matchStore = router.stores.matchStores.get(matchId)
if (!matchStore) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
Expand Down Expand Up @@ -504,7 +504,7 @@ export const Outlet = React.memo(function OutletImpl() {
let childMatchId: string | undefined

if (isServer ?? router.isServer) {
const matches = router.stores.activeMatchesSnapshot.get()
const matches = router.stores.matches.get()
const parentIndex = matchId
? matches.findIndex((match) => match.id === matchId)
: -1
Expand All @@ -517,7 +517,7 @@ export const Outlet = React.memo(function OutletImpl() {
// Subscribe directly to the match store from the pool instead of
// the two-level byId → matchStore pattern.
const parentMatchStore = matchId
? router.stores.activeMatchStoresById.get(matchId)
? router.stores.matchStores.get(matchId)
: undefined

// eslint-disable-next-line react-hooks/rules-of-hooks
Expand Down
10 changes: 5 additions & 5 deletions packages/react-router/src/Matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function MatchesInner() {
const router = useRouter()
const _isServer = isServer ?? router.isServer
const matchId = _isServer
? router.stores.firstMatchId.get()
? router.stores.firstId.get()
: // eslint-disable-next-line react-hooks/rules-of-hooks
useStore(router.stores.firstMatchId, (id) => id)
useStore(router.stores.firstId, (id) => id)
const resetKey = _isServer
? router.stores.loadedAt.get()
: // eslint-disable-next-line react-hooks/rules-of-hooks
Expand Down Expand Up @@ -142,7 +142,7 @@ export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {

if (!(isServer ?? router.isServer)) {
// eslint-disable-next-line react-hooks/rules-of-hooks
useStore(router.stores.matchRouteReactivity, (d) => d)
useStore(router.stores.matchRouteDeps, (d) => d)
}

return React.useCallback(
Expand Down Expand Up @@ -240,7 +240,7 @@ export function useMatches<
)

if (isServer ?? router.isServer) {
const matches = router.stores.activeMatchesSnapshot.get() as Array<
const matches = router.stores.matches.get() as Array<
MakeRouteMatchUnion<TRouter>
>
return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<
Expand All @@ -250,7 +250,7 @@ export function useMatches<
}

// eslint-disable-next-line react-hooks/rules-of-hooks
return useStore(router.stores.activeMatchesSnapshot, (matches) => {
return useStore(router.stores.matches, (matches) => {
const selected = opts?.select
? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)
: (matches as any)
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/src/Scripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ export const Scripts = () => {
)

if (isServer ?? router.isServer) {
const activeMatches = router.stores.activeMatchesSnapshot.get()
const activeMatches = router.stores.matches.get()
const assetScripts = getAssetScripts(activeMatches)
const scripts = getScripts(activeMatches)
return renderScripts(router, scripts, assetScripts)
}

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const assetScripts = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
getAssetScripts,
deepEqual,
)
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const scripts = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
getScripts,
deepEqual,
)
Expand Down
8 changes: 4 additions & 4 deletions packages/react-router/src/Transitioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export function Transitioner() {
const [isTransitioning, setIsTransitioning] = React.useState(false)
// Track pending state changes
const isLoading = useStore(router.stores.isLoading, (value) => value)
const hasPendingMatches = useStore(
router.stores.hasPendingMatches,
const hasPending = useStore(
router.stores.hasPending,
(value) => value,
)

const previousIsLoading = usePrevious(isLoading)

const isAnyPending = isLoading || isTransitioning || hasPendingMatches
const isAnyPending = isLoading || isTransitioning || hasPending
const previousIsAnyPending = usePrevious(isAnyPending)

const isPagePending = isLoading || hasPendingMatches
const isPagePending = isLoading || hasPending
const previousIsPagePending = usePrevious(isPagePending)

router.startTransition = (fn: () => void) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/react-router/src/headContentUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
return buildTagsFromMatches(
router,
nonce,
router.stores.activeMatchesSnapshot.get(),
router.stores.matches.get(),
assetCrossOrigin,
)
}

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const routeMeta = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
(matches) => {
return matches.map((match) => match.meta!).filter(Boolean)
},
Expand Down Expand Up @@ -282,7 +282,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const links = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
(matches) => {
const constructed = matches
.map((match) => match.links!)
Expand Down Expand Up @@ -327,7 +327,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const preloadLinks = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
(matches) => {
const preloadLinks: Array<RouterManagedTag> = []

Expand Down Expand Up @@ -359,7 +359,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const styles = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
(matches) =>
(
matches
Expand All @@ -379,7 +379,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {

// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
const headScripts: Array<RouterManagedTag> = useStore(
router.stores.activeMatchesSnapshot,
router.stores.matches,
(matches) =>
(
matches
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/src/useMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export function useMatch<
const key = opts.from ?? nearestMatchId
const matchStore = key
? opts.from
? router.stores.getMatchStoreByRouteId(key)
: router.stores.activeMatchStoresById.get(key)
? router.stores.getRouteMatchStore(key)
: router.stores.matchStores.get(key)
: undefined

if (isServer ?? router.isServer) {
Expand Down
10 changes: 5 additions & 5 deletions packages/router-core/src/load-matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {

const hasForcePendingActiveMatch = (router: AnyRouter): boolean => {
return router.stores.matchesId.get().some((matchId) => {
return router.stores.activeMatchStoresById.get(matchId)?.get()._forcePending
return router.stores.matchStores.get(matchId)?.get()._forcePending
})
}

const resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {
return !!(
inner.preload && !inner.router.stores.activeMatchStoresById.has(matchId)
inner.preload && !inner.router.stores.matchStores.has(matchId)
)
}

Expand Down Expand Up @@ -882,12 +882,12 @@ const loadRouteMatch = async (
const activeIdAtIndex = inner.router.stores.matchesId.get()[index]
const activeAtIndex =
(activeIdAtIndex &&
inner.router.stores.activeMatchStoresById.get(activeIdAtIndex)) ||
inner.router.stores.matchStores.get(activeIdAtIndex)) ||
null
const previousRouteMatchId =
activeAtIndex?.routeId === routeId
? activeIdAtIndex
: inner.router.stores.activeMatchesSnapshot
: inner.router.stores.matches
.get()
.find((d) => d.routeId === routeId)?.id
const preload = resolvePreload(inner, matchId)
Expand Down Expand Up @@ -923,7 +923,7 @@ const loadRouteMatch = async (
}
} else {
const nextPreload =
preload && !inner.router.stores.activeMatchStoresById.has(matchId)
preload && !inner.router.stores.matchStores.has(matchId)
const match = inner.router.getMatch(matchId)!
match._nonReactive.loaderPromise = createControlledPromise<void>()
if (nextPreload !== match.preload) {
Expand Down
Loading
Loading