mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
1cd17b5b69
* fix: usePathname() returns "/" during SSR of "use client" page components (#688) The navigation shim uses a registration pattern where navigation-state.ts calls _registerStateAccessors() to upgrade navigation.ts from module-level state to ALS-backed state. This only updates the specific module instance that imported navigation-state.ts. In Vite multi-environment dev mode, "use client" components can end up with a separate module instance of navigation.ts (due to pre-bundling or different resolver chains). That instance never receives the ALS-backed accessors and falls back to _serverContext (null), causing usePathname() to return "/". Fix: navigation-state.ts now also stores the accessor functions on globalThis via Symbol.for("vinext.navigation.globalAccessors"). The default accessors in navigation.ts check this global before falling back to module-level state. This ensures all module instances can reach the ALS-backed state regardless of which instance _registerStateAccessors was called on. On the browser (where navigation-state.ts is never imported), the global key does not exist, so the fallback to module-level _serverContext is preserved — which is the correct behavior for client-side hydration. Closes #688 * refactor: deduplicate global accessor key and tighten types - Export GLOBAL_ACCESSORS_KEY from navigation.ts and import in navigation-state.ts to prevent silent drift if the Symbol string ever changes - Add satisfies constraint on the accessor object so shape mismatches are caught at compile time - Assert warm-up fetch status in test to surface fixture setup failures