refactor(router): add support for non-blocking router resources - #70211
refactor(router): add support for non-blocking router resources #70211atscott wants to merge 3 commits into
Conversation
f1a4e5f to
45c2c1f
Compare
… feature Activated Route Injector feature was developed for resources. This moves the internal naming (files and vars) to reflect this now that we have landed the core bits of plumbing and are ready to implement router resources.
7308452 to
328a20f
Compare
|
On the size diff, this is mostly a result of accumulated size increase and crossing the threshold now origin/main router size (minified): 81,628 bytes |
328a20f to
9ed8d98
Compare
Introduces support for route-level resources via the `resources` property on route definitions, enabled with `withRouterResources()`. Router resources provide a reactive, signal-based alternative to resolvers, allowing routes to declare resources tied to route parameters and route lifecycle: - The `resources` function executes during navigation transitions within an injection context scoped to the route (`_localInjector`). - It receives a `ResourceContext` containing signals for `params`, `queryParams`, `fragment`, and `data`, alongside the static `snapshot`. - For newly created routes, `resources` runs once and attaches to `ActivatedRoute.resources`. For reused routes, parameter signals update reactively to trigger new data fetches while keeping resource references stable. - Wrapped resources (`routerResource`) provide transactional stability: snapshots are frozen during active navigations to prevent UI jitter, unfreezing on `NavigationEnd`. - On cancelled navigations or errors, rollback recovery retains the frozen snapshot until reverted signals settle, avoiding flashes of loading state. Manual reloads are rejected while frozen. - Local injectors are automatically cleaned up if navigations are cancelled or rolled back. Note that this commit only implements non-blocking resources (marked with `nonBlocking()`), deferring blocking resource resolution to future work to keep the initial changeset smaller and less complex.
9ed8d98 to
17d9385
Compare
| // (undocumented) | ||
| get queryParamMap(): ParamMap; | ||
| queryParams: Params; | ||
| resources?: ResourceResult; |
There was a problem hiding this comment.
We're missing an export for ResourceResult, it should appear in this file.
There was a problem hiding this comment.
It is exported just not to public API yet, which is correct.
There was a problem hiding this comment.
oh wait this is ActivatedRouteSnapshot - I thought it was Route. This needs to be internal
| // reactively loading new parameters behind the scenes) would disrupt the router's resource | ||
| // tracking for the transition. Similarly, during a rollback recovery, the router is | ||
| // already managing the resource reload to restore the previous state. | ||
| if (frozenSnapshot() !== null) { |
There was a problem hiding this comment.
Shouldn't we untrack here ?
| if (untracked(frozenSnapshot) !== null) { |
There was a problem hiding this comment.
The entire navigation transition is untracked (and async)
| } | ||
| } | ||
|
|
||
| return Promise.all(resourceSetupPromises).then(throwIfAborted); |
There was a problem hiding this comment.
Do we really need .then(throwIfAborted); ?
Wouldn't takeUntil(abortSignalToObservable(abortController.signal take care of unsubscribing and we would end up with a UnhandledPromiseRejection ?
There was a problem hiding this comment.
I'll remove it - it's because there's a blocking resolver await after that part which isn't included here. There's no unhandled promise because it's handled by rxjs.
f2d8bc6 to
8821e8c
Compare
Introduces support for route-level resources via the
resourcesproperty on route definitions, enabled withwithRouterResources().Router resources provide a reactive, signal-based alternative to resolvers, allowing routes to declare resources tied to route parameters and route lifecycle:
resourcesfunction executes during navigation transitions within an injection context scoped to the route (_localInjector).ResourceContextcontaining signals forparams,queryParams,fragment, anddata, alongside the staticsnapshot.resourcesruns once and attaches toActivatedRoute.resources. For reused routes, parameter signals update reactively to trigger new data fetches while keeping resource references stable.routerResource) provide transactional stability: snapshots are frozen during active navigations to prevent UI jitter, unfreezing onNavigationEnd.Note that this commit only implements non-blocking resources (marked with
nonBlocking()), deferring blocking resource resolution to future work to keep the initial changeset smaller and less complex.