mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
b89afe0736
Add wrapWithRouterContext() function to the next/router shim that wraps any React element in a <RouterContext.Provider>. This is the root-cause fix: it builds the router value object directly from the SSR context (server) or window.location + Router singleton (client) — no hooks, no duplicate state, no extra component. This provides a single source of truth for the router context value, matching how Next.js provides RouterContext at the framework level. Wrapping sites: - dev-server.ts: main render, ISR re-render, error page render - index.ts virtual module: production renderPage and ISR re-render - Hydration script: client-side hydration entry - navigateClient: client-side navigation re-renders Tests: - useRouter returns null without provider (default/App Router) - useRouter returns full router when wrapWithRouterContext wraps tree - useRouter reflects SSR context (pathname, query, asPath) - wrapWithRouterContext is exported from next/router Closes #239