Skip to content

feat(web): preload routes on navigation intent - #569

Open
Yevanchen wants to merge 1 commit into
mainfrom
perf/web-page-load-latency
Open

feat(web): preload routes on navigation intent#569
Yevanchen wants to merge 1 commit into
mainfrom
perf/web-page-load-latency

Conversation

@Yevanchen

Copy link
Copy Markdown
Collaborator

Summary

  • Prefetch the matched lazy route on pointer or keyboard intent, then reuse the resolved route and app-shell modules without another Suspense delay.
  • Load only the active translation catalog instead of bundling all four locales into the initial entry.
  • Add a repeatable Playwright benchmark covering all 39 route objects, including aliases and redirects.

Why

  • Lazy route changes could wait roughly 200–250 ms behind React's transition/Suspense deferral even after their chunks arrived.
  • Every visitor downloaded every translation catalog, making the initial JavaScript entry 90.86 kB gzip.

Closes YEF-1079.

Verification

  • Commands:
    • PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' bun run --filter @mosoo/e2e benchmark:web-page-loads
    • bun run --filter @mosoo/web test (238 passed)
    • just lint
    • just tc-package @mosoo/web
    • just tc-package @mosoo/e2e
    • bun run --filter @mosoo/web build
    • just fmt-check
  • Manual steps: Five fresh-context samples for every route passed the 50 ms median gate; medians were 1.7–29.3 ms and the worst individual sample was 29.6 ms. The entry fell from 90.86 to 31.27 kB gzip (65.6%).
  • Not run: The repository-wide just check was attempted, but the Driver suite has 11 failures and 1 error in its macOS process-supervision tests (1,222 other tests passed); focused Web/E2E verification above is green.

Impact

  • User/API/contract changes: Same-origin route links now prefetch their matching code on pointer hover or keyboard focus; language changes await the selected catalog once.
  • Generated files / GraphQL / DB / lockfile: None.
  • Env or config changes: None.
  • Risk and rollback: The preload map must stay aligned with the route registry. Reverting this commit restores the prior lazy-route and bundled-catalog behavior.

Review

  • Closest review areas: Route intent prefetching and Suspense boundaries, async locale loading, and the benchmark's route/redirect matrix.
  • Known trade-offs: Hovering or focusing a same-origin link may transfer its route chunk before activation; this is bounded by the module cache.

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.

1 participant