Skip to content

Minor internals from audit: URLPattern compile cache, shared idleController, locationInfo lifetime, testing exports #219

Description

@uhyo

Grab-bag of small items from a library audit (see AUDIT.md on branch claude/library-audit-sxpugz, §1.10 / §3.10) that don't warrant individual issues. Each is independently actionable.

  1. Cache compiled URLPatterns. matchPath constructs new URLPattern(...) per route per match attempt (packages/router/src/core/matchRoutes.ts). A module-level Map<string, URLPattern> keyed by the pattern string would cut per-navigation work; route tables are small and static so the map stays tiny.

  2. idleController is module-level (packages/router/src/core/NavigationAPIAdapter.ts), shared across adapter instances. Two Routers on one page share and abort each other's initial-load signal. Making it an instance field matches the rest of the adapter's state.

  3. locationInfo outlives the navigation. #currentNavigationInfo is only cleared when the next navigate event fires, so info (documented as "only available during navigation, not persisted") remains readable via context/props long after the navigation finished. Either clear it on navigatesuccess/currententrychange completion or soften the docs.

  4. Export matchRoutes/matchPath (and possibly a memory adapter) for userland testing. Apps currently can't unit-test their route tables without mounting <Router> plus a Navigation API mock. A documented matchRoutes(routes, pathname) export (marked as not-semver-stable if preferred) would go a long way; a memory adapter would enable full component tests without the global mock.

  5. The navigatesuccess subscriber fallback fires in all browsers, not just WebKit Private Browsing — currently harmless because the snapshot cache makes the second callback a no-op re-set, but it's an easy place for future regressions. A comment and/or a test pinning "no extra render on navigatesuccess in normal browsers" would guard it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions