@timber-js/app 0.2.0-alpha.223 → 0.2.0-alpha.225
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-7dTXYJfu.js → actions-B1xSIv32.js} +2 -2
- package/dist/_chunks/{actions-7dTXYJfu.js.map → actions-B1xSIv32.js.map} +1 -1
- package/dist/_chunks/{cache-api-TDZ4hlDc.js → cache-api-DsSXA4Sp.js} +68 -47
- package/dist/_chunks/cache-api-DsSXA4Sp.js.map +1 -0
- package/dist/_chunks/{cli-check-Dv3f8d2j.js → cli-check-B33yhAPa.js} +2 -2
- package/dist/_chunks/{cli-check-Dv3f8d2j.js.map → cli-check-B33yhAPa.js.map} +1 -1
- package/dist/_chunks/cli-context-BPdyA7Fp.js +1 -0
- package/dist/_chunks/{cli-context-CbZp32SK.js → cli-context-CwTKMjVe.js} +10 -2
- package/dist/_chunks/cli-context-CwTKMjVe.js.map +1 -0
- package/dist/_chunks/{dev-server-C61GWpGg.js → dev-server-B7o4As0l.js} +15 -1
- package/dist/_chunks/dev-server-B7o4As0l.js.map +1 -0
- package/dist/_chunks/dev-server-hZzmbMvK.js +1 -0
- package/dist/_chunks/{error-boundary-DRQXGWCp.js → error-boundary-D3YyVVuP.js} +2 -2
- package/dist/_chunks/{error-boundary-DRQXGWCp.js.map → error-boundary-D3YyVVuP.js.map} +1 -1
- package/dist/_chunks/{singleflight-BChPMjwH.js → singleflight-CzoOVB9Y.js} +2 -3
- package/dist/_chunks/singleflight-CzoOVB9Y.js.map +1 -0
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js → status-page-marker-C8POawuF.js} +2 -2
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js.map → status-page-marker-C8POawuF.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts +0 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -1
- package/dist/adapters/cloudflare-kv-cache.js.map +1 -1
- package/dist/cache/index.d.ts +5 -5
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/redis-handler.d.ts +0 -1
- package/dist/cache/redis-handler.d.ts.map +1 -1
- package/dist/cache/singleflight.d.ts +12 -2
- package/dist/cache/singleflight.d.ts.map +1 -1
- package/dist/cache/stable-stringify.d.ts +6 -0
- package/dist/cache/stable-stringify.d.ts.map +1 -1
- package/dist/cache/tag-aware-handler.d.ts +0 -1
- package/dist/cache/tag-aware-handler.d.ts.map +1 -1
- package/dist/cache/timber-cache.d.ts +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cli-context.d.ts +8 -0
- package/dist/cli-context.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -3
- package/dist/cli.js.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/internal.js +3 -3
- package/dist/config-types.d.ts +18 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +545 -9
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-in-server-package-deps.d.ts +63 -0
- package/dist/plugins/client-in-server-package-deps.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports-defaults.d.ts +13 -0
- package/dist/plugins/optimize-package-imports-defaults.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports.d.ts +124 -0
- package/dist/plugins/optimize-package-imports.d.ts.map +1 -0
- package/dist/server/flight-injector-core.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +162 -33
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline-helpers.d.ts +5 -2
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/response-framing.d.ts +43 -0
- package/dist/server/response-framing.d.ts.map +1 -0
- package/docs/api/34-api-config.mdx +20 -0
- package/package.json +2 -2
- package/src/adapters/cloudflare-kv-cache.ts +1 -5
- package/src/cache/index.ts +7 -27
- package/src/cache/redis-handler.ts +1 -5
- package/src/cache/singleflight.ts +17 -5
- package/src/cache/stable-stringify.ts +53 -0
- package/src/cache/tag-aware-handler.ts +1 -5
- package/src/cache/timber-cache.ts +55 -52
- package/src/cli-context.ts +9 -0
- package/src/cli.ts +16 -0
- package/src/config-types.ts +18 -0
- package/src/config-validation.ts +20 -0
- package/src/index.ts +4 -0
- package/src/plugins/client-in-server-package-deps.ts +139 -0
- package/src/plugins/optimize-package-imports-defaults.ts +88 -0
- package/src/plugins/optimize-package-imports.ts +439 -0
- package/src/server/flight-injector-core.ts +13 -9
- package/src/server/pipeline-helpers.ts +9 -5
- package/src/server/pipeline.ts +7 -0
- package/src/server/prebuilt-runtime.ts +125 -121
- package/src/server/response-framing.ts +59 -0
- package/dist/_chunks/cache-api-TDZ4hlDc.js.map +0 -1
- package/dist/_chunks/cli-context-CbZp32SK.js.map +0 -1
- package/dist/_chunks/cli-context-n5hmkdla.js +0 -1
- package/dist/_chunks/dev-server-C61GWpGg.js.map +0 -1
- package/dist/_chunks/dev-server-CBvvM7Lr.js +0 -1
- package/dist/_chunks/singleflight-BChPMjwH.js.map +0 -1
|
@@ -95,10 +95,13 @@ import {
|
|
|
95
95
|
/** Default timeout for component re-renders (overridden by renderTimeoutMs). */
|
|
96
96
|
const DEFAULT_COMPONENT_TIMEOUT_MS = DEFAULT_RENDER_TIMEOUT_MS;
|
|
97
97
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Singleflight for component re-renders (inline and background) and dev
|
|
100
|
+
* captures. One instance for the process: replacing it at boot would drop
|
|
101
|
+
* every flight in progress and let a caller after the swap run a second
|
|
102
|
+
* execution beside one still writing. The timeout is passed per call.
|
|
103
|
+
*/
|
|
104
|
+
const componentSingleflight = createSingleflight();
|
|
102
105
|
let componentTimeoutMs = DEFAULT_COMPONENT_TIMEOUT_MS;
|
|
103
106
|
|
|
104
107
|
/**
|
|
@@ -107,7 +110,6 @@ let componentTimeoutMs = DEFAULT_COMPONENT_TIMEOUT_MS;
|
|
|
107
110
|
*/
|
|
108
111
|
export function setComponentRefreshTimeout(timeoutMs: number): void {
|
|
109
112
|
componentTimeoutMs = timeoutMs;
|
|
110
|
-
componentSingleflight = createSingleflight({ timeoutMs });
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
let warnedNoWaitUntil = false;
|
|
@@ -365,43 +367,68 @@ async function storeCapturedEntry(
|
|
|
365
367
|
);
|
|
366
368
|
}
|
|
367
369
|
|
|
370
|
+
/** A re-render of one component entry: what both re-render paths capture. */
|
|
371
|
+
interface Rerender {
|
|
372
|
+
id: string;
|
|
373
|
+
component: ServerComponent;
|
|
374
|
+
props: Record<string, unknown>;
|
|
375
|
+
cacheKey: string;
|
|
376
|
+
options: PrebuiltComponentOptions;
|
|
377
|
+
hasSeed: boolean;
|
|
378
|
+
}
|
|
379
|
+
|
|
368
380
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
381
|
+
* Capture flight bytes and store them in the overlay, coalesced into one
|
|
382
|
+
* flight per overlay key. The inline and the background (SWR) re-render
|
|
383
|
+
* share the flight key: two executions for one key could otherwise both
|
|
384
|
+
* store, the older, slower one landing last (TIM-1447). A caller joining
|
|
385
|
+
* a flight started by the other path gets its bytes, or its error.
|
|
386
|
+
*
|
|
387
|
+
* Keyed by the overlay key, which carries the dev namespace: a request
|
|
388
|
+
* after a save never joins a re-render of the pre-save code. `wrap` runs
|
|
389
|
+
* the work inside the flight body — the background path reports its
|
|
390
|
+
* failure there, once per flight.
|
|
371
391
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
cacheKey
|
|
377
|
-
options: PrebuiltComponentOptions,
|
|
378
|
-
hasSeed: boolean,
|
|
379
|
-
outcome: string
|
|
380
|
-
): Promise<{ element: unknown } | null> {
|
|
392
|
+
function rerenderFlight(
|
|
393
|
+
r: Rerender,
|
|
394
|
+
wrap?: (signal: AbortSignal, work: () => Promise<Uint8Array>) => Promise<Uint8Array>
|
|
395
|
+
): Promise<Uint8Array> {
|
|
396
|
+
const { id, component, props, cacheKey, options, hasSeed } = r;
|
|
381
397
|
const tags = resolveTags(options, props);
|
|
382
398
|
const oKey = overlayKey(id, cacheKey);
|
|
383
|
-
// Keyed by the overlay key, which carries the dev namespace: a request
|
|
384
|
-
// after a save never joins a re-render of the pre-save code.
|
|
385
399
|
const sfKey = `prebuilt:${oKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
400
|
+
return componentSingleflight.do(
|
|
401
|
+
sfKey,
|
|
402
|
+
(signal) => {
|
|
403
|
+
const startEpoch = currentInvalidationEpoch();
|
|
404
|
+
const work = async (): Promise<Uint8Array> => {
|
|
405
|
+
const captured = await captureComponentPayload(id, component, props, options);
|
|
406
|
+
// Skip the store if aborted (singleflight timeout) or if the
|
|
407
|
+
// key/tags were invalidated, or a dev save landed, while rendering.
|
|
408
|
+
if (
|
|
409
|
+
!signal.aborted &&
|
|
410
|
+
hasRuntimeLifetime(options) &&
|
|
411
|
+
mayStoreRerender(startEpoch, id, cacheKey, oKey, tags)
|
|
412
|
+
) {
|
|
413
|
+
await storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed);
|
|
414
|
+
}
|
|
415
|
+
return captured.bytes;
|
|
416
|
+
};
|
|
417
|
+
return wrap ? wrap(signal, work) : work();
|
|
418
|
+
},
|
|
419
|
+
componentTimeoutMs
|
|
420
|
+
);
|
|
421
|
+
}
|
|
386
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Inline re-render: capture (or join the flight capturing) the entry, and
|
|
425
|
+
* revive it for the current request.
|
|
426
|
+
*/
|
|
427
|
+
async function inlineRerender(r: Rerender, outcome: string): Promise<{ element: unknown } | null> {
|
|
387
428
|
try {
|
|
388
|
-
|
|
389
|
-
const startEpoch = currentInvalidationEpoch();
|
|
390
|
-
const captured = await captureComponentPayload(id, component, props, options);
|
|
391
|
-
// Skip the store if aborted (singleflight timeout) or if the
|
|
392
|
-
// key/tags were invalidated, or a dev save landed, while rendering.
|
|
393
|
-
if (
|
|
394
|
-
!signal.aborted &&
|
|
395
|
-
hasRuntimeLifetime(options) &&
|
|
396
|
-
mayStoreRerender(startEpoch, id, cacheKey, oKey, tags)
|
|
397
|
-
) {
|
|
398
|
-
await storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed);
|
|
399
|
-
}
|
|
400
|
-
return captured.bytes;
|
|
401
|
-
});
|
|
402
|
-
return await revivePayload(id, payload, outcome);
|
|
429
|
+
return await revivePayload(r.id, await rerenderFlight(r), outcome);
|
|
403
430
|
} catch (error) {
|
|
404
|
-
console.error(`[timber] cache.component re-render failed for "${id}" — ${outcome}:`, error);
|
|
431
|
+
console.error(`[timber] cache.component re-render failed for "${r.id}" — ${outcome}:`, error);
|
|
405
432
|
return null;
|
|
406
433
|
}
|
|
407
434
|
}
|
|
@@ -432,44 +459,20 @@ function snapshotRequestContext(store: RequestContextStore): RequestContextStore
|
|
|
432
459
|
* Kick off a background re-render via waitUntil. The re-render runs inside
|
|
433
460
|
* a fresh ALS scope with snapshotted request context.
|
|
434
461
|
*/
|
|
435
|
-
function backgroundRerender(
|
|
436
|
-
id: string,
|
|
437
|
-
component: ServerComponent,
|
|
438
|
-
props: Record<string, unknown>,
|
|
439
|
-
cacheKey: string,
|
|
440
|
-
options: PrebuiltComponentOptions,
|
|
441
|
-
hasSeed: boolean,
|
|
442
|
-
snapshot: RequestContextStore
|
|
443
|
-
): void {
|
|
462
|
+
function backgroundRerender(r: Rerender, snapshot: RequestContextStore): void {
|
|
444
463
|
const waitUntil = getWaitUntil();
|
|
445
|
-
const tags = resolveTags(options, props);
|
|
446
|
-
const oKey = overlayKey(id, cacheKey);
|
|
447
|
-
const startEpoch = currentInvalidationEpoch();
|
|
448
|
-
const sfKey = `prebuilt-bg:${oKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
449
464
|
|
|
450
465
|
const work = requestContextAls.run(snapshot, () =>
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
async () => {
|
|
459
|
-
const captured = await captureComponentPayload(id, component, props, options);
|
|
460
|
-
if (!signal.aborted && mayStoreRerender(startEpoch, id, cacheKey, oKey, tags)) {
|
|
461
|
-
await storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed);
|
|
462
|
-
}
|
|
463
|
-
},
|
|
464
|
-
(error) =>
|
|
465
|
-
console.error(
|
|
466
|
-
`[timber] cache.component background re-render failed for "${id}":`,
|
|
467
|
-
error
|
|
468
|
-
)
|
|
469
|
-
)
|
|
466
|
+
// The stale payload already answered the request, so nothing else sees
|
|
467
|
+
// a failure here: logged and reported once per flight, inside the body.
|
|
468
|
+
// Inline re-render and revive failures are only logged: a live render
|
|
469
|
+
// answers instead.
|
|
470
|
+
rerenderFlight(r, (signal, capture) =>
|
|
471
|
+
runBackgroundFlight(signal, capture, (error) =>
|
|
472
|
+
console.error(`[timber] cache.component background re-render failed for "${r.id}":`, error)
|
|
470
473
|
)
|
|
471
|
-
|
|
472
|
-
//
|
|
474
|
+
)
|
|
475
|
+
// Reported inside the flight; this handle only keeps it unhandled-free.
|
|
473
476
|
.catch(() => {})
|
|
474
477
|
);
|
|
475
478
|
|
|
@@ -518,38 +521,42 @@ async function resolveDevSeed(
|
|
|
518
521
|
const guardTags = [...tags, devComponentTag(id)];
|
|
519
522
|
const sfKey = `prebuilt-dev:${guardKey}\0${lastInvalidationEpochFor(guardKey, guardTags)}`;
|
|
520
523
|
try {
|
|
521
|
-
return await componentSingleflight.do(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (outcome.bytes === null) return null;
|
|
532
|
-
// Smoke-revive before storing, as the build does: bytes that cannot
|
|
533
|
-
// be decoded would fail every later request until the next save.
|
|
534
|
-
if ((await revivePayload(id, outcome.bytes, 'not storing the dev capture')) === null) {
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
// A save (or revalidateTag) while this rendered: the bytes may come
|
|
538
|
-
// from the old code, so this request gets them but the store does not.
|
|
539
|
-
const moved = isr && overlayKey(id, cacheKey) !== guardKey;
|
|
540
|
-
if (!signal.aborted && !moved && !wasInvalidatedSince(startEpoch, guardKey, guardTags)) {
|
|
541
|
-
setDevSeed(id, cacheKey, {
|
|
542
|
-
bytes: outcome.bytes,
|
|
543
|
-
tags,
|
|
544
|
-
capturedAt,
|
|
545
|
-
isr,
|
|
546
|
-
});
|
|
547
|
-
warnNestingClamps({ id, options, tags }, outcome.nested, warnedNestingPairs, (m) =>
|
|
548
|
-
console.warn(m)
|
|
524
|
+
return await componentSingleflight.do(
|
|
525
|
+
sfKey,
|
|
526
|
+
async (signal) => {
|
|
527
|
+
const startEpoch = currentInvalidationEpoch();
|
|
528
|
+
const capturedAt = Date.now();
|
|
529
|
+
const { renderFlight } = requireRscFunctions();
|
|
530
|
+
// Outside the request's React.cache scope, like every stored capture
|
|
531
|
+
// (TIM-1529).
|
|
532
|
+
const outcome = await runOutsideReactCacheScope(() =>
|
|
533
|
+
renderEntry(registration, props, keyParams, getCaptureTimeoutMs(), false, renderFlight)
|
|
549
534
|
);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
535
|
+
if (outcome.failure instanceof BuildTimeContextError) throw outcome.failure;
|
|
536
|
+
if (outcome.bytes === null) return null;
|
|
537
|
+
// Smoke-revive before storing, as the build does: bytes that cannot
|
|
538
|
+
// be decoded would fail every later request until the next save.
|
|
539
|
+
if ((await revivePayload(id, outcome.bytes, 'not storing the dev capture')) === null) {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
// A save (or revalidateTag) while this rendered: the bytes may come
|
|
543
|
+
// from the old code, so this request gets them but the store does not.
|
|
544
|
+
const moved = isr && overlayKey(id, cacheKey) !== guardKey;
|
|
545
|
+
if (!signal.aborted && !moved && !wasInvalidatedSince(startEpoch, guardKey, guardTags)) {
|
|
546
|
+
setDevSeed(id, cacheKey, {
|
|
547
|
+
bytes: outcome.bytes,
|
|
548
|
+
tags,
|
|
549
|
+
capturedAt,
|
|
550
|
+
isr,
|
|
551
|
+
});
|
|
552
|
+
warnNestingClamps({ id, options, tags }, outcome.nested, warnedNestingPairs, (m) =>
|
|
553
|
+
console.warn(m)
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return { payload: outcome.bytes, capturedAt };
|
|
557
|
+
},
|
|
558
|
+
componentTimeoutMs
|
|
559
|
+
);
|
|
553
560
|
} catch (error) {
|
|
554
561
|
if (error instanceof BuildTimeContextError) throw error;
|
|
555
562
|
console.error(`[timber] cache.component dev capture failed for "${id}":`, error);
|
|
@@ -624,7 +631,10 @@ async function tryRevivePayload(
|
|
|
624
631
|
if (overlayResult) {
|
|
625
632
|
const overlayHasSeed = overlayResult.record?.s ?? false;
|
|
626
633
|
if (overlayResult.kind === 'tombstone') {
|
|
627
|
-
return await inlineRerender(
|
|
634
|
+
return await inlineRerender(
|
|
635
|
+
{ id, component, props, cacheKey, options, hasSeed: true },
|
|
636
|
+
outcome
|
|
637
|
+
);
|
|
628
638
|
}
|
|
629
639
|
// Unreadable is decided after the seed lookup: the seed says whether
|
|
630
640
|
// this key was ever enumerated (a strict miss must still throw), but
|
|
@@ -636,23 +646,13 @@ async function tryRevivePayload(
|
|
|
636
646
|
if (overlayResult.kind === 'stale' && overlayResult.payload) {
|
|
637
647
|
if (options.staleWhileRevalidate) {
|
|
638
648
|
backgroundRerender(
|
|
639
|
-
id,
|
|
640
|
-
component,
|
|
641
|
-
props,
|
|
642
|
-
cacheKey,
|
|
643
|
-
options,
|
|
644
|
-
overlayHasSeed,
|
|
649
|
+
{ id, component, props, cacheKey, options, hasSeed: overlayHasSeed },
|
|
645
650
|
snapshotRequestContext(store)
|
|
646
651
|
);
|
|
647
652
|
return await revivePayload(id, overlayResult.payload, outcome);
|
|
648
653
|
}
|
|
649
654
|
return await inlineRerender(
|
|
650
|
-
id,
|
|
651
|
-
component,
|
|
652
|
-
props,
|
|
653
|
-
cacheKey,
|
|
654
|
-
options,
|
|
655
|
-
overlayHasSeed,
|
|
655
|
+
{ id, component, props, cacheKey, options, hasSeed: overlayHasSeed },
|
|
656
656
|
outcome
|
|
657
657
|
);
|
|
658
658
|
}
|
|
@@ -669,7 +669,10 @@ async function tryRevivePayload(
|
|
|
669
669
|
: null;
|
|
670
670
|
if (seed !== null && overlayUnreadable) {
|
|
671
671
|
// Render, as for a tombstone (design/06 §Store failures).
|
|
672
|
-
return await inlineRerender(
|
|
672
|
+
return await inlineRerender(
|
|
673
|
+
{ id, component, props, cacheKey, options, hasSeed: true },
|
|
674
|
+
outcome
|
|
675
|
+
);
|
|
673
676
|
}
|
|
674
677
|
if (seed !== null) {
|
|
675
678
|
// Check seed freshness when the component has a TTL.
|
|
@@ -679,17 +682,15 @@ async function tryRevivePayload(
|
|
|
679
682
|
// Stale seed
|
|
680
683
|
if (options.staleWhileRevalidate) {
|
|
681
684
|
backgroundRerender(
|
|
682
|
-
id,
|
|
683
|
-
component,
|
|
684
|
-
props,
|
|
685
|
-
cacheKey,
|
|
686
|
-
options,
|
|
687
|
-
true,
|
|
685
|
+
{ id, component, props, cacheKey, options, hasSeed: true },
|
|
688
686
|
snapshotRequestContext(store)
|
|
689
687
|
);
|
|
690
688
|
return await revivePayload(id, seed.payload, outcome);
|
|
691
689
|
}
|
|
692
|
-
return await inlineRerender(
|
|
690
|
+
return await inlineRerender(
|
|
691
|
+
{ id, component, props, cacheKey, options, hasSeed: true },
|
|
692
|
+
outcome
|
|
693
|
+
);
|
|
693
694
|
}
|
|
694
695
|
}
|
|
695
696
|
// Fresh seed (or no TTL — immutable until redeploy)
|
|
@@ -710,7 +711,10 @@ async function tryRevivePayload(
|
|
|
710
711
|
// "only prebuilt content", so an unenumerated miss must throw (the
|
|
711
712
|
// wrapper handles the throw after we return null).
|
|
712
713
|
if (hasRuntime && options.fallbackOnMissingSegmentParams !== false) {
|
|
713
|
-
return await inlineRerender(
|
|
714
|
+
return await inlineRerender(
|
|
715
|
+
{ id, component, props, cacheKey, options, hasSeed: false },
|
|
716
|
+
outcome
|
|
717
|
+
);
|
|
714
718
|
}
|
|
715
719
|
|
|
716
720
|
return null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upstream framing on forwarded responses (GHSA-pc58-hwjq-p385 class,
|
|
3
|
+
* design/13-security.md #42).
|
|
4
|
+
*
|
|
5
|
+
* `fetch()` transparently decodes a gzip/br/deflate/zstd body but keeps the
|
|
6
|
+
* upstream's `Content-Encoding` and `Content-Length`, along with its
|
|
7
|
+
* connection-level headers. A route handler, proxy.ts or middleware that
|
|
8
|
+
* returns that `Response` — directly or through
|
|
9
|
+
* `new Response(res.body, { headers: res.headers })` — would otherwise send
|
|
10
|
+
* the decoded bytes framed by the encoded length. On a keep-alive HTTP/1.1
|
|
11
|
+
* connection the surplus bytes are read as the *next* response: a reverse
|
|
12
|
+
* proxy that queues several clients on one backend connection hands an
|
|
13
|
+
* upstream-controlled response to another client, or one client's response
|
|
14
|
+
* to the wrong one.
|
|
15
|
+
*
|
|
16
|
+
* Whether a body was decoded is not observable from the `Response` (the
|
|
17
|
+
* header-copying proxy pattern produces an ordinary constructed `Response`),
|
|
18
|
+
* so the rule is stated on the headers alone:
|
|
19
|
+
*
|
|
20
|
+
* - A response that declares `Content-Encoding` loses it and its
|
|
21
|
+
* `Content-Length`. The length described the encoded bytes; the server
|
|
22
|
+
* frames what it actually writes, and the adapter's compression step may
|
|
23
|
+
* re-encode it. Matches Next.js (vercel/next.js#101108). The cost: a
|
|
24
|
+
* handler cannot hand back a pre-compressed body under its own
|
|
25
|
+
* `Content-Encoding`.
|
|
26
|
+
* - Hop-by-hop headers (RFC 9110 §7.6.1) describe the upstream's
|
|
27
|
+
* connection, not this one, and are owned by the server writing the
|
|
28
|
+
* socket. They are always dropped. A forwarded `Connection: keep-alive` otherwise
|
|
29
|
+
* overrides the client's `Connection: close`, and a forwarded
|
|
30
|
+
* `Transfer-Encoding` claims a framing the server did not choose.
|
|
31
|
+
* The extra headers a `Connection` value names are deliberately not
|
|
32
|
+
* honored: the response's headers here are the upstream's merged with
|
|
33
|
+
* the app's own (cookies, middleware headers), and an upstream sending
|
|
34
|
+
* `Connection: set-cookie` must not be able to delete the app's session.
|
|
35
|
+
* - A `Content-Length` on an unencoded response is the route's own claim
|
|
36
|
+
* and is kept — a HEAD response relies on it (head-requests.test.ts).
|
|
37
|
+
*
|
|
38
|
+
* Applied at the pipeline's single exit, before compression, so every
|
|
39
|
+
* producer is covered — including ones added later. Timber's own renderers
|
|
40
|
+
* set none of these headers inside the pipeline.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const HOP_BY_HOP = [
|
|
44
|
+
'connection',
|
|
45
|
+
'keep-alive',
|
|
46
|
+
'proxy-connection',
|
|
47
|
+
'te',
|
|
48
|
+
'trailer',
|
|
49
|
+
'transfer-encoding',
|
|
50
|
+
'upgrade',
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
export function dropUpstreamFraming(response: Response): void {
|
|
54
|
+
const { headers } = response;
|
|
55
|
+
for (const name of HOP_BY_HOP) headers.delete(name);
|
|
56
|
+
if (!headers.has('content-encoding')) return;
|
|
57
|
+
headers.delete('content-encoding');
|
|
58
|
+
headers.delete('content-length');
|
|
59
|
+
}
|