Skip to content

feat(router): parse query params and pass to components as attributes#237

Merged
mohamedmansour merged 2 commits intomainfrom
feat/parse-query-param
Apr 15, 2026
Merged

feat(router): parse query params and pass to components as attributes#237
mohamedmansour merged 2 commits intomainfrom
feat/parse-query-param

Conversation

@mohamedmansour
Copy link
Copy Markdown
Contributor

  • Add parseQuery() helper to extract URLSearchParams from request paths
  • Include 'query' field in NavigationEvent dispatched on navigation
  • Pass query params as kebab-case attributes on mounted/re-applied components
  • Add page-compose fixture with @attr fields for query param testing
  • Add 7 unit tests for parseQuery (empty, single, multiple, encoded, dupes)
  • Add 3 E2E tests: SSR render, client-side attr flow, navigated event query
  • Update router README and docs/guide/ai.md with query param documentation
  • All 32 unit tests + 11 E2E tests pass

janechu
janechu previously approved these changes Apr 14, 2026
@mohamedmansour mohamedmansour force-pushed the feat/parse-query-param branch 2 times, most recently from d2d6432 to 1941989 Compare April 14, 2026 22:44
Parse URL query parameters and forward them as component attributes,
gated by a deny-by-default allowlist declared on <route> elements:

  <route path="compose" component="page-compose" query="action,to,subject" />

Full-stack implementation across proto schema, parser, handler, and
TS router. Only params listed in the query attribute are set as DOM
attributes; unlisted params are silently dropped. Route params always
take priority over query params (kebab-case collision check), and
stale query-param attributes are removed on re-navigation.

The NavigationEvent.query field exposes all URL query params
(unfiltered) for programmatic JS consumers.

Also in this commit:
- Handle non-JSON server responses gracefully in fetchPartial by
  checking Content-Type before parsing; falls back to full page
  navigation for HTML responses (e.g. login redirects)
- Add View Transitions API documentation to README and docs/guide
- Add page-compose fixture with @attr fields for E2E testing
- Add 14 unit tests (parseQuery + filterQuery) and 5 E2E tests
  (SSR render, client-side attr flow, allowlist enforcement,
  navigated event query, unfiltered event verification)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohamedmansour mohamedmansour force-pushed the feat/parse-query-param branch from 410d533 to 43237b3 Compare April 15, 2026 01:45
- Add Rust tests for allowed_query across the stack:
  - Protocol: round-trip with non-empty allowed_query
  - Parser: query attribute parsed into allowed_query field
  - Handler: matched/non-matched routes emit query attr in SSR
  - Handler: RouteChainEntry.to_json includes/omits allowedQuery
  - Handler: collect_route_chain carries allowed_query through
- Update DESIGN.md with allowed_query proto field and query attr docs
- Update VitePress docs: route.md, routing.md, ai.md with query attr
- Extract toKebab to module-level helper (was duplicated 3x)
- Add abort guard before content-type redirect in fetchPartial
- Fix fetch mocks in unit tests to include headers for content-type check

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohamedmansour mohamedmansour force-pushed the feat/parse-query-param branch from 43237b3 to 15a3987 Compare April 15, 2026 01:47
@mohamedmansour mohamedmansour requested review from a team and janechu April 15, 2026 01:59
@mohamedmansour mohamedmansour merged commit c9fbf9b into main Apr 15, 2026
21 checks passed
@mohamedmansour mohamedmansour deleted the feat/parse-query-param branch April 15, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants