@timber-js/app 0.2.0-alpha.249 → 0.2.0-alpha.250
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{actions-C7_xl9iA.js → actions-DH_TCxJb.js} +2 -2
- package/dist/_chunks/{actions-C7_xl9iA.js.map → actions-DH_TCxJb.js.map} +1 -1
- package/dist/_chunks/dev-span-0aG7Q_Ph.js.map +1 -1
- package/dist/_chunks/{dist-GyaJm4GA.js → dist-ob734WH3.js} +20 -19
- package/dist/_chunks/dist-ob734WH3.js.map +1 -0
- package/dist/_chunks/{error-boundary-wuNvAJ4n.js → error-boundary-BR21tTQc.js} +3 -3
- package/dist/_chunks/{error-boundary-wuNvAJ4n.js.map → error-boundary-BR21tTQc.js.map} +1 -1
- package/dist/_chunks/global-context-DbxNWeBP.js +47 -0
- package/dist/_chunks/global-context-DbxNWeBP.js.map +1 -0
- package/dist/_chunks/{navigation-root-Cvb7P1ud.js → navigation-root-AuCD35Sv.js} +42 -47
- package/dist/_chunks/navigation-root-AuCD35Sv.js.map +1 -0
- package/dist/_chunks/ssr-data-BfsCqCLl.js +47 -0
- package/dist/_chunks/ssr-data-BfsCqCLl.js.map +1 -0
- package/dist/client/browser-entry/post-hydration.d.ts +2 -2
- package/dist/client/browser-entry/post-hydration.d.ts.map +1 -1
- package/dist/client/browser-entry/scroll.d.ts +11 -8
- package/dist/client/browser-entry/scroll.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +12 -9
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.d.ts +0 -2
- package/dist/client/internal.d.ts.map +1 -1
- package/dist/client/internal.js +6 -6
- package/dist/client/internal.js.map +1 -1
- package/dist/client/link.d.ts.map +1 -1
- package/dist/client/ssr-data.d.ts +35 -38
- package/dist/client/ssr-data.d.ts.map +1 -1
- package/dist/client/state.d.ts +1 -8
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/use-cookie.d.ts.map +1 -1
- package/dist/client/use-search-params.d.ts.map +1 -1
- package/dist/cookies/index.js +3 -3
- package/dist/cookies/index.js.map +1 -1
- package/dist/native/rsc/client/global-context.js +20 -0
- package/dist/native/rsc/client/global-context.js.map +1 -0
- package/dist/native/rsc/client/ssr-data.js +9 -4
- package/dist/native/rsc/client/ssr-data.js.map +1 -1
- package/dist/native/rsc/client/use-cookie.js +4 -4
- package/dist/native/rsc/client/use-cookie.js.map +1 -1
- package/dist/native/rsc/manifest.json +1 -1
- package/dist/native/rsc/server/build-manifest.js +1 -4
- package/dist/native/rsc/server/build-manifest.js.map +1 -1
- package/dist/native/rsc/server/html-injectors.js +6 -7
- package/dist/native/rsc/server/html-injectors.js.map +1 -1
- package/dist/native/rsc/server/react-cache-bridge.js +2 -2
- package/dist/native/rsc/server/react-cache-bridge.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +3 -5
- package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/ssr-renderer.js +3 -2
- package/dist/native/rsc/server/rsc-entry/ssr-renderer.js.map +1 -1
- package/dist/native/ssr/client/link.js +10 -8
- package/dist/native/ssr/client/link.js.map +1 -1
- package/dist/native/ssr/client/ssr-data.js +10 -6
- package/dist/native/ssr/client/ssr-data.js.map +1 -1
- package/dist/native/ssr/client/state.js +1 -5
- package/dist/native/ssr/client/state.js.map +1 -1
- package/dist/native/ssr/client/use-cookie.js +2 -2
- package/dist/native/ssr/client/use-cookie.js.map +1 -1
- package/dist/native/ssr/client/use-search-params.js +3 -2
- package/dist/native/ssr/client/use-search-params.js.map +1 -1
- package/dist/native/ssr/server/ssr-wrappers.js +11 -4
- package/dist/native/ssr/server/ssr-wrappers.js.map +1 -1
- package/dist/server/build-manifest.d.ts +0 -7
- package/dist/server/build-manifest.d.ts.map +1 -1
- package/dist/server/html-injectors.d.ts +5 -4
- package/dist/server/html-injectors.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +1 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts +2 -0
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/ssr-bridge-types.d.ts +6 -0
- package/dist/server/ssr-bridge-types.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/ssr-wrappers.d.ts +14 -9
- package/dist/server/ssr-wrappers.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/client/browser-entry/post-hydration.ts +27 -22
- package/src/client/browser-entry/scroll.ts +12 -9
- package/src/client/internal.ts +0 -4
- package/src/client/link.tsx +14 -13
- package/src/client/ssr-data.ts +50 -57
- package/src/client/state.ts +1 -14
- package/src/client/use-cookie.ts +4 -3
- package/src/client/use-search-params.ts +5 -4
- package/src/server/build-manifest.ts +0 -10
- package/src/server/html-injectors.ts +11 -13
- package/src/server/rsc-entry/render-route.ts +9 -8
- package/src/server/rsc-entry/ssr-renderer.ts +4 -1
- package/src/server/ssr-bridge-types.ts +6 -0
- package/src/server/ssr-entry.ts +180 -207
- package/src/server/ssr-wrappers.tsx +52 -14
- package/dist/_chunks/dist-GyaJm4GA.js.map +0 -1
- package/dist/_chunks/navigation-root-Cvb7P1ud.js.map +0 -1
- package/dist/_chunks/ssr-data-9hPtcNOr.js +0 -48
- package/dist/_chunks/ssr-data-9hPtcNOr.js.map +0 -1
- package/dist/_chunks/state-B-EBjeER.js +0 -49
- package/dist/_chunks/state-B-EBjeER.js.map +0 -1
- package/dist/native/rsc/client/state.js +0 -14
- package/dist/native/rsc/client/state.js.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// src/client/global-context.ts
|
|
3
|
+
/**
|
|
4
|
+
* createGlobalContext — a React context with a process-wide singleton identity.
|
|
5
|
+
*
|
|
6
|
+
* SINGLETON GUARANTEE: Uses globalThis + Symbol.for — same pattern as
|
|
7
|
+
* NavigationContext. The RSC client bundler can duplicate a module across
|
|
8
|
+
* chunks (browser-entry graph + client-reference graph). With ESM output,
|
|
9
|
+
* each chunk gets its own module scope — a bare createContext at module
|
|
10
|
+
* level would create separate instances per chunk. globalThis guarantees a
|
|
11
|
+
* single instance regardless of duplication.
|
|
12
|
+
*
|
|
13
|
+
* One context per React instance, not per process. Duplicated chunks share
|
|
14
|
+
* one React, so they share the context. A dev SSR program reload evaluates
|
|
15
|
+
* React and react-dom/server again, in the same process: the new renderer
|
|
16
|
+
* must get a context of its own. Handed the previous one, React logs
|
|
17
|
+
* "Detected multiple renderers concurrently rendering the same context
|
|
18
|
+
* provider" on every client-component edit, and the stale context keeps a
|
|
19
|
+
* piece of the discarded copy alive (TIM-1590).
|
|
20
|
+
*
|
|
21
|
+
* See design/19-client-navigation.md §"Singleton Guarantee via globalThis"
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The context `key` names for this React instance, created on first use.
|
|
25
|
+
* Pass the key as a `Symbol.for('…')` literal at the call site, so each key
|
|
26
|
+
* stays greppable in the build output (tests/bundle-singleton-audit.test.ts
|
|
27
|
+
* checks `__timber_nav_ctx`).
|
|
28
|
+
*/
|
|
29
|
+
function createGlobalContext(key, defaultValue) {
|
|
30
|
+
return createGlobalContextFor(React, key, defaultValue);
|
|
31
|
+
}
|
|
32
|
+
/** createGlobalContext for a given React instance. Exported for tests. */
|
|
33
|
+
function createGlobalContextFor(react, key, defaultValue) {
|
|
34
|
+
if (typeof react.createContext !== "function") return;
|
|
35
|
+
const slot = Reflect.get(globalThis, key);
|
|
36
|
+
const byReact = slot instanceof WeakMap ? slot : /* @__PURE__ */ new WeakMap();
|
|
37
|
+
if (byReact !== slot) Reflect.set(globalThis, key, byReact);
|
|
38
|
+
let ctx = byReact.get(react);
|
|
39
|
+
if (!ctx) {
|
|
40
|
+
ctx = react.createContext(defaultValue);
|
|
41
|
+
byReact.set(react, ctx);
|
|
42
|
+
}
|
|
43
|
+
return ctx;
|
|
44
|
+
}
|
|
45
|
+
export { createGlobalContext as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=global-context-DbxNWeBP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-context-DbxNWeBP.js","names":[],"sources":["../../src/client/global-context.ts"],"sourcesContent":["/**\n * createGlobalContext — a React context with a process-wide singleton identity.\n *\n * SINGLETON GUARANTEE: Uses globalThis + Symbol.for — same pattern as\n * NavigationContext. The RSC client bundler can duplicate a module across\n * chunks (browser-entry graph + client-reference graph). With ESM output,\n * each chunk gets its own module scope — a bare createContext at module\n * level would create separate instances per chunk. globalThis guarantees a\n * single instance regardless of duplication.\n *\n * One context per React instance, not per process. Duplicated chunks share\n * one React, so they share the context. A dev SSR program reload evaluates\n * React and react-dom/server again, in the same process: the new renderer\n * must get a context of its own. Handed the previous one, React logs\n * \"Detected multiple renderers concurrently rendering the same context\n * provider\" on every client-component edit, and the stale context keeps a\n * piece of the discarded copy alive (TIM-1590).\n *\n * See design/19-client-navigation.md §\"Singleton Guarantee via globalThis\"\n */\n\nimport React from 'react';\n\n/** The part of a React instance a context comes from. */\nexport interface ContextFactory {\n createContext?: typeof React.createContext;\n}\n\n/**\n * The context `key` names for this React instance, created on first use.\n * Pass the key as a `Symbol.for('…')` literal at the call site, so each key\n * stays greppable in the build output (tests/bundle-singleton-audit.test.ts\n * checks `__timber_nav_ctx`).\n */\nexport function createGlobalContext<T>(key: symbol, defaultValue: T): React.Context<T> {\n return createGlobalContextFor(React, key, defaultValue);\n}\n\n/** createGlobalContext for a given React instance. Exported for tests. */\nexport function createGlobalContextFor<T>(\n react: ContextFactory,\n key: symbol,\n defaultValue: T\n): React.Context<T> {\n if (typeof react.createContext !== 'function') {\n // RSC environment — createContext not available. Return a dummy that\n // won't be used (the consumers only render on the client / during SSR).\n return undefined as unknown as React.Context<T>;\n }\n const slot: unknown = Reflect.get(globalThis, key);\n const byReact = slot instanceof WeakMap ? slot : new WeakMap<object, React.Context<T>>();\n if (byReact !== slot) Reflect.set(globalThis, key, byReact);\n let ctx: React.Context<T> | undefined = byReact.get(react);\n if (!ctx) {\n ctx = react.createContext<T>(defaultValue);\n byReact.set(react, ctx);\n }\n return ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,oBAAuB,KAAa,cAAmC;CACrF,OAAO,uBAAuB,OAAO,KAAK,YAAY;AACxD;;AAGA,SAAgB,uBACd,OACA,KACA,cACkB;CAClB,IAAI,OAAO,MAAM,kBAAkB,YAGjC;CAEF,MAAM,OAAgB,QAAQ,IAAI,YAAY,GAAG;CACjD,MAAM,UAAU,gBAAgB,UAAU,uBAAO,IAAI,QAAkC;CACvF,IAAI,YAAY,MAAM,QAAQ,IAAI,YAAY,KAAK,OAAO;CAC1D,IAAI,MAAoC,QAAQ,IAAI,KAAK;CACzD,IAAI,CAAC,KAAK;EACR,MAAM,MAAM,cAAiB,YAAY;EACzC,QAAQ,IAAI,OAAO,GAAG;CACxB;CACA,OAAO;AACT"}
|
|
@@ -1,5 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { t as createGlobalContext } from "./global-context-DbxNWeBP.js";
|
|
2
|
+
import { createElement, use, useContext, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
// src/client/state.ts
|
|
4
|
+
/** The global router singleton — set once during bootstrap. */
|
|
5
|
+
var globalRouter = null;
|
|
6
|
+
function _setGlobalRouter(router) {
|
|
7
|
+
globalRouter = router;
|
|
8
|
+
}
|
|
9
|
+
/** Cached search string — avoids reparsing when URL hasn't changed. */
|
|
10
|
+
var cachedSearch = "";
|
|
11
|
+
var cachedSearchParams = new URLSearchParams();
|
|
12
|
+
function _setCachedSearch(search, params) {
|
|
13
|
+
cachedSearch = search;
|
|
14
|
+
cachedSearchParams = params;
|
|
15
|
+
}
|
|
16
|
+
/** Whether the page is currently being unloaded. */
|
|
17
|
+
var unloading = false;
|
|
18
|
+
function _setUnloading(value) {
|
|
19
|
+
unloading = value;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether a status page for the main route has rendered since the last
|
|
23
|
+
* navigation was prepared. Raised by `StatusPageMarker`, consumed by the
|
|
24
|
+
* navigation's commit. See navigation-commit.ts §"What a status page
|
|
25
|
+
* teaches the cache".
|
|
26
|
+
*/
|
|
27
|
+
var statusPageRendered = false;
|
|
28
|
+
function _setStatusPageRendered(value) {
|
|
29
|
+
statusPageRendered = value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What a status page report does beyond raising the flag: registered by the
|
|
33
|
+
* router's committer so the report can clear the segment cache at once, for
|
|
34
|
+
* the commits no navigation consumes (a row arriving inside Suspense after
|
|
35
|
+
* its navigation published, a status document being hydrated).
|
|
36
|
+
*/
|
|
37
|
+
var onStatusPageRendered;
|
|
38
|
+
function _setOnStatusPageRendered(handler) {
|
|
39
|
+
onStatusPageRendered = handler;
|
|
40
|
+
}
|
|
3
41
|
// src/client/router-ref.ts
|
|
4
42
|
/**
|
|
5
43
|
* Set the global router instance. Called once during bootstrap.
|
|
@@ -23,49 +61,6 @@ function getRouter() {
|
|
|
23
61
|
function getRouterOrNull() {
|
|
24
62
|
return globalRouter;
|
|
25
63
|
}
|
|
26
|
-
// src/client/global-context.ts
|
|
27
|
-
/**
|
|
28
|
-
* createGlobalContext — a React context with a process-wide singleton identity.
|
|
29
|
-
*
|
|
30
|
-
* SINGLETON GUARANTEE: Uses globalThis + Symbol.for — same pattern as
|
|
31
|
-
* NavigationContext. The RSC client bundler can duplicate a module across
|
|
32
|
-
* chunks (browser-entry graph + client-reference graph). With ESM output,
|
|
33
|
-
* each chunk gets its own module scope — a bare createContext at module
|
|
34
|
-
* level would create separate instances per chunk. globalThis guarantees a
|
|
35
|
-
* single instance regardless of duplication.
|
|
36
|
-
*
|
|
37
|
-
* One context per React instance, not per process. Duplicated chunks share
|
|
38
|
-
* one React, so they share the context. A dev SSR program reload evaluates
|
|
39
|
-
* React and react-dom/server again, in the same process: the new renderer
|
|
40
|
-
* must get a context of its own. Handed the previous one, React logs
|
|
41
|
-
* "Detected multiple renderers concurrently rendering the same context
|
|
42
|
-
* provider" on every client-component edit, and the stale context keeps a
|
|
43
|
-
* piece of the discarded copy alive (TIM-1590).
|
|
44
|
-
*
|
|
45
|
-
* See design/19-client-navigation.md §"Singleton Guarantee via globalThis"
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* The context `key` names for this React instance, created on first use.
|
|
49
|
-
* Pass the key as a `Symbol.for('…')` literal at the call site, so each key
|
|
50
|
-
* stays greppable in the build output (tests/bundle-singleton-audit.test.ts
|
|
51
|
-
* checks `__timber_nav_ctx`).
|
|
52
|
-
*/
|
|
53
|
-
function createGlobalContext(key, defaultValue) {
|
|
54
|
-
return createGlobalContextFor(React, key, defaultValue);
|
|
55
|
-
}
|
|
56
|
-
/** createGlobalContext for a given React instance. Exported for tests. */
|
|
57
|
-
function createGlobalContextFor(react, key, defaultValue) {
|
|
58
|
-
if (typeof react.createContext !== "function") return;
|
|
59
|
-
const slot = Reflect.get(globalThis, key);
|
|
60
|
-
const byReact = slot instanceof WeakMap ? slot : /* @__PURE__ */ new WeakMap();
|
|
61
|
-
if (byReact !== slot) Reflect.set(globalThis, key, byReact);
|
|
62
|
-
let ctx = byReact.get(react);
|
|
63
|
-
if (!ctx) {
|
|
64
|
-
ctx = react.createContext(defaultValue);
|
|
65
|
-
byReact.set(react, ctx);
|
|
66
|
-
}
|
|
67
|
-
return ctx;
|
|
68
|
-
}
|
|
69
64
|
// src/client/navigation-context.ts
|
|
70
65
|
/**
|
|
71
66
|
* NavigationContext — React context for navigation state.
|
|
@@ -306,6 +301,6 @@ function getHardNavStore() {
|
|
|
306
301
|
function setHardNavigating(value) {
|
|
307
302
|
getHardNavStore().value = value;
|
|
308
303
|
}
|
|
309
|
-
export { NavigationProvider as a,
|
|
304
|
+
export { statusPageRendered as _, NavigationProvider as a, getRouterOrNull as c, _setOnStatusPageRendered as d, _setStatusPageRendered as f, onStatusPageRendered as g, cachedSearchParams as h, routerUrlKey as i, setGlobalRouter as l, cachedSearch as m, usePendingNavigation as n, useNavigationContext as o, _setUnloading as p, parseRouterUrl as r, getRouter as s, setHardNavigating as t, _setCachedSearch as u, unloading as v };
|
|
310
305
|
|
|
311
|
-
//# sourceMappingURL=navigation-root-
|
|
306
|
+
//# sourceMappingURL=navigation-root-AuCD35Sv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-root-AuCD35Sv.js","names":[],"sources":["../../src/client/state.ts","../../src/client/router-ref.ts","../../src/client/navigation-context.ts","../../src/client/router-url.ts","../../src/client/use-pending-navigation.ts","../../src/client/navigation-root.tsx"],"sourcesContent":["/**\n * Centralized client singleton state registry.\n *\n * ALL mutable module-level state that must have singleton semantics across\n * the client bundle lives here. Individual modules (router-ref.ts,\n * use-segment-params.ts, use-search-params.ts, unload-guard.ts) import from this file\n * and re-export thin wrapper functions.\n *\n * Why: In Vite dev, a module is instantiated separately if reached via different\n * import paths (e.g., relative `./foo.js` vs barrel `@timber-js/app/client`).\n * By centralizing all mutable state in a single module that is always reached\n * through the same dependency chain (barrel → wrapper → state.ts), we guarantee\n * a single instance of every piece of shared state.\n *\n * DO NOT import this file from outside client/. Server code must never depend\n * on client state. The barrel (client/index.ts) is the public entry point.\n *\n * See design/18-build-system.md §\"Module Singleton Strategy\" and\n * §\"Singleton State Registry\".\n */\n\nimport type { RouterInstance } from './router-types.ts';\n\n// ─── Router (from router-ref.ts) ──────────────────────────────────────────\n\n/** The global router singleton — set once during bootstrap. */\nexport let globalRouter: RouterInstance | null = null;\n\nexport function _setGlobalRouter(router: RouterInstance | null): void {\n globalRouter = router;\n}\n\n// ─── Search Params Cache (from use-search-params.ts) ────────────────────────\n\n/** Cached search string — avoids reparsing when URL hasn't changed. */\nexport let cachedSearch = '';\nexport let cachedSearchParams = new URLSearchParams();\n\nexport function _setCachedSearch(search: string, params: URLSearchParams): void {\n cachedSearch = search;\n cachedSearchParams = params;\n}\n\n// ─── Unload Guard (from unload-guard.ts) ─────────────────────────────────────\n\n/** Whether the page is currently being unloaded. */\nexport let unloading = false;\n\nexport function _setUnloading(value: boolean): void {\n unloading = value;\n}\n\n// ─── Status Page Commit Flag (from navigation-commit.ts) ────────────────────\n\n/**\n * Whether a status page for the main route has rendered since the last\n * navigation was prepared. Raised by `StatusPageMarker`, consumed by the\n * navigation's commit. See navigation-commit.ts §\"What a status page\n * teaches the cache\".\n */\nexport let statusPageRendered = false;\n\nexport function _setStatusPageRendered(value: boolean): void {\n statusPageRendered = value;\n}\n\n/**\n * What a status page report does beyond raising the flag: registered by the\n * router's committer so the report can clear the segment cache at once, for\n * the commits no navigation consumes (a row arriving inside Suspense after\n * its navigation published, a status document being hydrated).\n */\nexport let onStatusPageRendered: (() => void) | undefined;\n\nexport function _setOnStatusPageRendered(handler: (() => void) | undefined): void {\n onStatusPageRendered = handler;\n}\n","// Global router reference — shared between browser-entry and client hooks.\n//\n// Delegates to client/state.ts for the actual module-level variable.\n// This ensures singleton semantics regardless of import path — all\n// callers converge on the same state.ts instance via the barrel.\n//\n// See design/18-build-system.md §\"Module Singleton Strategy\"\n\nimport type { RouterInstance } from './router-types.ts';\nimport { globalRouter, _setGlobalRouter } from './state.ts';\n\n/**\n * Set the global router instance. Called once during bootstrap.\n */\nexport function setGlobalRouter(router: RouterInstance): void {\n _setGlobalRouter(router);\n}\n\n/**\n * Get the global router instance. Throws if called before bootstrap.\n * Used by client-side hooks (usePendingNavigation, etc.)\n */\nexport function getRouter(): RouterInstance {\n if (!globalRouter) {\n throw new Error('[timber] Router not initialized. getRouter() was called before bootstrap().');\n }\n return globalRouter;\n}\n\n/**\n * Get the global router instance or null if not yet initialized.\n * Used by useRouter() methods to avoid silent failures — callers\n * can log a meaningful warning instead of silently no-oping.\n */\nexport function getRouterOrNull(): RouterInstance | null {\n return globalRouter;\n}\n\n/**\n * Reset the global router to null. Used only in tests to isolate\n * module-level state between test cases.\n * @internal\n */\nexport function resetGlobalRouter(): void {\n _setGlobalRouter(null);\n}\n","'use client';\n\n/**\n * NavigationContext — React context for navigation state.\n *\n * Holds the current pathname and search, updated atomically with the RSC\n * tree on each navigation. This replaces the previous useSyncExternalStore\n * approach for usePathname() and useSearchParams(), which suffered from a\n * timing gap: the new tree could commit before the external store\n * re-renders fired, causing a frame where both old and new active states\n * were visible simultaneously.\n *\n * Segment params are NOT here — see the note on NavigationState below.\n *\n * By wrapping the RSC payload element in NavigationProvider inside the\n * router's `renderTree` (browser-entry/router-init.ts), the context value and the element tree are passed to\n * reactRoot.render() in the same call — atomic by construction.\n * All consumers (usePathname, useSearchParams) see the new values in the\n * same render pass as the new tree.\n *\n * During SSR, the wrapper chain mounts this same provider with the\n * request's pathname and raw search string (TIM-1424), so the hooks\n * resolve through the identical code path on both sides. Per-request\n * isolation is by construction — the value is part of the request's\n * element tree.\n *\n * This module is `'use client'` and is never evaluated in the RSC\n * environment. The shims plugin resolves next/navigation to\n * navigation-rsc.ts in RSC, which has throwing stubs (TIM-1420).\n *\n * SINGLETON GUARANTEE: All shared mutable state uses globalThis via\n * Symbol.for keys. The RSC client bundler can duplicate this module\n * across chunks (browser-entry graph + client-reference graph). With\n * ESM output, each chunk gets its own module scope — module-level\n * variables would create separate singleton instances per chunk.\n * globalThis guarantees a single instance regardless of duplication.\n *\n * This workaround will be removed when Rolldown ships `format: 'app'`\n * (module registry format that deduplicates like webpack/Turbopack).\n * See design/27-chunking-strategy.md.\n *\n * See design/19-client-navigation.md §\"NavigationContext\"\n */\n\nimport { useContext, createElement, type ReactNode } from 'react';\nimport { createGlobalContext } from './global-context.ts';\n\n// ---------------------------------------------------------------------------\n// Context type\n// ---------------------------------------------------------------------------\n\n/**\n * What the browser knows about the current location.\n *\n * Params are deliberately absent: they are a property of the tree the server\n * rendered, not of the address bar, and they now travel inside the payload as\n * the payload root. Keeping a copy here meant the router had to thread\n * the record from a response header into context on every path — navigation,\n * traversal, prefetch, revalidation — and each of those was a place to drop it\n * (TIM-1294).\n */\nexport interface NavigationState {\n pathname: string;\n search: string;\n}\n\n// ---------------------------------------------------------------------------\n// Lazy context initialization\n// ---------------------------------------------------------------------------\n\n/**\n * Context instances are stored on globalThis (NOT in module-level\n * variables) because the ESM bundler can duplicate this module across\n * chunks. Module-level variables would create separate instances per\n * chunk — the provider in NavigationRoot (index chunk) would use\n * context A while the consumer in usePendingNavigation (shared chunk)\n * reads from context B. globalThis guarantees a single instance.\n *\n * This module is `'use client'` so it is never evaluated in the RSC\n * environment — `createContext` and `useContext` are always available.\n * The shims plugin resolves next/navigation to navigation-rsc.ts in RSC,\n * which has throwing stubs for the hooks (TIM-1420).\n *\n * See design/19-client-navigation.md §\"Singleton Guarantee via globalThis\"\n *\n * Exported for `usePendingNavigation(select)`, which reads it with React\n * `use()` — only in its selector form, so the plain form does not re-render\n * on every commit.\n */\nexport function getOrCreateContext(): import('react').Context<NavigationState | null> {\n return createGlobalContext<NavigationState | null>(Symbol.for('__timber_nav_ctx'), null);\n}\n\n/**\n * Read the navigation context. Returns null only when no provider is above\n * the caller — a component rendered outside the timber app.\n *\n * Internal — used by usePathname() and useSearchParams().\n */\nexport function useNavigationContext(): NavigationState | null {\n return useContext(getOrCreateContext());\n}\n\n// ---------------------------------------------------------------------------\n// Provider component\n// ---------------------------------------------------------------------------\n\nexport interface NavigationProviderProps {\n value: NavigationState;\n children?: ReactNode;\n}\n\n/**\n * Wraps children with NavigationContext.Provider.\n *\n * Used in browser-entry/router-init.ts `renderTree` to wrap the RSC payload element\n * so that navigation state updates atomically with the tree render.\n */\nexport function NavigationProvider({\n value,\n children,\n}: NavigationProviderProps): import('react').ReactElement {\n return createElement(getOrCreateContext().Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Pending navigation state lives in the router, not here\n// ---------------------------------------------------------------------------\n\n/**\n * There was a second React context here — `PendingNavigationContext`, holding\n * the in-flight navigation URL, provided by `NavigationRoot` out of a\n * `useState` — plus a `usePendingNavigationUrl()` reader for it. Both are gone\n * (TIM-1307).\n *\n * Nothing read them. `usePendingNavigation()` (use-pending-navigation.ts) and\n * `TopLoader` both subscribe to the router's external pending store via\n * `useSyncExternalStore`: sync priority, immune to transition entanglement,\n * and cleared by `runNavigation`'s supersession-guarded `finally` (TIM-1034).\n * The context was a parallel representation of the same fact that no consumer\n * ever migrated to, and one that could not even agree with the store — a\n * navigation superseded by a cached popstate replay left its URL set until the\n * next full navigation, because the staleness guard skipped the clear and no\n * other path touched it.\n *\n * One representation, and it is the router's. See\n * design/19-client-navigation.md §\"How Pending State Works\".\n */\n","/**\n * How the client router reads the URLs it is handed.\n *\n * One parser, so the places that key or compare by URL — the history stack,\n * the navigation state a page renders with, the departing page sent as\n * `X-Timber-URL` — cannot disagree about what a URL says. They did: a\n * history entry stored under `navigate('/café')`'s spelling was looked up\n * under the address bar's `/caf%C3%A9`, and missed (TIM-1541).\n */\n\nconst BASE = 'http://localhost';\n\n/**\n * Parse a router URL. A URL that starts with \"/\" is a path — including one\n * that starts with \"//\": that is the pathname a document at\n * `https://host//a/b` reports, and resolved against a base it would parse as\n * a scheme-relative reference to host `a`. Anything else resolves against a\n * placeholder origin, so an absolute URL keeps its own.\n */\nexport function parseRouterUrl(url: string): URL {\n return url.startsWith('/') ? new URL(BASE + url) : new URL(url, BASE);\n}\n\n/**\n * The spelling a URL is stored and looked up under: the browser's own\n * pathname + search, so `/a?` and `/a`, `/café` and `/caf%C3%A9`, are one\n * key. The fragment is dropped — it is client-only.\n */\nexport function routerUrlKey(url: string): string {\n const parsed = parseRouterUrl(url);\n return parsed.pathname + parsed.search;\n}\n","import { use, useMemo, useRef, useSyncExternalStore } from 'react';\nimport { getOrCreateContext } from './navigation-context.ts';\nimport { getRouterOrNull } from './router-ref.ts';\nimport { parseRouterUrl } from './router-url.ts';\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const router = getRouterOrNull();\n if (!router) return () => {};\n return router.onPendingChange(onStoreChange);\n}\n\nfunction isPending(): boolean {\n const router = getRouterOrNull();\n return router ? router.isPending() : false;\n}\n\nconst HAS_SCHEME = /^[a-z][a-z\\d+.-]*:/i;\n\n/**\n * A router URL as a `URL`, read the way the router reads it (`parseRouterUrl`)\n * so `to` names the page the router will commit. Anything without a scheme is\n * a path on this document's origin; an absolute URL keeps its own.\n */\nfunction pageUrl(url: string): URL {\n const parsed = parseRouterUrl(url);\n if (HAS_SCHEME.test(url)) return parsed;\n return new URL(window.location.origin + parsed.pathname + parsed.search + parsed.hash);\n}\n\n/**\n * Decides what a component wants to know about the navigation in flight.\n *\n * `to` is where the router is going, with the `#fragment` of a link or\n * `router.push()` that has one (traversals and refreshes carry none). `from`\n * is the page the navigation departs from, as the calling component rendered\n * it — not the address bar, which on Back/Forward has already moved. Both are\n * fresh `URL`s; don't mutate them.\n */\nexport type PendingNavigationSelector<T> = (to: URL, from: URL) => T;\n\n/**\n * Whether an RSC navigation is in flight — until its payload has decoded and\n * React has committed the destination, so it never turns false while the\n * departing page is still on screen.\n *\n * Reads the router's external pending store via `useSyncExternalStore`, so\n * only components that call this hook re-render when a navigation starts or\n * ends.\n *\n * ```tsx\n * 'use client'\n * import { usePendingNavigation } from '@timber-js/app/client'\n *\n * export function NavBar() {\n * const isPending = usePendingNavigation()\n * return <nav className={isPending ? 'opacity-50' : ''}>…</nav>\n * }\n * ```\n */\nexport function usePendingNavigation(): boolean;\n/**\n * The selector form: `select(to, from)` while a navigation is in flight,\n * `false` when none is. A navigation starting, being superseded or ending\n * re-renders the component only when the result changes (`Object.is`), so\n * return a primitive. The selector form also re-renders on commits, as\n * `usePathname()` does. A superseded navigation reports the newest target; a\n * followed redirect reports the redirect's destination.\n *\n * ```tsx\n * // Dim a list only while its own sort/filter/page navigation is in flight.\n * const replacing = usePendingNavigation((to, from) => to.pathname === from.pathname)\n * ```\n *\n * See design/19-client-navigation.md §\"Where the navigation is going\".\n */\nexport function usePendingNavigation<T>(select: PendingNavigationSelector<T>): T | false;\nexport function usePendingNavigation<T>(select?: PendingNavigationSelector<T>): T | boolean {\n // Read only by the selector form, so the plain form — TopLoader, a global\n // spinner — does not re-render on every commit.\n const nav = select ? use(getOrCreateContext()) : null;\n if (select && nav === null) {\n throw new Error(\n '[timber] usePendingNavigation(select) was called outside the timber app tree ' +\n '(no NavigationProvider found). In tests, render the component ' +\n 'inside the timber providers.'\n );\n }\n const rendered = nav ? nav.pathname + nav.search : null;\n\n // The page each navigation departs from: what this component was rendering\n // when it first saw the target. Held for the navigation's lifetime because\n // the location context moves to the destination at its commit, while the\n // router is still pending — read live, a link away would report \"same page\"\n // for that commit and for any streaming tail after it.\n const departure = useRef<{ target: string; from: string } | null>(null);\n\n const getSnapshot = useMemo((): (() => T | boolean) => {\n if (!select || rendered === null) return isPending;\n // `getSnapshot` must return the same value for the same store state, and\n // a selector returning `to` would otherwise hand React a new URL per call.\n let last: { target: string; from: string; value: T } | null = null;\n return () => {\n const target = getRouterOrNull()?.getPendingUrl() ?? null;\n if (target === null) {\n departure.current = null;\n return false;\n }\n if (departure.current?.target !== target) departure.current = { target, from: rendered };\n const from = departure.current.from;\n if (last?.target !== target || last.from !== from) {\n last = { target, from, value: select(pageUrl(target), pageUrl(from)) };\n }\n return last.value;\n };\n }, [select, rendered]);\n\n // The same read on the server: no router there, so it reports idle.\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","/**\n * NavigationRoot — the component the router renders the page through.\n *\n * It is stateless. The router owns the displayed tree and drives React with\n * `root.render(<NavigationRoot rendered={{ element, publish }} />)` inside a\n * synchronous `startTransition` (see `client/react-root.ts`). A transition\n * update keeps the committed tree on screen while the incoming one resolves,\n * instead of replacing it with a Suspense fallback — the reason this\n * component exists (TIM-1306).\n *\n * It used to hold the tree in `useState` and register `setState` closures\n * into module globals during render so the router could reach into it, with a\n * second set of stand-in closures for the window before a root existed\n * (TIM-600). Inverting that — router calls React, not the reverse — deleted\n * all of it (TIM-1431). Next.js's `use-action-queue.ts` says it wants this\n * shape and cannot have it because it must decode Flight during render;\n * timber decodes in `router-pipeline.ts`, so nothing stands in the way.\n *\n * What this component does own is **the commit-time publish**: a navigation's\n * state (segment cache, address bar, history stack, pathname) is published\n * from a layout effect keyed on the tree object, so the event that puts a\n * route on screen is the event that makes it current (TIM-1301). Props work\n * for that exactly as state did.\n *\n * This component holds no pending state. The `TopLoader` it renders and the\n * public `usePendingNavigation()` both subscribe to the router's external\n * pending store; NavigationRoot's own `pendingUrl` was a second, unread\n * representation of the same fact and is gone (TIM-1307).\n *\n * Hard navigation guard: When a hard navigation is triggered (500 error,\n * version skew), the component throws an unresolved thenable AFTER all\n * hooks to suspend forever — preventing React from rendering children\n * during page teardown. The throw must come after hooks to satisfy\n * React's rules (same hook count every render) while still preventing\n * child renders that could hit hook count mismatches in components\n * whose positions shift during teardown. This pattern is borrowed from\n * Next.js (app-router.tsx pushRef.mpaNavigation — also after hooks).\n *\n * See design/05-streaming.md §\"deferSuspenseFor\"\n * See design/19-client-navigation.md §\"NavigationContext\"\n */\n\nimport { createElement, Fragment, useLayoutEffect, useRef, type ReactNode } from 'react';\nimport { TopLoader, type TopLoaderConfig } from './top-loader.tsx';\n\n// ─── Rendered Tree ──────────────────────────────────────────────\n\n/**\n * The tree the router has handed to React, and the state publish that belongs\n * to it. They travel as one object so React's commit of the tree is the event\n * that publishes — see the effect in NavigationRoot. Every `render` builds a\n * fresh one, which is what keys that effect: a tree is published once, however\n * many times React re-runs the effect for it.\n */\nexport interface RenderedTree {\n element: ReactNode;\n /**\n * Publishes the navigation's state — segment cache, pathname, address bar,\n * history stack, and the client's record of the mounted tree — and\n * announces it to listeners outside React. Runs when React commits\n * `element`, never before (TIM-1301). Null for a render that has nothing to\n * publish on commit (hydration, the shallow search re-wrap).\n */\n publish: (() => void) | null;\n}\n\n/**\n * Hand a tree to React in a transition. `publish` runs when React commits it.\n *\n * Every path that puts a page on screen goes through one of these — a\n * navigation, a revalidation, a popstate replay, a shallow search re-wrap —\n * and it is always a synchronous `startTransition` around `root.render`.\n * The production one is `createReactRoot().render`.\n *\n * `types` are the view transition types this render animates as\n * (design/37-navigation-api.md §\"Transition types\"). They are added with\n * `addTransitionType` inside that same `startTransition`, and nowhere else:\n * React queues types per root and hands them to the next transition-only\n * commit, so a type added in any other scope describes whichever tree commits\n * next rather than this one (TIM-1463, TIM-1471). Empty for the shallow search\n * re-wrap, which re-renders the displayed page rather than changing it.\n */\nexport type NavigationRender = (\n element: ReactNode,\n publish: (() => void) | null,\n types: readonly string[]\n) => void;\n\n// ─── Hard Navigation Guard ──────────────────────────────────────\n\n/**\n * Module-level flag indicating a hard (MPA) navigation is in progress.\n *\n * When true:\n * - NavigationRoot throws an unresolved thenable to suspend forever,\n * preventing React from rendering children during page teardown\n * (avoids \"Rendered more hooks\" crashes).\n * - The Navigation API handler skips interception, letting the browser\n * perform a full page load (prevents infinite loops where\n * window.location.href → navigate event → router.navigate → 500 →\n * window.location.href → ...).\n *\n * Uses globalThis for singleton guarantee across chunks (same pattern\n * as NavigationContext). See design/19-client-navigation.md §\"Singleton\n * Guarantee via globalThis\".\n */\nconst HARD_NAV_KEY = Symbol.for('__timber_hard_navigating');\n\nfunction getHardNavStore(): { value: boolean } {\n const g = globalThis as Record<symbol, unknown>;\n if (!g[HARD_NAV_KEY]) {\n g[HARD_NAV_KEY] = { value: false };\n }\n return g[HARD_NAV_KEY] as { value: boolean };\n}\n\n/**\n * Set the hard-navigating flag. Call this BEFORE setting\n * window.location.href or window.location.reload() to prevent:\n * 1. React from rendering children during page teardown\n * 2. Navigation API from intercepting the hard navigation\n */\nexport function setHardNavigating(value: boolean): void {\n getHardNavStore().value = value;\n}\n\n/**\n * Check if a hard navigation is in progress.\n * Used by NavigationRoot (throw unresolvedThenable) and by the\n * Navigation API handler (skip interception).\n */\nexport function isHardNavigating(): boolean {\n return getHardNavStore().value;\n}\n\n/**\n * A thenable that never resolves. When thrown during React render,\n * it causes the component to suspend forever — React keeps the\n * old committed tree visible and never attempts to render children.\n *\n * This is the same pattern Next.js uses in app-router.tsx for MPA\n * navigations (pushRef.mpaNavigation → throw unresolvedThenable).\n */\n// for React's Suspense mechanism. Same pattern as Next.js's unresolvedThenable.\n// eslint-disable-next-line unicorn/no-thenable -- Intentionally a never-resolving thenable\nconst unresolvedThenable = { then() {} } as PromiseLike<never>;\n\n// ─── Component ───────────────────────────────────────────────────\n\n/**\n * Root component the router renders the page through.\n *\n * Renders the TopLoader alongside the tree it is given. Neither adds a DOM\n * element on the hydration path, so the tree matches the server HTML.\n *\n * Rendered only by `createReactRoot` (client/react-root.ts): hydration passes\n * `{ element, publish: null }`, and every later render is a synchronous\n * `startTransition(() => root.render(...))` with a fresh `rendered` object.\n */\nexport function NavigationRoot({\n rendered,\n topLoaderConfig,\n}: {\n rendered: RenderedTree;\n topLoaderConfig?: TopLoaderConfig;\n}): ReactNode {\n // Publish the navigation's state when React commits its tree — not when the\n // tree is handed over. A tree React is still waiting on, or one a later\n // navigation replaces before React renders it, has been *given* to React\n // without being on screen; publishing then describes a route the user never\n // saw, which is the defect this ordering exists to prevent (TIM-1301).\n //\n // A **layout** effect, so the publish lands before the browser paints and,\n // more importantly, before every descendant's passive effect. A destination\n // component that navigates from a mount effect — a redirect guard, a\n // `refresh()` on mount — would otherwise start its navigation while the\n // segment cache, address bar and pathname still described the departing\n // route, and send an X-Timber-State-Tree for a tree that is no longer\n // mounted (codex on #998).\n //\n // Descendant *layout* effects still run first: React runs layout effects\n // child-before-parent, and the only way to precede them would be a fiber\n // rendered as an earlier sibling of the payload. That is not free here —\n // `server/ssr-wrappers.tsx` mirrors this component's fiber shape so `useId`\n // agrees across hydration, and an extra sibling shifts every id in the\n // payload subtree. A layout effect that navigates on mount is the price.\n //\n // Keyed on the tree object rather than on the effect run. A publish moves\n // the address bar, which is not idempotent, so any second invocation for the\n // same tree — an effect re-run React is entitled to perform, StrictMode's\n // double-invoke — must be a no-op rather than a second history entry.\n const publishedRef = useRef<RenderedTree | null>(null);\n useLayoutEffect(() => {\n if (publishedRef.current === rendered) return;\n publishedRef.current = rendered;\n rendered.publish?.();\n }, [rendered]);\n\n // ─── Hard navigation guard ─────────────────────────────────\n // When a hard navigation is in progress (500 error, version skew),\n // suspend forever to prevent React from rendering children during\n // page teardown. This avoids \"Rendered more hooks\" crashes in\n // CHILD components whose hook counts may shift during teardown.\n //\n // CRITICAL: This throw MUST come AFTER all hooks (the useRef and\n // useLayoutEffect above). React requires the same hooks to run on every\n // render. If we threw before hooks, React would see 0 hooks on the\n // re-render vs 2 on the initial render — triggering the exact \"Rendered\n // more hooks\" error we're trying to prevent.\n //\n // By placing it after hooks but before the return, all hooks\n // satisfy React's rules, but the thrown thenable prevents any\n // children from rendering. Same pattern as Next.js app-router.tsx\n // (pushRef.mpaNavigation — also placed after all hooks).\n if (isHardNavigating()) {\n throw unresolvedThenable;\n }\n\n // Inject TopLoader alongside the element tree. It subscribes to the router's\n // pending store itself, so it takes no props from here beyond its config,\n // and only it re-renders when a navigation starts or ends. Its slot holds\n // `null` when the loader is disabled via config.\n //\n // This Fragment is a FORK — two children — so it advances React's tree\n // context and shifts every `useId` below it. `server/ssr-wrappers.tsx`\n // mirrors it for exactly that reason, and renders the document's default\n // <meta> tags in the first slot. The fork is unconditional so the server\n // never needs to know whether the loader is enabled: a `null` child still\n // counts toward the fork on both sides. See tests/ssr-wrapper-parity.test.ts.\n const showTopLoader = topLoaderConfig?.enabled !== false;\n return createElement(\n Fragment,\n null,\n showTopLoader ? createElement(TopLoader, { config: topLoaderConfig }) : null,\n rendered.element\n );\n}\n"],"mappings":";;;;AA0BA,IAAW,eAAsC;AAEjD,SAAgB,iBAAiB,QAAqC;CACpE,eAAe;AACjB;;AAKA,IAAW,eAAe;AAC1B,IAAW,qBAAqB,IAAI,gBAAgB;AAEpD,SAAgB,iBAAiB,QAAgB,QAA+B;CAC9E,eAAe;CACf,qBAAqB;AACvB;;AAKA,IAAW,YAAY;AAEvB,SAAgB,cAAc,OAAsB;CAClD,YAAY;AACd;;;;;;;AAUA,IAAW,qBAAqB;AAEhC,SAAgB,uBAAuB,OAAsB;CAC3D,qBAAqB;AACvB;;;;;;;AAQA,IAAW;AAEX,SAAgB,yBAAyB,SAAyC;CAChF,uBAAuB;AACzB;;;;;AC9DA,SAAgB,gBAAgB,QAA8B;CAC5D,iBAAiB,MAAM;AACzB;;;;;AAMA,SAAgB,YAA4B;CAC1C,IAAI,CAAC,cACH,MAAM,IAAI,MAAM,6EAA6E;CAE/F,OAAO;AACT;;;;;;AAOA,SAAgB,kBAAyC;CACvD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACqDA,SAAgB,qBAAsE;CACpF,OAAO,oBAA4C,OAAO,IAAI,kBAAkB,GAAG,IAAI;AACzF;;;;;;;AAQA,SAAgB,uBAA+C;CAC7D,OAAO,WAAW,mBAAmB,CAAC;AACxC;;;;;;;AAiBA,SAAgB,mBAAmB,EACjC,OACA,YACwD;CACxD,OAAO,cAAc,mBAAmB,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACjHA,IAAM,OAAO;;;;;;;;AASb,SAAgB,eAAe,KAAkB;CAC/C,OAAO,IAAI,WAAW,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI;AACtE;;;;;;AAOA,SAAgB,aAAa,KAAqB;CAChD,MAAM,SAAS,eAAe,GAAG;CACjC,OAAO,OAAO,WAAW,OAAO;AAClC;;AC1BA,SAAS,UAAU,eAAuC;CACxD,MAAM,SAAS,gBAAgB;CAC/B,IAAI,CAAC,QAAQ,aAAa,CAAC;CAC3B,OAAO,OAAO,gBAAgB,aAAa;AAC7C;AAEA,SAAS,YAAqB;CAC5B,MAAM,SAAS,gBAAgB;CAC/B,OAAO,SAAS,OAAO,UAAU,IAAI;AACvC;AAEA,IAAM,aAAa;;;;;;AAOnB,SAAS,QAAQ,KAAkB;CACjC,MAAM,SAAS,eAAe,GAAG;CACjC,IAAI,WAAW,KAAK,GAAG,GAAG,OAAO;CACjC,OAAO,IAAI,IAAI,OAAO,SAAS,SAAS,OAAO,WAAW,OAAO,SAAS,OAAO,IAAI;AACvF;AAiDA,SAAgB,qBAAwB,QAAoD;CAG1F,MAAM,MAAM,SAAS,IAAI,mBAAmB,CAAC,IAAI;CACjD,IAAI,UAAU,QAAQ,MACpB,MAAM,IAAI,MACR,yKAGF;CAEF,MAAM,WAAW,MAAM,IAAI,WAAW,IAAI,SAAS;CAOnD,MAAM,YAAY,OAAgD,IAAI;CAEtE,MAAM,cAAc,cAAmC;EACrD,IAAI,CAAC,UAAU,aAAa,MAAM,OAAO;EAGzC,IAAI,OAA0D;EAC9D,aAAa;GACX,MAAM,SAAS,gBAAgB,CAAC,EAAE,cAAc,KAAK;GACrD,IAAI,WAAW,MAAM;IACnB,UAAU,UAAU;IACpB,OAAO;GACT;GACA,IAAI,UAAU,SAAS,WAAW,QAAQ,UAAU,UAAU;IAAE;IAAQ,MAAM;GAAS;GACvF,MAAM,OAAO,UAAU,QAAQ;GAC/B,IAAI,MAAM,WAAW,UAAU,KAAK,SAAS,MAC3C,OAAO;IAAE;IAAQ;IAAM,OAAO,OAAO,QAAQ,MAAM,GAAG,QAAQ,IAAI,CAAC;GAAE;GAEvE,OAAO,KAAK;EACd;CACF,GAAG,CAAC,QAAQ,QAAQ,CAAC;CAGrB,OAAO,qBAAqB,WAAW,aAAa,WAAW;AACjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACZA,IAAM,eAAe,OAAO,IAAI,0BAA0B;AAE1D,SAAS,kBAAsC;CAC7C,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,eACL,EAAE,gBAAgB,EAAE,OAAO,MAAM;CAEnC,OAAO,EAAE;AACX;;;;;;;AAQA,SAAgB,kBAAkB,OAAsB;CACtD,gBAAgB,CAAC,CAAC,QAAQ;AAC5B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { t as createGlobalContext } from "./global-context-DbxNWeBP.js";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
// src/client/ssr-data.ts
|
|
4
|
+
/**
|
|
5
|
+
* SSR Data — the request values client code reads while rendering on the server.
|
|
6
|
+
*
|
|
7
|
+
* `useCookie()` and `<Link preserveSearchParams>` have no other way to see the
|
|
8
|
+
* request's cookies and search string during SSR, so the SSR wrapper chain
|
|
9
|
+
* (server/ssr-wrappers.tsx) provides them here. `useSearchParams()` reads
|
|
10
|
+
* NavigationContext and checks this context only to tell that it is
|
|
11
|
+
* rendering on the server. Route params travel in `ParamsContext`, decoded
|
|
12
|
+
* from the payload root.
|
|
13
|
+
*
|
|
14
|
+
* Link reads the search string here rather than from NavigationContext
|
|
15
|
+
* because this context never changes in the browser: subscribing every Link
|
|
16
|
+
* to NavigationContext would re-render all of them on each navigation.
|
|
17
|
+
* wrapSsrElement fills both from the same `search` option.
|
|
18
|
+
*
|
|
19
|
+
* Why a React context, not AsyncLocalStorage: Fizz resumes a suspended
|
|
20
|
+
* subtree (an async layout, a lazy Flight row) from whatever callback
|
|
21
|
+
* resolved it. On Node that is a `data` event of the Flight stream, which
|
|
22
|
+
* runs in the async context of the RSC render that produced the chunk, not
|
|
23
|
+
* the SSR request's. An ALS store set around `handleSsr` was gone there, so
|
|
24
|
+
* every cookie read below the first streamed chunk came back empty. A
|
|
25
|
+
* context value is part of the request's element tree: React restores it
|
|
26
|
+
* wherever it resumes the tree, and concurrent requests cannot see each
|
|
27
|
+
* other's.
|
|
28
|
+
*
|
|
29
|
+
* In the browser no provider is mounted and `useSsrData()` returns null.
|
|
30
|
+
*
|
|
31
|
+
* IMPORTANT: This module is imported by 'use client' hooks bundled for the
|
|
32
|
+
* browser. It must not import node:async_hooks or other Node-only APIs.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* On globalThis (by Symbol.for key) so a module duplicated across chunks
|
|
36
|
+
* still yields one context per React instance — see global-context.ts.
|
|
37
|
+
*/
|
|
38
|
+
function getSsrDataContext() {
|
|
39
|
+
return createGlobalContext(Symbol.for("__timber_ssr_data_ctx"), null);
|
|
40
|
+
}
|
|
41
|
+
/** The current request's SSR data, or null outside a server render. */
|
|
42
|
+
function useSsrData() {
|
|
43
|
+
return React$1.useContext(getSsrDataContext());
|
|
44
|
+
}
|
|
45
|
+
export { useSsrData as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=ssr-data-BfsCqCLl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-data-BfsCqCLl.js","names":["React"],"sources":["../../src/client/ssr-data.ts"],"sourcesContent":["/**\n * SSR Data — the request values client code reads while rendering on the server.\n *\n * `useCookie()` and `<Link preserveSearchParams>` have no other way to see the\n * request's cookies and search string during SSR, so the SSR wrapper chain\n * (server/ssr-wrappers.tsx) provides them here. `useSearchParams()` reads\n * NavigationContext and checks this context only to tell that it is\n * rendering on the server. Route params travel in `ParamsContext`, decoded\n * from the payload root.\n *\n * Link reads the search string here rather than from NavigationContext\n * because this context never changes in the browser: subscribing every Link\n * to NavigationContext would re-render all of them on each navigation.\n * wrapSsrElement fills both from the same `search` option.\n *\n * Why a React context, not AsyncLocalStorage: Fizz resumes a suspended\n * subtree (an async layout, a lazy Flight row) from whatever callback\n * resolved it. On Node that is a `data` event of the Flight stream, which\n * runs in the async context of the RSC render that produced the chunk, not\n * the SSR request's. An ALS store set around `handleSsr` was gone there, so\n * every cookie read below the first streamed chunk came back empty. A\n * context value is part of the request's element tree: React restores it\n * wherever it resumes the tree, and concurrent requests cannot see each\n * other's.\n *\n * In the browser no provider is mounted and `useSsrData()` returns null.\n *\n * IMPORTANT: This module is imported by 'use client' hooks bundled for the\n * browser. It must not import node:async_hooks or other Node-only APIs.\n */\n\n// A namespace import, as use-cookie.ts does: `defineCookie` pulls this module\n// into the RSC environment, whose React build exports no `useContext`, and a\n// named import of it fails to link there. Nothing here runs in RSC.\nimport * as React from 'react';\nimport { createGlobalContext } from './global-context.ts';\n\nexport interface SsrData {\n /**\n * The request's raw app-visible query string (`''` or `?…`), matching what\n * `window.location.search` will hold after hydration. Raw, so repeated keys\n * (`?tag=a&tag=b`) survive (TIM-1428).\n */\n search: string;\n /** The request's cookies as name→value pairs */\n cookies: ReadonlyMap<string, string>;\n}\n\n/**\n * On globalThis (by Symbol.for key) so a module duplicated across chunks\n * still yields one context per React instance — see global-context.ts.\n */\nfunction getSsrDataContext(): React.Context<SsrData | null> {\n return createGlobalContext<SsrData | null>(Symbol.for('__timber_ssr_data_ctx'), null);\n}\n\n/** The current request's SSR data, or null outside a server render. */\nexport function useSsrData(): SsrData | null {\n return React.useContext(getSsrDataContext());\n}\n\n/** Provides the request's SSR data to the tree. Mounted by wrapSsrElement only. */\nexport function SsrDataProvider({\n value,\n children,\n}: {\n value: SsrData;\n children?: React.ReactNode;\n}): React.ReactElement {\n return React.createElement(getSsrDataContext().Provider, { value }, children);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAS,oBAAmD;CAC1D,OAAO,oBAAoC,OAAO,IAAI,uBAAuB,GAAG,IAAI;AACtF;;AAGA,SAAgB,aAA6B;CAC3C,OAAOA,QAAM,WAAW,kBAAkB,CAAC;AAC7C"}
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* they are the router's, and hydration makes the page current through
|
|
11
11
|
* `RouterInstance.hydrate` like any other commit (TIM-1541).
|
|
12
12
|
*
|
|
13
|
-
* See design/19-client-navigation.md §
|
|
13
|
+
* See design/19-client-navigation.md §'History Stack'
|
|
14
14
|
*/
|
|
15
15
|
import type { RouterInstance } from '#client-internal';
|
|
16
16
|
import type { NavigationApiController } from '../navigation-api.ts';
|
|
17
17
|
interface PostHydrationOptions {
|
|
18
|
-
router: RouterInstance
|
|
18
|
+
router: Pick<RouterInstance, 'handlePopState'>;
|
|
19
19
|
navApiController: NavigationApiController | null;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-hydration.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/post-hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,UAAU,oBAAoB;IAC5B,MAAM,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"post-hydration.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/post-hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,UAAU,oBAAoB;IAC5B,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAC/C,gBAAgB,EAAE,uBAAuB,GAAG,IAAI,CAAC;CAClD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,oBAAoB,GAAG,IAAI,CA2E3F"}
|
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
*
|
|
7
7
|
* See design/19-client-navigation.md §"Overflow Scroll Containers".
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* Scroll the element matching a URL #fragment into view.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors browser anchor behavior: looks up the decoded fragment by id,
|
|
13
|
+
* then by anchor name. Returns true when a matching element was found and
|
|
14
|
+
* scrolled; false otherwise (the router falls back to scroll-to-top, same
|
|
15
|
+
* as a full page load with an unknown fragment). See TIM-1035.
|
|
16
|
+
*/
|
|
17
|
+
export declare function scrollToHashTarget(hash: string): boolean;
|
|
9
18
|
/**
|
|
10
19
|
* Read the current scroll position.
|
|
11
20
|
*
|
|
@@ -14,15 +23,9 @@
|
|
|
14
23
|
* place via `cloneElement` — React preserves their DOM and scroll state
|
|
15
24
|
* naturally. We don't need to auto-detect overflow containers; only
|
|
16
25
|
* explicitly marked containers are tracked.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Scroll the element matching a URL #fragment into view.
|
|
20
26
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* scrolled; false otherwise (the router falls back to scroll-to-top, same
|
|
24
|
-
* as a full page load with an unknown fragment). See TIM-1035.
|
|
27
|
+
* Every read here forces a layout when styles are dirty, so callers must not
|
|
28
|
+
* run it synchronously during boot (see post-hydration.ts).
|
|
25
29
|
*/
|
|
26
|
-
export declare function scrollToHashTarget(hash: string): boolean;
|
|
27
30
|
export declare function getScrollY(): number;
|
|
28
31
|
//# sourceMappingURL=scroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/scroll.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH
|
|
1
|
+
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/scroll.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAaxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAQnC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { n as interpolateParams, r as resolveHref } from "../_chunks/href-8l5VD23D.js";
|
|
3
3
|
import { i as validateNavigationHref, n as isInternalHref } from "../_chunks/href-validation-DNg-zV7u.js";
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
4
|
+
import { c as getRouterOrNull, n as usePendingNavigation, o as useNavigationContext } from "../_chunks/navigation-root-AuCD35Sv.js";
|
|
5
|
+
import { t as useSsrData } from "../_chunks/ssr-data-BfsCqCLl.js";
|
|
6
6
|
import { n as resolveSegmentParams, t as mergePreservedSearchParams } from "../_chunks/merge-search-params-7o_5yX0L.js";
|
|
7
7
|
import { l as stripRscCacheKey } from "../_chunks/rsc-cache-key-BGvUtMtN.js";
|
|
8
8
|
import { n as useSegmentContext } from "../_chunks/segment-context-GAyTjjtS.js";
|
|
9
9
|
import "../_chunks/param-value-DqlGfF57.js";
|
|
10
|
+
import { t as createGlobalContext } from "../_chunks/global-context-DbxNWeBP.js";
|
|
10
11
|
import { n as useQueryStates } from "../_chunks/use-query-states-D3MMl-KM.js";
|
|
11
12
|
import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
12
13
|
import { flushSync } from "react-dom";
|
|
@@ -63,16 +64,17 @@ function locationSearch() {
|
|
|
63
64
|
var LINK_PENDING = { isPending: true };
|
|
64
65
|
var LINK_IDLE = { isPending: false };
|
|
65
66
|
/**
|
|
66
|
-
* Read the current URL's search string
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* Read the current URL's search string. During SSR, the request's raw query
|
|
68
|
+
* string from the SSR data context (passed in as `ssrSearch`); on the
|
|
69
|
+
* client, window.location.search. Both have the same `''` or
|
|
69
70
|
* `?…` shape, preserving repeated keys (`?tag=a&tag=b`) so the
|
|
70
71
|
* server-rendered href matches what the hydrated client rebuilds from the
|
|
71
72
|
* address bar (TIM-1428). Returns empty string if unavailable.
|
|
72
73
|
*/
|
|
73
|
-
function getCurrentSearch() {
|
|
74
|
+
function getCurrentSearch(ssrSearch) {
|
|
75
|
+
if (ssrSearch !== void 0) return ssrSearch;
|
|
74
76
|
if (typeof window !== "undefined") return locationSearch();
|
|
75
|
-
return
|
|
77
|
+
return "";
|
|
76
78
|
}
|
|
77
79
|
/** Native in-page scrolling needs neither an RSC navigation nor a prefetch. */
|
|
78
80
|
function isNativeFragmentLink(anchor) {
|
|
@@ -137,9 +139,10 @@ var Link = function LinkImpl(props) {
|
|
|
137
139
|
const [isPending, setIsPending] = useState(false);
|
|
138
140
|
const clickSeq = useRef(0);
|
|
139
141
|
const linkStatus = isPending ? LINK_PENDING : LINK_IDLE;
|
|
142
|
+
const ssrSearch = useSsrData()?.search;
|
|
140
143
|
const internal = isInternalHref(baseHref);
|
|
141
|
-
const resolvedHref = preserveSearchParams && internal ? mergePreservedSearchParams(baseHref, getCurrentSearch(), preserveSearchParams) : baseHref;
|
|
142
|
-
const resolveEventUrl = () => new URL(preserveSearchParams ? mergePreservedSearchParams(baseHref, getCurrentSearch(), preserveSearchParams) : resolvedHref, window.location.href);
|
|
144
|
+
const resolvedHref = preserveSearchParams && internal ? mergePreservedSearchParams(baseHref, getCurrentSearch(ssrSearch), preserveSearchParams) : baseHref;
|
|
145
|
+
const resolveEventUrl = () => new URL(preserveSearchParams ? mergePreservedSearchParams(baseHref, getCurrentSearch(ssrSearch), preserveSearchParams) : resolvedHref, window.location.href);
|
|
143
146
|
const handleClick = internal ? (event) => {
|
|
144
147
|
userOnClick?.(event);
|
|
145
148
|
if (!shouldInterceptClick(event, resolvedHref)) return;
|