feat(router): add route loaders via static loader() method#255
Merged
mohamedmansour merged 1 commit intomainfrom Apr 20, 2026
Merged
feat(router): add route loaders via static loader() method#255mohamedmansour merged 1 commit intomainfrom
mohamedmansour merged 1 commit intomainfrom
Conversation
6 tasks
5a06493 to
fa5edb3
Compare
mcritzjam
previously approved these changes
Apr 20, 2026
Components can define a static loader({ params, query, signal }) method
to fetch data from a custom source instead of using server-provided state.
- Loaders run pre-commit (before view transition) for synchronous DOM update
- Loaders run on SSR bootstrap too for SSR/SPA parity
- On failure, falls back to server data.state with a console warning
- AbortSignal tied to navigation cancels in-flight loaders
- Export RouteLoaderContext type from @microsoft/webui-router
- 6 new unit tests (54 total, all passing)
- Update routing docs, ai.md, and router README
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fa5edb3 to
d62bcb2
Compare
mcritzjam
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Why: Components need a way to fetch their own data instead of relying on server-provided state — WebSocket dashboards, custom APIs, client-side caches all need this. TanStack and Remix both have loader APIs; we had no equivalent.
What: Add
static loader({ params, query, signal })on component classes as the structured replacement for the removedstatelessattribute. The router orchestrates loader execution, error handling, and abort signals.How:
resolveLoaders()runs pre-commit (before view transition) so loader results are available synchronously during DOM update.console.warnand the component falls back todata.statefrom the server partial.AbortSignaltied to navigation cancels in-flight loaders when the user navigates away.RouteLoaderContexttype from@microsoft/webui-router.Test Plan
pnpm testin webui-router — 55 unit tests pass (6 new loader tests)Checklist
static loader()method on component classRouteLoaderContexttype exported