@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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* timber-client-in-server-package-deps — in dev, the RSC environment resolves
|
|
3
|
+
* a package's inner 'use client' file through its bare package path, so the
|
|
4
|
+
* browser loads it from the client pre-bundle.
|
|
5
|
+
*
|
|
6
|
+
* plugin-rsc records a package source only for a file the RSC environment
|
|
7
|
+
* reaches through a bare import. A server component that reaches a 'use
|
|
8
|
+
* client' file through the package's own relative imports (lucide-react's
|
|
9
|
+
* `icons/play.mjs` → `createLucideIcon.mjs` → `./Icon.mjs`, or
|
|
10
|
+
* `@mui/material/Button` → `./Button.mjs`) gets a client reference whose
|
|
11
|
+
* browser module re-exports the file's absolute path
|
|
12
|
+
* (`client-in-server-package-proxy`). Vite serves that file, and everything it
|
|
13
|
+
* imports, raw:
|
|
14
|
+
*
|
|
15
|
+
* - If an app client component also imports the package, the browser holds
|
|
16
|
+
* two instances of those modules, the pre-bundled one and the raw one, so a
|
|
17
|
+
* context the package provides (`LucideProvider`) does not reach icons
|
|
18
|
+
* rendered by server components. plugin-rsc detects this and warns "client
|
|
19
|
+
* component dependency is inconsistently optimized" on every dev start.
|
|
20
|
+
* - If the file imports a CommonJS package (`prop-types`), the browser
|
|
21
|
+
* cannot link it and the page fails (vitejs/vite-plugin-react#1538).
|
|
22
|
+
*
|
|
23
|
+
* This plugin resolves such an import as the bare specifier the file has from
|
|
24
|
+
* the app root (`lucide-react/dist/esm/Icon.mjs`). plugin-rsc then records that
|
|
25
|
+
* specifier as the file's package source and gives the browser
|
|
26
|
+
* `client-package-proxy`, which imports the bare specifier. The client deps
|
|
27
|
+
* optimizer pre-bundles it like any package import, splitting the modules it
|
|
28
|
+
* shares with the package's own entry into one chunk, so the browser loads one
|
|
29
|
+
* instance. No inconsistency remains, so plugin-rsc does not warn.
|
|
30
|
+
*
|
|
31
|
+
* Every rule leans toward leaving the import alone, which keeps plugin-rsc's
|
|
32
|
+
* raw-file behavior:
|
|
33
|
+
* - only in the RSC environment, in dev (a build has no proxy modules);
|
|
34
|
+
* - only for a non-bare source (a bare one already gets a package source);
|
|
35
|
+
* - only from a package file, or for an absolute path into `node_modules`
|
|
36
|
+
* (what the barrel rewrite emits), so an app module's own relative imports
|
|
37
|
+
* are not resolved twice;
|
|
38
|
+
* - only when the resolved id is a plain file (no query but Vite's `?v=`; a
|
|
39
|
+
* `?raw` or `?url` import asks for something other than the module), under
|
|
40
|
+
* `node_modules`, whose directive prologue holds 'use client';
|
|
41
|
+
* - only when the bare specifier resolves to the same file, from the importer
|
|
42
|
+
* here and from the app root in plugin-rsc. A package whose `exports` hides
|
|
43
|
+
* the file, or a transitive dependency the app cannot import by name, stays
|
|
44
|
+
* as it is.
|
|
45
|
+
*
|
|
46
|
+
* A file found after startup is a new client dep, so the client optimizer
|
|
47
|
+
* re-runs once, as for any import discovered late; Vite keeps it in the dep
|
|
48
|
+
* cache for later starts. See design/21-dev-server.md §"Inner 'use client'
|
|
49
|
+
* Files of Packages".
|
|
50
|
+
*
|
|
51
|
+
* Remove once plugin-rsc imports these files through the client pre-bundle
|
|
52
|
+
* itself.
|
|
53
|
+
*/
|
|
54
|
+
import type { Plugin } from 'vite';
|
|
55
|
+
/**
|
|
56
|
+
* The bare specifier `file` has as a package path, or null when the file is not
|
|
57
|
+
* inside a package. The last `node_modules` segment is the package, so a pnpm
|
|
58
|
+
* store path (`.pnpm/lucide-react@1.66.0/node_modules/lucide-react/…`) names
|
|
59
|
+
* the package, not the store.
|
|
60
|
+
*/
|
|
61
|
+
export declare function packagePathOf(file: string): string | null;
|
|
62
|
+
export declare function timberClientInServerPackageDeps(rscEnvironmentName?: string): Plugin;
|
|
63
|
+
//# sourceMappingURL=client-in-server-package-deps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-in-server-package-deps.d.ts","sourceRoot":"","sources":["../../src/plugins/client-in-server-package-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AASnC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKzD;AAED,wBAAgB,+BAA+B,CAAC,kBAAkB,SAAQ,GAAG,MAAM,CA6DlF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import specifiers whose barrel imports timber rewrites by default.
|
|
3
|
+
*
|
|
4
|
+
* Copied from Next.js's built-in `optimizePackageImports` list
|
|
5
|
+
* (packages/next/src/server/config.ts, vercel/next.js@50bf604f2), so an app
|
|
6
|
+
* moving from Next gets the same set without configuring it. Entries are exact
|
|
7
|
+
* import specifiers, not package names: a package with several icon entry
|
|
8
|
+
* points (`react-icons/fa`, `@heroicons/react/24/solid`) lists each one.
|
|
9
|
+
*
|
|
10
|
+
* See design/21-dev-server.md §"Barrel Import Optimization".
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_OPTIMIZE_PACKAGE_IMPORTS: readonly string[];
|
|
13
|
+
//# sourceMappingURL=optimize-package-imports-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimize-package-imports-defaults.d.ts","sourceRoot":"","sources":["../../src/plugins/optimize-package-imports-defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,EAAE,SAAS,MAAM,EA4E7D,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* timber-optimize-package-imports — rewrites named imports from a listed
|
|
3
|
+
* barrel package into imports of only the modules that define those names.
|
|
4
|
+
*
|
|
5
|
+
* In dev, `@vitejs/plugin-rsc` keeps packages with a `react` peer dependency
|
|
6
|
+
* in the rsc and ssr module graphs without pre-bundling them, so on the server
|
|
7
|
+
* `import { Play } from 'lucide-react'` enters lucide's barrel and Vite
|
|
8
|
+
* transforms all ~2,000 icon modules it re-exports, once per environment. A
|
|
9
|
+
* build loads all of them too, before tree-shaking. The
|
|
10
|
+
* rewrite turns that import into one of the icon's own file:
|
|
11
|
+
*
|
|
12
|
+
* import { Play } from 'lucide-react'
|
|
13
|
+
* → import { default as Play } from "/…/lucide-react/dist/esm/icons/play.mjs";
|
|
14
|
+
*
|
|
15
|
+
* Next.js does the same for its `optimizePackageImports` list
|
|
16
|
+
* (next-barrel-loader.ts, optimize_barrel.rs). It applies to every environment
|
|
17
|
+
* in builds; in dev, to the server environments and only for packages Vite
|
|
18
|
+
* compiles itself (the client environment pre-bundles them; the server
|
|
19
|
+
* environments hand most other packages to Node). See design/21-dev-server.md
|
|
20
|
+
* §"Barrel Import Optimization".
|
|
21
|
+
*
|
|
22
|
+
* Every rule here leans toward leaving the import alone. A missed rewrite costs
|
|
23
|
+
* compile time; a wrong one breaks the app. An import is rewritten only when
|
|
24
|
+
* the barrel is a pure barrel (nothing but imports and re-exports) and every
|
|
25
|
+
* imported name is in its export map with a target that resolves to a file.
|
|
26
|
+
*/
|
|
27
|
+
import { MagicString } from 'magic-string';
|
|
28
|
+
import { type Plugin } from 'vite';
|
|
29
|
+
import type { PluginContext } from '../plugin-context.ts';
|
|
30
|
+
type Lang = 'js' | 'jsx' | 'ts' | 'tsx';
|
|
31
|
+
/** Where a barrel's export comes from. */
|
|
32
|
+
export interface BarrelExport {
|
|
33
|
+
/** The specifier as written in the barrel (`'./icons/play.mjs'`). */
|
|
34
|
+
source: string;
|
|
35
|
+
/** The name in `source`: an export name, `'default'`, or `'*'` for a namespace. */
|
|
36
|
+
imported: string;
|
|
37
|
+
}
|
|
38
|
+
/** Export name → origin, for the names a barrel states explicitly. */
|
|
39
|
+
export type BarrelExportMap = ReadonlyMap<string, BarrelExport>;
|
|
40
|
+
/** A barrel the rewrite may import past, as seen from one importer. */
|
|
41
|
+
export interface ResolvedBarrel {
|
|
42
|
+
exports: BarrelExportMap;
|
|
43
|
+
/** Resolve a source from `exports` relative to the barrel; null = leave the import alone. */
|
|
44
|
+
resolveTarget(source: string): Promise<string | null>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Merge the user's list with the defaults (Next's semantics: the user list
|
|
48
|
+
* adds, never replaces). Config validation reports invalid entries without
|
|
49
|
+
* stopping the dev server, so only the valid ones (non-empty strings) are used
|
|
50
|
+
* here; a string list is not spread into characters, and an empty entry does
|
|
51
|
+
* not match every quoted empty string.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveOptimizedPackages(user: readonly string[] | undefined): ReadonlySet<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Read a barrel's export map, or null when the file is not a pure barrel.
|
|
56
|
+
*
|
|
57
|
+
* A pure barrel holds only imports, re-exports, and `export { local }` of an
|
|
58
|
+
* imported binding (`import * as icons from './icons'; export { icons }`, which
|
|
59
|
+
* lucide-react's barrel opens with). Anything that runs code of its own, a
|
|
60
|
+
* declaration, an expression, a bare side-effect import, makes it not a barrel:
|
|
61
|
+
* importing past it would skip that code. So does any directive except
|
|
62
|
+
* `'use strict'`: a `'use client'` or `'use server'` barrel is a boundary
|
|
63
|
+
* plugin-rsc draws around the barrel module itself, and importing past it would
|
|
64
|
+
* load the re-exported files on the wrong side of it.
|
|
65
|
+
*
|
|
66
|
+
* `export default local` is not followed even when `local` is imported: it
|
|
67
|
+
* exports the value `local` held when the barrel ran, not a live binding, so
|
|
68
|
+
* importing `local` directly would see later reassignments the barrel's
|
|
69
|
+
* default never does. `export { local as default }` is live and is followed.
|
|
70
|
+
*
|
|
71
|
+
* A source-phase or deferred import, or import attributes, change what the
|
|
72
|
+
* barrel's binding is, so a barrel using them is not followed. An
|
|
73
|
+
* `export {} from` with no names only runs the module, like a bare import.
|
|
74
|
+
*
|
|
75
|
+
* `export * from` adds no entries. A name it might supply is not in the map, so
|
|
76
|
+
* an import of that name falls back; explicit exports shadow star exports, so
|
|
77
|
+
* every name that is in the map is exact.
|
|
78
|
+
*/
|
|
79
|
+
export declare function readBarrelExportMap(code: string, lang: Lang): BarrelExportMap | null;
|
|
80
|
+
/**
|
|
81
|
+
* Rewrite every import and `export { … } from` of a listed specifier whose
|
|
82
|
+
* names the barrel's export map covers. Returns null when nothing changed.
|
|
83
|
+
*
|
|
84
|
+
* Replacements stay on the statement's own lines, so positions after it keep
|
|
85
|
+
* their line numbers even before the source map is applied.
|
|
86
|
+
*/
|
|
87
|
+
export declare function rewriteBarrelImports(code: string, packages: ReadonlySet<string>, loadBarrel: (specifier: string) => Promise<ResolvedBarrel | null>): Promise<MagicString | null>;
|
|
88
|
+
/** The resolve options that decide whether a server environment externalizes a package. */
|
|
89
|
+
export interface ExternalizationConfig {
|
|
90
|
+
noExternal: string | RegExp | readonly (string | RegExp)[] | true;
|
|
91
|
+
external: readonly string[] | true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether the environment loads `specifier` through Vite rather than handing
|
|
95
|
+
* it to Node. Only those imports are rewritten.
|
|
96
|
+
*
|
|
97
|
+
* A server environment externalizes most of node_modules in dev: Node loads
|
|
98
|
+
* the package natively, so its barrel costs nothing to compile. Rewriting such
|
|
99
|
+
* an import to a file path would pull that file into Vite's module graph
|
|
100
|
+
* while any other import of the package stayed external, two instances of one
|
|
101
|
+
* module. In dev, plugin-rsc keeps packages with a `react` peer dependency
|
|
102
|
+
* (lucide-react, the icon sets, the component libraries) out of
|
|
103
|
+
* externalization, and timber's production build sets `noExternal: true`.
|
|
104
|
+
*
|
|
105
|
+
* Vite's own check is internal, so this is its conservative subset: the
|
|
106
|
+
* package must match `resolve.noExternal` exactly (a string or a RegExp) and
|
|
107
|
+
* `resolve.external` must not name it. A glob string in `noExternal` does
|
|
108
|
+
* not match here, which only costs the optimization.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isLoadedThroughVite(specifier: string, config: ExternalizationConfig): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* A resolved id as a plain file import, or null when it is not one (virtual,
|
|
113
|
+
* relative, or carrying a query that changes what the module is).
|
|
114
|
+
*
|
|
115
|
+
* Vite's dev resolver appends `?v=<hash>` to files under node_modules, in the
|
|
116
|
+
* server environments too, and appends the same query again when it resolves
|
|
117
|
+
* the absolute path this rewrite emits. So the query is dropped, never copied:
|
|
118
|
+
* the emitted path resolves to the same id the barrel's own import would, which
|
|
119
|
+
* keeps one module instance per file.
|
|
120
|
+
*/
|
|
121
|
+
export declare function asFilePath(id: string): string | null;
|
|
122
|
+
export declare function timberOptimizePackageImports(ctx: PluginContext): Plugin;
|
|
123
|
+
export {};
|
|
124
|
+
//# sourceMappingURL=optimize-package-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,qBAA0B,EASpE;IAED,wFAAwF;IACxF,gBAAgB,IAAI,IAAI,CAEvB;IAED,+EAA+E;IAC/E,cAAc,IAAI,IAAI,CAErB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;;;;;;OAOG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAKtD;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAQ5B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,OAAO,CAAC,OAAO;YAID,WAAW;CA2D1B"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as addSpanEvent, D as getSpanId, I as isDenySignal, L as isRedirectSignal, M as withSpan, O as getTraceId, S as isDevMode, x as isDebug } from "../_chunks/logger-CWk44DLp.js";
|
|
2
2
|
import { t as formatSize } from "../_chunks/format-DuPOoXUP.js";
|
|
3
|
-
import { _ as getHeaders, a as parseFormData, c as deny, d as waitUntil, i as coerce, l as redirect, n as revalidatePath, p as getCookieJar, r as revalidateTag, u as redirectExternal, y as getSegmentParams } from "../_chunks/actions-
|
|
3
|
+
import { _ as getHeaders, a as parseFormData, c as deny, d as waitUntil, i as coerce, l as redirect, n as revalidatePath, p as getCookieJar, r as revalidateTag, u as redirectExternal, y as getSegmentParams } from "../_chunks/actions-B1xSIv32.js";
|
|
4
4
|
// src/shared/redirect-type.ts
|
|
5
5
|
/**
|
|
6
6
|
* Next.js redirect type discriminator.
|
package/dist/server/internal.js
CHANGED
|
@@ -10,10 +10,10 @@ import { i as requestContextAls, n as prebuiltCaptureAls, o as timingAls, t as e
|
|
|
10
10
|
import { A as runWithTraceId, E as getOtelTraceId, F as isControlFlowSignal, I as isDenySignal, L as isRedirectSignal, M as withSpan, O as getTraceId, T as generateTraceId, _ as logWaitUntilRejected, b as swallow, c as logMiddlewareShortCircuit, d as logRequestCompleted, f as logRequestReceived, g as logSwrRefetchFailed, h as logSlowRequest, i as logCsrfRejected, j as setSpanAttribute, k as replaceTraceId, l as logProxyError, m as logRouteSetupError, n as logCacheMiss, p as logRouteError, s as logMiddlewareError, t as getLogger, u as logRenderError, v as logWaitUntilUnsupported, x as isDebug, y as setLogger } from "../_chunks/logger-CWk44DLp.js";
|
|
11
11
|
import { i as collectRouteModulepreloads, n as collectRouteCss, r as collectRouteFonts } from "../_chunks/build-manifest-Y4jl7nwU.js";
|
|
12
12
|
import { i as isRscCacheKeyShape, n as RSC_KEY_PARAM, r as appVisibleSearch, s as rscCacheKey, t as RSC_KEY_HEADERS } from "../_chunks/rsc-cache-key-D0cb0Gmc.js";
|
|
13
|
-
import { C as setMatchedSegmentPath, E as runOutsideReactCacheScope, S as runWithSegmentParams, T as setSegmentParams, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setMutableCookieContext, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-
|
|
14
|
-
import { _ as getWaitUntil, a as storeOverlayEntry, c as lookupArtifactSeed, d as checkVersionSkew, g as observeKeyDiscipline, i as overlayKey, l as setPrebuiltPayloadSource, n as lookupOverlay, o as hasPrebuiltPayloadSource, r as mayStoreRerender, s as isParamIndependent, u as applyReloadHeaders } from "../_chunks/cache-api-
|
|
15
|
-
import { n as createSingleflight } from "../_chunks/singleflight-
|
|
16
|
-
import { l as TIMBER_ERROR_HEADER, t as StatusPageMarker } from "../_chunks/status-page-marker-
|
|
13
|
+
import { C as setMatchedSegmentPath, E as runOutsideReactCacheScope, S as runWithSegmentParams, T as setSegmentParams, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setMutableCookieContext, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-B1xSIv32.js";
|
|
14
|
+
import { _ as getWaitUntil, a as storeOverlayEntry, c as lookupArtifactSeed, d as checkVersionSkew, g as observeKeyDiscipline, i as overlayKey, l as setPrebuiltPayloadSource, n as lookupOverlay, o as hasPrebuiltPayloadSource, r as mayStoreRerender, s as isParamIndependent, u as applyReloadHeaders } from "../_chunks/cache-api-DsSXA4Sp.js";
|
|
15
|
+
import { n as createSingleflight } from "../_chunks/singleflight-CzoOVB9Y.js";
|
|
16
|
+
import { l as TIMBER_ERROR_HEADER, t as StatusPageMarker } from "../_chunks/status-page-marker-C8POawuF.js";
|
|
17
17
|
import { n as toBracketKey } from "../_chunks/resolve-schema-B-aCuTu3.js";
|
|
18
18
|
import { t as normalizeParamValue } from "../_chunks/param-value-DqlGfF57.js";
|
|
19
19
|
import { t as createGlobalContext } from "../_chunks/global-context-DbxNWeBP.js";
|
|
@@ -761,7 +761,10 @@ function fireInBackground(report) {
|
|
|
761
761
|
* per request that joined it, so the report happens inside the body. A
|
|
762
762
|
* body still running when the singleflight times out is reported then,
|
|
763
763
|
* with the timeout error (the signal's reason), and its later rejection
|
|
764
|
-
* is
|
|
764
|
+
* is not reported again.
|
|
765
|
+
* - **Settles with the work's outcome.** The value or the error passes
|
|
766
|
+
* through, so an inline re-render that joined this flight receives the
|
|
767
|
+
* captured bytes, or the failure, instead of `undefined`.
|
|
765
768
|
* - **Against the request whose stale read started it**, read from the
|
|
766
769
|
* request context the work runs in. With no request (the build-time
|
|
767
770
|
* capture store) it is only logged.
|
|
@@ -779,9 +782,10 @@ async function runBackgroundFlight(signal, work, log) {
|
|
|
779
782
|
const settled = new AbortController();
|
|
780
783
|
onAbortUntil(signal, () => failed(signal.reason), settled.signal);
|
|
781
784
|
try {
|
|
782
|
-
await work();
|
|
785
|
+
return await work();
|
|
783
786
|
} catch (error) {
|
|
784
787
|
if (!signal.aborted) failed(error);
|
|
788
|
+
throw error;
|
|
785
789
|
} finally {
|
|
786
790
|
settled.abort();
|
|
787
791
|
}
|
|
@@ -2241,6 +2245,64 @@ async function enforceRscCacheKey(req, response) {
|
|
|
2241
2245
|
if (await hasValidRscCacheKey(req)) return;
|
|
2242
2246
|
preventResponseCaching(response.headers);
|
|
2243
2247
|
}
|
|
2248
|
+
// src/server/response-framing.ts
|
|
2249
|
+
/**
|
|
2250
|
+
* Upstream framing on forwarded responses (GHSA-pc58-hwjq-p385 class,
|
|
2251
|
+
* design/13-security.md #42).
|
|
2252
|
+
*
|
|
2253
|
+
* `fetch()` transparently decodes a gzip/br/deflate/zstd body but keeps the
|
|
2254
|
+
* upstream's `Content-Encoding` and `Content-Length`, along with its
|
|
2255
|
+
* connection-level headers. A route handler, proxy.ts or middleware that
|
|
2256
|
+
* returns that `Response` — directly or through
|
|
2257
|
+
* `new Response(res.body, { headers: res.headers })` — would otherwise send
|
|
2258
|
+
* the decoded bytes framed by the encoded length. On a keep-alive HTTP/1.1
|
|
2259
|
+
* connection the surplus bytes are read as the *next* response: a reverse
|
|
2260
|
+
* proxy that queues several clients on one backend connection hands an
|
|
2261
|
+
* upstream-controlled response to another client, or one client's response
|
|
2262
|
+
* to the wrong one.
|
|
2263
|
+
*
|
|
2264
|
+
* Whether a body was decoded is not observable from the `Response` (the
|
|
2265
|
+
* header-copying proxy pattern produces an ordinary constructed `Response`),
|
|
2266
|
+
* so the rule is stated on the headers alone:
|
|
2267
|
+
*
|
|
2268
|
+
* - A response that declares `Content-Encoding` loses it and its
|
|
2269
|
+
* `Content-Length`. The length described the encoded bytes; the server
|
|
2270
|
+
* frames what it actually writes, and the adapter's compression step may
|
|
2271
|
+
* re-encode it. Matches Next.js (vercel/next.js#101108). The cost: a
|
|
2272
|
+
* handler cannot hand back a pre-compressed body under its own
|
|
2273
|
+
* `Content-Encoding`.
|
|
2274
|
+
* - Hop-by-hop headers (RFC 9110 §7.6.1) describe the upstream's
|
|
2275
|
+
* connection, not this one, and are owned by the server writing the
|
|
2276
|
+
* socket. They are always dropped. A forwarded `Connection: keep-alive` otherwise
|
|
2277
|
+
* overrides the client's `Connection: close`, and a forwarded
|
|
2278
|
+
* `Transfer-Encoding` claims a framing the server did not choose.
|
|
2279
|
+
* The extra headers a `Connection` value names are deliberately not
|
|
2280
|
+
* honored: the response's headers here are the upstream's merged with
|
|
2281
|
+
* the app's own (cookies, middleware headers), and an upstream sending
|
|
2282
|
+
* `Connection: set-cookie` must not be able to delete the app's session.
|
|
2283
|
+
* - A `Content-Length` on an unencoded response is the route's own claim
|
|
2284
|
+
* and is kept — a HEAD response relies on it (head-requests.test.ts).
|
|
2285
|
+
*
|
|
2286
|
+
* Applied at the pipeline's single exit, before compression, so every
|
|
2287
|
+
* producer is covered — including ones added later. Timber's own renderers
|
|
2288
|
+
* set none of these headers inside the pipeline.
|
|
2289
|
+
*/
|
|
2290
|
+
var HOP_BY_HOP = [
|
|
2291
|
+
"connection",
|
|
2292
|
+
"keep-alive",
|
|
2293
|
+
"proxy-connection",
|
|
2294
|
+
"te",
|
|
2295
|
+
"trailer",
|
|
2296
|
+
"transfer-encoding",
|
|
2297
|
+
"upgrade"
|
|
2298
|
+
];
|
|
2299
|
+
function dropUpstreamFraming(response) {
|
|
2300
|
+
const { headers } = response;
|
|
2301
|
+
for (const name of HOP_BY_HOP) headers.delete(name);
|
|
2302
|
+
if (!headers.has("content-encoding")) return;
|
|
2303
|
+
headers.delete("content-encoding");
|
|
2304
|
+
headers.delete("content-length");
|
|
2305
|
+
}
|
|
2244
2306
|
// src/server/pipeline.ts
|
|
2245
2307
|
/**
|
|
2246
2308
|
* Create the request handler from a pipeline configuration.
|
|
@@ -2324,6 +2386,7 @@ function createPipeline(config) {
|
|
|
2324
2386
|
if (newTokens.length > 0) result.headers.set("Vary", existingVary ? `${existingVary}, ${newTokens.join(", ")}` : newTokens.join(", "));
|
|
2325
2387
|
await enforceRscCacheKey(canonicalReq, result);
|
|
2326
2388
|
hardenRscPayloadResponse(result);
|
|
2389
|
+
dropUpstreamFraming(result);
|
|
2327
2390
|
result = stripHeadBody(result, method);
|
|
2328
2391
|
if (serverTiming === "detailed") {
|
|
2329
2392
|
const timingHeader = getServerTimingHeader();
|
|
@@ -4618,8 +4681,13 @@ async function renderEntry(registration, props, coercedParams, timeoutMs, isLayo
|
|
|
4618
4681
|
*/
|
|
4619
4682
|
/** Default timeout for component re-renders (overridden by renderTimeoutMs). */
|
|
4620
4683
|
var DEFAULT_COMPONENT_TIMEOUT_MS = DEFAULT_RENDER_TIMEOUT_MS;
|
|
4621
|
-
/**
|
|
4622
|
-
|
|
4684
|
+
/**
|
|
4685
|
+
* Singleflight for component re-renders (inline and background) and dev
|
|
4686
|
+
* captures. One instance for the process: replacing it at boot would drop
|
|
4687
|
+
* every flight in progress and let a caller after the swap run a second
|
|
4688
|
+
* execution beside one still writing. The timeout is passed per call.
|
|
4689
|
+
*/
|
|
4690
|
+
var componentSingleflight = createSingleflight();
|
|
4623
4691
|
var componentTimeoutMs = DEFAULT_COMPONENT_TIMEOUT_MS;
|
|
4624
4692
|
var warnedNoWaitUntil = false;
|
|
4625
4693
|
/**
|
|
@@ -4740,22 +4808,41 @@ async function storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed
|
|
|
4740
4808
|
}, captured.nested, warnedNestingPairs, (m) => console.warn(m));
|
|
4741
4809
|
}
|
|
4742
4810
|
/**
|
|
4743
|
-
*
|
|
4744
|
-
*
|
|
4811
|
+
* Capture flight bytes and store them in the overlay, coalesced into one
|
|
4812
|
+
* flight per overlay key. The inline and the background (SWR) re-render
|
|
4813
|
+
* share the flight key: two executions for one key could otherwise both
|
|
4814
|
+
* store, the older, slower one landing last (TIM-1447). A caller joining
|
|
4815
|
+
* a flight started by the other path gets its bytes, or its error.
|
|
4816
|
+
*
|
|
4817
|
+
* Keyed by the overlay key, which carries the dev namespace: a request
|
|
4818
|
+
* after a save never joins a re-render of the pre-save code. `wrap` runs
|
|
4819
|
+
* the work inside the flight body — the background path reports its
|
|
4820
|
+
* failure there, once per flight.
|
|
4745
4821
|
*/
|
|
4746
|
-
|
|
4822
|
+
function rerenderFlight(r, wrap) {
|
|
4823
|
+
const { id, component, props, cacheKey, options, hasSeed } = r;
|
|
4747
4824
|
const tags = resolveTags(options, props);
|
|
4748
4825
|
const oKey = overlayKey(id, cacheKey);
|
|
4749
4826
|
const sfKey = `prebuilt:${oKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4827
|
+
return componentSingleflight.do(sfKey, (signal) => {
|
|
4828
|
+
const startEpoch = currentInvalidationEpoch();
|
|
4829
|
+
const work = async () => {
|
|
4753
4830
|
const captured = await captureComponentPayload(id, component, props, options);
|
|
4754
4831
|
if (!signal.aborted && hasRuntimeLifetime(options) && mayStoreRerender(startEpoch, id, cacheKey, oKey, tags)) await storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed);
|
|
4755
4832
|
return captured.bytes;
|
|
4756
|
-
}
|
|
4833
|
+
};
|
|
4834
|
+
return wrap ? wrap(signal, work) : work();
|
|
4835
|
+
}, componentTimeoutMs);
|
|
4836
|
+
}
|
|
4837
|
+
/**
|
|
4838
|
+
* Inline re-render: capture (or join the flight capturing) the entry, and
|
|
4839
|
+
* revive it for the current request.
|
|
4840
|
+
*/
|
|
4841
|
+
async function inlineRerender(r, outcome) {
|
|
4842
|
+
try {
|
|
4843
|
+
return await revivePayload(r.id, await rerenderFlight(r), outcome);
|
|
4757
4844
|
} catch (error) {
|
|
4758
|
-
console.error(`[timber] cache.component re-render failed for "${id}" — ${outcome}:`, error);
|
|
4845
|
+
console.error(`[timber] cache.component re-render failed for "${r.id}" — ${outcome}:`, error);
|
|
4759
4846
|
return null;
|
|
4760
4847
|
}
|
|
4761
4848
|
}
|
|
@@ -4784,16 +4871,9 @@ function snapshotRequestContext(store) {
|
|
|
4784
4871
|
* Kick off a background re-render via waitUntil. The re-render runs inside
|
|
4785
4872
|
* a fresh ALS scope with snapshotted request context.
|
|
4786
4873
|
*/
|
|
4787
|
-
function backgroundRerender(
|
|
4874
|
+
function backgroundRerender(r, snapshot) {
|
|
4788
4875
|
const waitUntil = getWaitUntil();
|
|
4789
|
-
const
|
|
4790
|
-
const oKey = overlayKey(id, cacheKey);
|
|
4791
|
-
const startEpoch = currentInvalidationEpoch();
|
|
4792
|
-
const sfKey = `prebuilt-bg:${oKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
4793
|
-
const work = requestContextAls.run(snapshot, () => componentSingleflight.do(sfKey, (signal) => runBackgroundFlight(signal, async () => {
|
|
4794
|
-
const captured = await captureComponentPayload(id, component, props, options);
|
|
4795
|
-
if (!signal.aborted && mayStoreRerender(startEpoch, id, cacheKey, oKey, tags)) await storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed);
|
|
4796
|
-
}, (error) => console.error(`[timber] cache.component background re-render failed for "${id}":`, error))).catch(() => {}));
|
|
4876
|
+
const work = requestContextAls.run(snapshot, () => rerenderFlight(r, (signal, capture) => runBackgroundFlight(signal, capture, (error) => console.error(`[timber] cache.component background re-render failed for "${r.id}":`, error))).catch(() => {}));
|
|
4797
4877
|
if (waitUntil) waitUntil(work);
|
|
4798
4878
|
else if (!warnedNoWaitUntil) {
|
|
4799
4879
|
warnedNoWaitUntil = true;
|
|
@@ -4850,7 +4930,7 @@ async function resolveDevSeed(registration, props, keyParams, cacheKey) {
|
|
|
4850
4930
|
payload: outcome.bytes,
|
|
4851
4931
|
capturedAt
|
|
4852
4932
|
};
|
|
4853
|
-
});
|
|
4933
|
+
}, componentTimeoutMs);
|
|
4854
4934
|
} catch (error) {
|
|
4855
4935
|
if (error instanceof BuildTimeContextError) throw error;
|
|
4856
4936
|
console.error(`[timber] cache.component dev capture failed for "${id}":`, error);
|
|
@@ -4882,34 +4962,83 @@ async function tryRevivePayload(registration, props, keyPropsOverride) {
|
|
|
4882
4962
|
const overlayResult = await lookupOverlay(id, cacheKey);
|
|
4883
4963
|
if (overlayResult) {
|
|
4884
4964
|
const overlayHasSeed = overlayResult.record?.s ?? false;
|
|
4885
|
-
if (overlayResult.kind === "tombstone") return await inlineRerender(
|
|
4965
|
+
if (overlayResult.kind === "tombstone") return await inlineRerender({
|
|
4966
|
+
id,
|
|
4967
|
+
component,
|
|
4968
|
+
props,
|
|
4969
|
+
cacheKey,
|
|
4970
|
+
options,
|
|
4971
|
+
hasSeed: true
|
|
4972
|
+
}, outcome);
|
|
4886
4973
|
overlayUnreadable = overlayResult.kind === "unreadable";
|
|
4887
4974
|
if (overlayResult.kind === "fresh" && overlayResult.payload) return await revivePayload(id, overlayResult.payload, outcome);
|
|
4888
4975
|
if (overlayResult.kind === "stale" && overlayResult.payload) {
|
|
4889
4976
|
if (options.staleWhileRevalidate) {
|
|
4890
|
-
backgroundRerender(
|
|
4977
|
+
backgroundRerender({
|
|
4978
|
+
id,
|
|
4979
|
+
component,
|
|
4980
|
+
props,
|
|
4981
|
+
cacheKey,
|
|
4982
|
+
options,
|
|
4983
|
+
hasSeed: overlayHasSeed
|
|
4984
|
+
}, snapshotRequestContext(store));
|
|
4891
4985
|
return await revivePayload(id, overlayResult.payload, outcome);
|
|
4892
4986
|
}
|
|
4893
|
-
return await inlineRerender(
|
|
4987
|
+
return await inlineRerender({
|
|
4988
|
+
id,
|
|
4989
|
+
component,
|
|
4990
|
+
props,
|
|
4991
|
+
cacheKey,
|
|
4992
|
+
options,
|
|
4993
|
+
hasSeed: overlayHasSeed
|
|
4994
|
+
}, outcome);
|
|
4894
4995
|
}
|
|
4895
4996
|
}
|
|
4896
4997
|
}
|
|
4897
4998
|
const seed = devStore ? options.prerender ? await resolveDevSeed(registration, props, keyParams, cacheKey) : null : hasSource ? await lookupArtifactSeed(id, cacheKey, options.ttl !== void 0) : null;
|
|
4898
|
-
if (seed !== null && overlayUnreadable) return await inlineRerender(
|
|
4999
|
+
if (seed !== null && overlayUnreadable) return await inlineRerender({
|
|
5000
|
+
id,
|
|
5001
|
+
component,
|
|
5002
|
+
props,
|
|
5003
|
+
cacheKey,
|
|
5004
|
+
options,
|
|
5005
|
+
hasSeed: true
|
|
5006
|
+
}, outcome);
|
|
4899
5007
|
if (seed !== null) {
|
|
4900
5008
|
if (options.ttl !== void 0) {
|
|
4901
5009
|
if ((Date.now() - seed.capturedAt) / 1e3 > options.ttl) {
|
|
4902
5010
|
if (options.staleWhileRevalidate) {
|
|
4903
|
-
backgroundRerender(
|
|
5011
|
+
backgroundRerender({
|
|
5012
|
+
id,
|
|
5013
|
+
component,
|
|
5014
|
+
props,
|
|
5015
|
+
cacheKey,
|
|
5016
|
+
options,
|
|
5017
|
+
hasSeed: true
|
|
5018
|
+
}, snapshotRequestContext(store));
|
|
4904
5019
|
return await revivePayload(id, seed.payload, outcome);
|
|
4905
5020
|
}
|
|
4906
|
-
return await inlineRerender(
|
|
5021
|
+
return await inlineRerender({
|
|
5022
|
+
id,
|
|
5023
|
+
component,
|
|
5024
|
+
props,
|
|
5025
|
+
cacheKey,
|
|
5026
|
+
options,
|
|
5027
|
+
hasSeed: true
|
|
5028
|
+
}, outcome);
|
|
4907
5029
|
}
|
|
4908
5030
|
}
|
|
4909
5031
|
return await revivePayload(id, seed.payload, outcome);
|
|
4910
5032
|
}
|
|
4911
5033
|
if (hasSource && options.prerender) console.warn(`[timber] cache.component cache miss: "${id}" with params ${JSON.stringify(store.segmentParams ?? {})} — ${outcome}`);
|
|
4912
|
-
if (hasRuntime && options.fallbackOnMissingSegmentParams !== false) return await inlineRerender(
|
|
5034
|
+
if (hasRuntime && options.fallbackOnMissingSegmentParams !== false) return await inlineRerender({
|
|
5035
|
+
id,
|
|
5036
|
+
component,
|
|
5037
|
+
props,
|
|
5038
|
+
cacheKey,
|
|
5039
|
+
options,
|
|
5040
|
+
hasSeed: false
|
|
5041
|
+
}, outcome);
|
|
4913
5042
|
return null;
|
|
4914
5043
|
}
|
|
4915
5044
|
/**
|