@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
package/src/client/state.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Centralized client singleton state registry.
|
|
3
3
|
*
|
|
4
4
|
* ALL mutable module-level state that must have singleton semantics across
|
|
5
|
-
* the client bundle lives here. Individual modules (router-ref.ts,
|
|
5
|
+
* the client bundle lives here. Individual modules (router-ref.ts,
|
|
6
6
|
* use-segment-params.ts, use-search-params.ts, unload-guard.ts) import from this file
|
|
7
7
|
* and re-export thin wrapper functions.
|
|
8
8
|
*
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { RouterInstance } from './router-types.ts';
|
|
23
|
-
import type { SsrData } from './ssr-data.ts';
|
|
24
23
|
|
|
25
24
|
// ─── Router (from router-ref.ts) ──────────────────────────────────────────
|
|
26
25
|
|
|
@@ -31,18 +30,6 @@ export function _setGlobalRouter(router: RouterInstance | null): void {
|
|
|
31
30
|
globalRouter = router;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
// ─── SSR Data Provider (from ssr-data.ts) ──────────────────────────────────
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* ALS-backed SSR data provider, registered by the SSR entry. getSsrData()
|
|
38
|
-
* reads through it; unset in the browser.
|
|
39
|
-
*/
|
|
40
|
-
export let ssrDataProvider: (() => SsrData | undefined) | undefined;
|
|
41
|
-
|
|
42
|
-
export function _setSsrDataProvider(provider: (() => SsrData | undefined) | undefined): void {
|
|
43
|
-
ssrDataProvider = provider;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
33
|
// ─── Search Params Cache (from use-search-params.ts) ────────────────────────
|
|
47
34
|
|
|
48
35
|
/** Cached search string — avoids reparsing when URL hasn't changed. */
|
package/src/client/use-cookie.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// code runs. Same rule as `client/params-context.ts` (TIM-1297, TIM-1298).
|
|
18
18
|
import * as React from 'react';
|
|
19
19
|
import { parseCookie, stringifySetCookie } from 'cookie';
|
|
20
|
-
import {
|
|
20
|
+
import { useSsrData } from './ssr-data.ts';
|
|
21
21
|
import { assertValidCookieName } from '../cookies/validation.ts';
|
|
22
22
|
|
|
23
23
|
// ─── Types ────────────────────────────────────────────────────────────────
|
|
@@ -148,10 +148,11 @@ export function useCookie(
|
|
|
148
148
|
};
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
+
// The request cookies during SSR (provided by the SSR wrapper chain), null
|
|
152
|
+
// in the browser.
|
|
153
|
+
const ssrData = useSsrData();
|
|
151
154
|
const getSnapshot = (): string | undefined => getCookieValue(name);
|
|
152
155
|
const getServerSnapshot = (): string | undefined => {
|
|
153
|
-
// During SSR, read the ALS-backed request cookies.
|
|
154
|
-
const ssrData = getSsrData();
|
|
155
156
|
if (ssrData) return ssrData.cookies.get(name);
|
|
156
157
|
// During client hydration there is no SSR data (it lives in the server's
|
|
157
158
|
// module graph), but React still calls getServerSnapshot. document.cookie
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Compatible with Next.js's `useSearchParams()` from `next/navigation`.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import {
|
|
27
|
+
import { useSsrData } from './ssr-data.ts';
|
|
28
28
|
import { useNavigationContext } from './navigation-context.ts';
|
|
29
29
|
import { cachedSearch, cachedSearchParams, _setCachedSearch } from './state.ts';
|
|
30
30
|
|
|
@@ -46,6 +46,7 @@ function getSearchParams(search: string): URLSearchParams {
|
|
|
46
46
|
*/
|
|
47
47
|
export function useSearchParams(): URLSearchParams {
|
|
48
48
|
const nav = useNavigationContext();
|
|
49
|
+
const ssrData = useSsrData();
|
|
49
50
|
if (nav === null) {
|
|
50
51
|
throw new Error(
|
|
51
52
|
'[timber] useSearchParams() was called outside the timber app tree ' +
|
|
@@ -58,9 +59,9 @@ export function useSearchParams(): URLSearchParams {
|
|
|
58
59
|
// server it would be shared mutable state across concurrent requests
|
|
59
60
|
// (design/13-security.md, "no global fallback state"). Both halves of the
|
|
60
61
|
// check matter: `window` is absent in a plain Node SSR render, and
|
|
61
|
-
//
|
|
62
|
-
// always
|
|
63
|
-
if (typeof window === 'undefined' ||
|
|
62
|
+
// the SSR data context catches SSR environments that do define `window`
|
|
63
|
+
// (wrapSsrElement always provides it). Pinned by tests/ssr-provider-hooks.test.ts.
|
|
64
|
+
if (typeof window === 'undefined' || ssrData) {
|
|
64
65
|
return new URLSearchParams(nav.search);
|
|
65
66
|
}
|
|
66
67
|
return getSearchParams(nav.search);
|
|
@@ -173,13 +173,3 @@ export function collectRouteModulepreloads(
|
|
|
173
173
|
|
|
174
174
|
return result;
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Generate <link rel="modulepreload"> tags for JS dependency URLs.
|
|
179
|
-
*
|
|
180
|
-
* Modulepreload hints tell the browser to fetch and parse JS modules
|
|
181
|
-
* before they're needed, reducing waterfall latency for dynamic imports.
|
|
182
|
-
*/
|
|
183
|
-
export function buildModulepreloadTags(urls: string[]): string {
|
|
184
|
-
return urls.map((url) => `<link rel="modulepreload" href="${url}">`).join('');
|
|
185
|
-
}
|
|
@@ -303,13 +303,14 @@ export function injectRscPayload(
|
|
|
303
303
|
* Suspense boundaries are still streaming. Uses dynamic `import()` to kick off
|
|
304
304
|
* module loading, enabling hydration to start before the stream closes.
|
|
305
305
|
*
|
|
306
|
-
* - `
|
|
307
|
-
*
|
|
308
|
-
*
|
|
306
|
+
* - `modulePreloads`: hashed URLs of the browser entry's production dependencies.
|
|
307
|
+
* SSR hands them to React as `preloadModule()` calls (ssr-wrappers.tsx), so
|
|
308
|
+
* Fizz writes one `<link rel="modulepreload">` per chunk — deduplicated
|
|
309
|
+
* against the client-reference preloads plugin-rsc issues for the same chunks.
|
|
309
310
|
*/
|
|
310
311
|
export interface ClientBootstrapConfig {
|
|
311
312
|
bootstrapScriptContent: string;
|
|
312
|
-
|
|
313
|
+
modulePreloads: string[];
|
|
313
314
|
}
|
|
314
315
|
|
|
315
316
|
/** Find a manifest entry by matching the key suffix (e.g. 'client/browser-entry/index.ts'). */
|
|
@@ -368,10 +369,10 @@ export function buildClientScripts(runtimeConfig: {
|
|
|
368
369
|
if (runtimeConfig.dev && needsViteClient) {
|
|
369
370
|
return {
|
|
370
371
|
bootstrapScriptContent: 'import("/@vite/client")',
|
|
371
|
-
|
|
372
|
+
modulePreloads: [],
|
|
372
373
|
};
|
|
373
374
|
}
|
|
374
|
-
return { bootstrapScriptContent: '',
|
|
375
|
+
return { bootstrapScriptContent: '', modulePreloads: [] };
|
|
375
376
|
}
|
|
376
377
|
|
|
377
378
|
if (runtimeConfig.dev) {
|
|
@@ -391,7 +392,7 @@ export function buildClientScripts(runtimeConfig: {
|
|
|
391
392
|
return {
|
|
392
393
|
bootstrapScriptContent:
|
|
393
394
|
'import("/@vite/client");import("/@id/__x00__virtual:vite-rsc/entry-browser")',
|
|
394
|
-
|
|
395
|
+
modulePreloads: [],
|
|
395
396
|
};
|
|
396
397
|
}
|
|
397
398
|
|
|
@@ -404,23 +405,20 @@ export function buildClientScripts(runtimeConfig: {
|
|
|
404
405
|
? findManifestEntry(manifest.js, 'client/browser-entry/index.ts')
|
|
405
406
|
: undefined;
|
|
406
407
|
|
|
407
|
-
let
|
|
408
|
+
let modulePreloads: string[] = [];
|
|
408
409
|
let bootstrapScriptContent: string;
|
|
409
410
|
|
|
410
411
|
if (browserEntryUrl) {
|
|
411
412
|
// Modulepreload hints for browser entry dependencies
|
|
412
|
-
|
|
413
|
+
modulePreloads =
|
|
413
414
|
(manifest
|
|
414
415
|
? findManifestEntryArray(manifest.modulepreload, 'client/browser-entry/index.ts')
|
|
415
416
|
: undefined) ?? [];
|
|
416
|
-
for (const url of preloads) {
|
|
417
|
-
preloadLinks += `<link rel="modulepreload" href="${url}">`;
|
|
418
|
-
}
|
|
419
417
|
bootstrapScriptContent = `import("${browserEntryUrl}")`;
|
|
420
418
|
} else {
|
|
421
419
|
// Fallback: no manifest entry (e.g. manifest not yet populated)
|
|
422
420
|
bootstrapScriptContent = 'import("/virtual:timber-browser-entry")';
|
|
423
421
|
}
|
|
424
422
|
|
|
425
|
-
return { bootstrapScriptContent,
|
|
423
|
+
return { bootstrapScriptContent, modulePreloads };
|
|
426
424
|
}
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
import type { BuildManifest } from '../build-manifest.ts';
|
|
21
21
|
import {
|
|
22
22
|
buildFontPreloadTags,
|
|
23
|
-
buildModulepreloadTags,
|
|
24
23
|
collectRouteFonts,
|
|
25
24
|
collectRouteModulepreloads,
|
|
26
25
|
} from '../build-manifest.ts';
|
|
@@ -183,13 +182,14 @@ export async function renderRoute(
|
|
|
183
182
|
// twice. The 103 / Link preload (early-hints.ts) is what gets CSS loading
|
|
184
183
|
// before the HTML arrives.
|
|
185
184
|
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
185
|
+
// The matched segments' JS chunks are not spliced as <link> strings either:
|
|
186
|
+
// SSR hands them to React's preloadModule() with the browser entry's
|
|
187
|
+
// (ssr-wrappers.tsx), because plugin-rsc preloads client-reference chunks
|
|
188
|
+
// through React too, and Fizz only deduplicates what React rendered.
|
|
189
|
+
// Skipped when client JavaScript is disabled — no JS to preload.
|
|
190
|
+
const routeModulePreloads = clientJsDisabled
|
|
191
|
+
? []
|
|
192
|
+
: collectRouteModulepreloads(segments, buildManifest);
|
|
193
193
|
|
|
194
194
|
// Metadata tags (<title>, <meta>, <link>) are now rendered as React
|
|
195
195
|
// elements in the route element tree — React 19 Float hoists them into
|
|
@@ -236,6 +236,7 @@ export async function renderRoute(
|
|
|
236
236
|
clientBootstrap,
|
|
237
237
|
clientJsDisabled,
|
|
238
238
|
headHtml,
|
|
239
|
+
routeModulePreloads,
|
|
239
240
|
deferSuspenseFor,
|
|
240
241
|
globalError,
|
|
241
242
|
formState,
|
|
@@ -96,6 +96,8 @@ interface SsrRenderOptions {
|
|
|
96
96
|
clientBootstrap: ClientBootstrapConfig;
|
|
97
97
|
clientJsDisabled: boolean;
|
|
98
98
|
headHtml: string;
|
|
99
|
+
/** The matched segments' JS chunks, preloaded after the browser entry's. */
|
|
100
|
+
routeModulePreloads: string[];
|
|
99
101
|
deferSuspenseFor: number;
|
|
100
102
|
/** Tier 2 global-error.tsx file, if present in app/. */
|
|
101
103
|
globalError?: GlobalErrorFile;
|
|
@@ -142,6 +144,7 @@ export async function renderSsrResponse(opts: SsrRenderOptions): Promise<Respons
|
|
|
142
144
|
clientBootstrap,
|
|
143
145
|
clientJsDisabled,
|
|
144
146
|
headHtml,
|
|
147
|
+
routeModulePreloads,
|
|
145
148
|
deferSuspenseFor,
|
|
146
149
|
globalError,
|
|
147
150
|
formState,
|
|
@@ -184,7 +187,6 @@ export async function renderSsrResponse(opts: SsrRenderOptions): Promise<Respons
|
|
|
184
187
|
responseHeaders,
|
|
185
188
|
headHtml:
|
|
186
189
|
headHtml +
|
|
187
|
-
clientBootstrap.preloadLinks +
|
|
188
190
|
// Initialize __timber_f in <head> so it exists before any streaming
|
|
189
191
|
// chunk scripts arrive in <body>. See flight-scripts.ts, LOCAL-415.
|
|
190
192
|
(clientJsDisabled ? '' : flightInitScript(nonce)),
|
|
@@ -193,6 +195,7 @@ export async function renderSsrResponse(opts: SsrRenderOptions): Promise<Respons
|
|
|
193
195
|
: () =>
|
|
194
196
|
`<script${nonceAttr(nonce)}>self.__timber_segments=${htmlEscapeJsonString(JSON.stringify(buildSegmentInfo(segments, layoutComponents, getFirstDeniedSegmentIndex())))}</script>`,
|
|
195
197
|
bootstrapScriptContent: clientBootstrap.bootstrapScriptContent,
|
|
198
|
+
modulePreloads: [...clientBootstrap.modulePreloads, ...routeModulePreloads],
|
|
196
199
|
nonce,
|
|
197
200
|
// Skip RSC inline stream when client JS is disabled — no client to hydrate.
|
|
198
201
|
rscStream: clientJsDisabled ? undefined : inlineStream,
|
|
@@ -82,6 +82,12 @@ export interface NavContext {
|
|
|
82
82
|
headHtml: string;
|
|
83
83
|
/** Inline JS for React's bootstrapScriptContent — kicks off module loading */
|
|
84
84
|
bootstrapScriptContent: string;
|
|
85
|
+
/**
|
|
86
|
+
* Hashed URLs of the browser entry's chunks to modulepreload. SSR issues
|
|
87
|
+
* them as React `preloadModule()` calls so Fizz deduplicates them against
|
|
88
|
+
* client-reference preloads (ssr-wrappers.tsx). Absent on fallback pages.
|
|
89
|
+
*/
|
|
90
|
+
modulePreloads?: readonly string[];
|
|
85
91
|
/**
|
|
86
92
|
* Request CSP nonce, generated when middleware read `ctx.nonce` for its
|
|
87
93
|
* `Content-Security-Policy` header (`getCspNonce()`). SSR passes it to
|