@timber-js/app 0.2.0-alpha.215 → 0.2.0-alpha.217
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/als-registry-BZqHCtq-.js.map +1 -1
- package/dist/_chunks/{chains-CjK1Eu6a.js → chains-YKZ8WpIW.js} +2 -2
- package/dist/_chunks/{chains-CjK1Eu6a.js.map → chains-YKZ8WpIW.js.map} +1 -1
- package/dist/_chunks/{classify-GAdt6aiA.js → classify-2Yp3xJY1.js} +3 -3
- package/dist/_chunks/{classify-GAdt6aiA.js.map → classify-2Yp3xJY1.js.map} +1 -1
- package/dist/_chunks/{cli-check-DOzjlycg.js → cli-check-D2WtbNqo.js} +3 -3
- package/dist/_chunks/{cli-check-DOzjlycg.js.map → cli-check-D2WtbNqo.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js → cli-schema-sync-CySLKrO3.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js.map → cli-schema-sync-CySLKrO3.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-DEp8ZHce.js → client-dep-entries-BOkpKjj1.js} +2 -2
- package/dist/_chunks/{client-dep-entries-DEp8ZHce.js.map → client-dep-entries-BOkpKjj1.js.map} +1 -1
- package/dist/_chunks/{convention-lint-B3QEGJX7.js → convention-lint-ByKJ6aqD.js} +2 -2
- package/dist/_chunks/{convention-lint-B3QEGJX7.js.map → convention-lint-ByKJ6aqD.js.map} +1 -1
- package/dist/_chunks/{dev-server-_9L4KWC-.js → dev-server-B8zsT-ee.js} +4 -4
- package/dist/_chunks/{dev-server-_9L4KWC-.js.map → dev-server-B8zsT-ee.js.map} +1 -1
- package/dist/_chunks/{live-graph-Cd3YHvrH.js → live-graph-BhtrZpRd.js} +4 -4
- package/dist/_chunks/{live-graph-Cd3YHvrH.js.map → live-graph-BhtrZpRd.js.map} +1 -1
- package/dist/_chunks/{metadata-routes-DSDjM_hJ.js → metadata-routes-B3XJNyIH.js} +1 -2
- package/dist/_chunks/metadata-routes-B3XJNyIH.js.map +1 -0
- package/dist/_chunks/{poison-scan-BnJjBOkn.js → poison-scan-C4FgMxFl.js} +2 -2
- package/dist/_chunks/{poison-scan-BnJjBOkn.js.map → poison-scan-C4FgMxFl.js.map} +1 -1
- package/dist/_chunks/{scanner-CKAT5gRx.js → scanner-Cb3fSjAC.js} +4 -4
- package/dist/_chunks/{scanner-CKAT5gRx.js.map → scanner-Cb3fSjAC.js.map} +1 -1
- package/dist/_chunks/{walkers-DwCXEyRu.js → walkers-Ber9bamD.js} +3 -3
- package/dist/_chunks/{walkers-DwCXEyRu.js.map → walkers-Ber9bamD.js.map} +1 -1
- package/dist/adapters/nitro-immutable-assets.d.ts +47 -0
- package/dist/adapters/nitro-immutable-assets.d.ts.map +1 -0
- package/dist/adapters/nitro-preview.d.ts +3 -2
- package/dist/adapters/nitro-preview.d.ts.map +1 -1
- package/dist/adapters/nitro.d.ts +16 -2
- package/dist/adapters/nitro.d.ts.map +1 -1
- package/dist/adapters/nitro.js +130 -10
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.js +3 -3
- package/dist/index.js +6 -6
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +2 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/internal.js +2 -2
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-collector.d.ts +2 -0
- package/dist/server/metadata-collector.d.ts.map +1 -1
- package/dist/server/metadata-route-links.d.ts +70 -0
- package/dist/server/metadata-route-links.d.ts.map +1 -0
- package/dist/server/metadata-routes.d.ts +0 -24
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +7 -0
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/docs/api/34-api-config.mdx +1 -1
- package/package.json +1 -1
- package/src/adapters/nitro-immutable-assets.ts +142 -0
- package/src/adapters/nitro-preview.ts +12 -3
- package/src/adapters/nitro.ts +31 -17
- package/src/server/als-registry.ts +2 -0
- package/src/server/metadata-collector.ts +15 -17
- package/src/server/metadata-route-links.ts +200 -0
- package/src/server/metadata-routes.ts +0 -106
- package/src/server/route-element-builder.ts +1 -0
- package/src/server/route-matcher.ts +2 -2
- package/dist/_chunks/metadata-routes-DSDjM_hJ.js.map +0 -1
|
@@ -29,6 +29,8 @@ export interface MetadataCollectorProps {
|
|
|
29
29
|
metadataExport: Metadata | (() => Promise<Metadata>);
|
|
30
30
|
segmentName: string;
|
|
31
31
|
isPage: boolean;
|
|
32
|
+
/** Index of the owning segment in the route chain. */
|
|
33
|
+
segmentIndex: number;
|
|
32
34
|
children: ReactNode;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAyC9D,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,CAmB1E;AAID,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,8FAA8F;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAgC/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-linking: turn the metadata route files in a page's segment chain into
|
|
3
|
+
* the <link>/<meta> tags its <head> carries, and decide precedence between
|
|
4
|
+
* those files and the metadata the app declares.
|
|
5
|
+
*
|
|
6
|
+
* Every link must name a file the metadata route matcher actually serves at
|
|
7
|
+
* that URL, so the OG winner is chosen by asking the matcher rather than by
|
|
8
|
+
* modelling its precedence here.
|
|
9
|
+
*
|
|
10
|
+
* See design/16-metadata.md §"Auto-Linking".
|
|
11
|
+
*/
|
|
12
|
+
import type { HeadElement } from './metadata.ts';
|
|
13
|
+
import type { Metadata } from './types.ts';
|
|
14
|
+
import { type ManifestSegmentNode } from './route-matcher.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Segment index whose metadata export supplied the resolved `openGraph.images`
|
|
17
|
+
* and `twitter.images`, or -1 when none did. A file-based `opengraph-image`
|
|
18
|
+
* replaces declared images only from a deeper segment.
|
|
19
|
+
*/
|
|
20
|
+
export interface DeclaredImageOwners {
|
|
21
|
+
openGraph: number;
|
|
22
|
+
twitter: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find which segment's export supplied the resolved `openGraph.images` and
|
|
26
|
+
* `twitter.images`: the deepest entry whose images are the resolved value.
|
|
27
|
+
* Read off the merge result rather than re-deriving `resolveMetadata`'s merge
|
|
28
|
+
* rule, so the two cannot drift.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findDeclaredImageOwners(entries: {
|
|
31
|
+
metadata: Metadata;
|
|
32
|
+
segmentIndex: number;
|
|
33
|
+
}[], resolved: Metadata): DeclaredImageOwners;
|
|
34
|
+
/** Auto-linked head elements, and the declared metadata they leave in force. */
|
|
35
|
+
export interface MetadataRouteLinks {
|
|
36
|
+
/** `resolvedMetadata` minus any declared images a deeper file replaced. */
|
|
37
|
+
metadata: Metadata;
|
|
38
|
+
elements: HeadElement[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Link metadata route files in the segment chain into the page's head.
|
|
42
|
+
*
|
|
43
|
+
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
44
|
+
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
45
|
+
* hoists into <head>.
|
|
46
|
+
*
|
|
47
|
+
* A metadata file is served under the URL of the segment that owns it, not
|
|
48
|
+
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
49
|
+
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
50
|
+
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
51
|
+
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
52
|
+
* walk slot matching uses), filled with the request's raw param values — the
|
|
53
|
+
* parts the metadata route matcher walks back to the same owner.
|
|
54
|
+
*
|
|
55
|
+
* Segments at or below an intercepting segment are skipped: the metadata
|
|
56
|
+
* matcher only walks the canonical tree, so nothing serves their files.
|
|
57
|
+
*
|
|
58
|
+
* Precedence, so no tag is ever emitted twice:
|
|
59
|
+
* - Icon and apple-icon files link from every segment, root to leaf, unless
|
|
60
|
+
* the metadata declares `icons.icon` / `icons.apple`. A declared manifest
|
|
61
|
+
* likewise replaces `app/manifest.*`.
|
|
62
|
+
* - Only the deepest served `opengraph-image` links. It replaces declared
|
|
63
|
+
* `openGraph.images` / `twitter.images` from a shallower segment (those are
|
|
64
|
+
* dropped from the returned metadata) and yields to images declared at its
|
|
65
|
+
* own segment or deeper.
|
|
66
|
+
*
|
|
67
|
+
* See design/16-metadata.md §"Auto-Linking"
|
|
68
|
+
*/
|
|
69
|
+
export declare function linkMetadataRoutes(segments: ManifestSegmentNode[], resolvedMetadata: Metadata, declaredImages: DeclaredImageOwners, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): MetadataRouteLinks;
|
|
70
|
+
//# sourceMappingURL=metadata-route-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-route-links.d.ts","sourceRoot":"","sources":["../../src/server/metadata-route-links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBlF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAAE,EACvD,QAAQ,EAAE,QAAQ,GACjB,mBAAmB,CASrB;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,mBAAmB,EAAE,EAC/B,gBAAgB,EAAE,QAAQ,EAC1B,cAAc,EAAE,mBAAmB,EACnC,UAAU,EAAE,GAAG,EACf,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EACnD,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,kBAAkB,CA8FpB"}
|
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
*
|
|
10
10
|
* See design/16-metadata.md §"Metadata Routes"
|
|
11
11
|
*/
|
|
12
|
-
import type { HeadElement } from './metadata.ts';
|
|
13
|
-
import type { Metadata } from './types.ts';
|
|
14
|
-
import type { ManifestSegmentNode } from './route-matcher.ts';
|
|
15
12
|
/** Classification of a metadata route file. */
|
|
16
13
|
export interface MetadataRouteInfo {
|
|
17
14
|
/** The metadata route type. */
|
|
@@ -130,25 +127,4 @@ export type AutoLinkTag = AutoLinkLink | AutoLinkMeta;
|
|
|
130
127
|
* @returns Tag descriptor(s) for the <head>, or null if no auto-link
|
|
131
128
|
*/
|
|
132
129
|
export declare function getMetadataRouteAutoLink(type: MetadataRouteType, href: string): AutoLinkTag[];
|
|
133
|
-
/**
|
|
134
|
-
* Collect auto-linked head elements from metadata route files in the segment chain.
|
|
135
|
-
*
|
|
136
|
-
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
137
|
-
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
138
|
-
* hoists into <head>.
|
|
139
|
-
*
|
|
140
|
-
* A metadata file is served under the URL of the segment that owns it, not
|
|
141
|
-
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
142
|
-
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
143
|
-
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
144
|
-
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
145
|
-
* walk slot matching uses), filled with the request's raw param values — the
|
|
146
|
-
* parts the metadata route matcher walks back to the same owner.
|
|
147
|
-
*
|
|
148
|
-
* Segments at or below an intercepting segment are skipped: the metadata
|
|
149
|
-
* matcher only walks the canonical tree, so nothing serves their files.
|
|
150
|
-
*
|
|
151
|
-
* See design/16-metadata.md §"Auto-Linking"
|
|
152
|
-
*/
|
|
153
|
-
export declare function collectMetadataRouteHeadElements(segments: ManifestSegmentNode[], firstDeniedIndex: number, resolvedMetadata: Metadata, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): HeadElement[];
|
|
154
130
|
//# sourceMappingURL=metadata-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,IAAI,EAAE,iBAAiB,CAAC;IACxB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,QAAQ,GACR,UAAU,GACV,SAAS,GACT,MAAM,GACN,iBAAiB,GACjB,YAAY,CAAC;AAIjB;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAC7C,MAAM,EACN;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IA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EAAE,cAAc,CAAC;IACxB,wDAAwD;IACxD,gBAAgB,EAAE,oBAAoB,EAAE,CAAC;IACzC,qCAAqC;IACrC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;OAIG;IACH,YAAY,EAAE,aAAa,EAAE,CAAC;IAC9B;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;CACjC;AA4DD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EACjB,YAAY,CAAC,EAAE,mBAAmB,EAClC,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,EACxC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,kBAAkB,CAAC,CAua7B"}
|
|
@@ -97,4 +97,11 @@ export interface MetadataRouteMatch {
|
|
|
97
97
|
* See design/16-metadata.md §"Metadata Routes"
|
|
98
98
|
*/
|
|
99
99
|
export declare function createMetadataRouteMatcher(manifest: ManifestRoot): (pathname: string) => MetadataRouteMatch | null;
|
|
100
|
+
/**
|
|
101
|
+
* Match a pathname against metadata routes in the segment tree.
|
|
102
|
+
*
|
|
103
|
+
* Checks if the last URL part is a known metadata route serve path,
|
|
104
|
+
* then walks the tree to find the segment that owns the route.
|
|
105
|
+
*/
|
|
106
|
+
export declare function matchMetadataRoute(root: ManifestSegmentNode, pathname: string): MetadataRouteMatch | null;
|
|
100
107
|
//# sourceMappingURL=route-matcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-matcher.d.ts","sourceRoot":"","sources":["../../src/server/route-matcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eA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,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAEnF;AAID,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,4DAA4D;IAC5D,IAAI,EAAE,iBAAiB,CAAC;IACxB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,IAAI,EAAE,YAAY,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,mBAAmB,CAAC;IAC7B;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAClD;AAcD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,YAAY,GACrB,CAAC,QAAQ,EAAE,MAAM,KAAK,kBAAkB,GAAG,IAAI,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,mBAAmB,EACzB,QAAQ,EAAE,MAAM,GACf,kBAAkB,GAAG,IAAI,CAqE3B"}
|
|
@@ -356,4 +356,4 @@ type BuildArtifacts =
|
|
|
356
356
|
};
|
|
357
357
|
```
|
|
358
358
|
|
|
359
|
-
Every path is absolute. `prebuilt` and `manifestInit` are absent when the build did not produce them, so check the field rather than whether a directory exists on disk. `immutableDirs` lists the directories of the served site whose file names are content-hashed — such as `assets`, `_timber/fonts`, and a static build's `_rsc` — relative to the site root, without a leading slash or the deployment `base`. Give those a long-lived `immutable` cache
|
|
359
|
+
Every path is absolute. `prebuilt` and `manifestInit` are absent when the build did not produce them, so check the field rather than whether a directory exists on disk. `immutableDirs` lists the directories of the served site whose file names are content-hashed — such as `assets`, `_timber/fonts`, and a static build's `_rsc` — relative to the site root, without a leading slash or the deployment `base`. Give the files in those directories a long-lived `immutable` cache header instead of hard-coding the paths. Set it only on a response that served a file. A rule that matches by path alone also covers the 404 for a file that is missing, for example during a rolling deploy when one server has a new asset and another does not. A CDN would then cache that 404 for a year. `preview()` runs in a separate process after the build, so instead of `BuildArtifacts` it receives the build output directory and the configured `output` mode.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.217",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Immutable caching for the build's content-hashed directories on Nitro.
|
|
2
|
+
//
|
|
3
|
+
// A one-year `immutable` Cache-Control is correct only on a response that
|
|
4
|
+
// served a file. Nitro route rules cannot tell a hit from a miss — their
|
|
5
|
+
// headers land on every response under the path, the 404 for a file that is
|
|
6
|
+
// not there included — so a CDN in front of a pod that lacked the file mid
|
|
7
|
+
// rollout cached that 404 for a year (TIM-1578). Nitro's public-asset `maxAge`
|
|
8
|
+
// option is a route rule underneath, with the same reach.
|
|
9
|
+
//
|
|
10
|
+
// Instead, three pieces, all keyed by one generated path matcher:
|
|
11
|
+
//
|
|
12
|
+
// - Each directory is its own non-fallthrough public-asset directory. Where
|
|
13
|
+
// Nitro serves files itself, a GET or HEAD miss there is a 404 from its
|
|
14
|
+
// static handler; Vercel and Netlify route such misses to a platform 404
|
|
15
|
+
// instead of the function.
|
|
16
|
+
// - timber's Nitro entry answers any request under those directories that
|
|
17
|
+
// still reaches it with a plain `no-store` 404, before the app runs. Nothing
|
|
18
|
+
// else answers there: a preset without Nitro's static handler (aws-lambda),
|
|
19
|
+
// a method the static handler ignores, or a path it does not claim
|
|
20
|
+
// (`/assets/`) gets the 404 rather than a page.
|
|
21
|
+
// - A Nitro runtime plugin sets Cache-Control from the outcome. Since only a
|
|
22
|
+
// served file can succeed under those directories, a successful GET or HEAD
|
|
23
|
+
// is a hit.
|
|
24
|
+
//
|
|
25
|
+
// See design/25-production-deployments.md §"Hashed assets".
|
|
26
|
+
|
|
27
|
+
import { writeFile } from 'node:fs/promises';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
import { IMMUTABLE_CACHE } from './shared.ts';
|
|
30
|
+
|
|
31
|
+
/** The generated module, written beside the Nitro entry that imports it. */
|
|
32
|
+
const IMMUTABLE_ASSETS_MODULE = '_immutable-assets.mjs';
|
|
33
|
+
|
|
34
|
+
/** One Nitro `publicAssets` entry. */
|
|
35
|
+
interface NitroPublicAssetDir {
|
|
36
|
+
dir: string;
|
|
37
|
+
baseURL: string;
|
|
38
|
+
fallthrough: false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The Nitro config that serves `immutableDirs` from `<nitroDir>/public`. */
|
|
42
|
+
export interface ImmutableAssetsNitroConfig {
|
|
43
|
+
publicAssets: NitroPublicAssetDir[];
|
|
44
|
+
plugins: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Write the generated module into `nitroDir` and return the Nitro config that
|
|
49
|
+
* serves the build's content-hashed directories from `<nitroDir>/public`.
|
|
50
|
+
*
|
|
51
|
+
* No `maxAge`: Nitro would turn it into a route rule (see the module header),
|
|
52
|
+
* and Vercel already gives a non-fallthrough directory a one-year immutable
|
|
53
|
+
* header on hits and `no-store` on misses by default.
|
|
54
|
+
*/
|
|
55
|
+
export async function prepareImmutableAssets(
|
|
56
|
+
nitroDir: string,
|
|
57
|
+
immutableDirs: readonly string[]
|
|
58
|
+
): Promise<ImmutableAssetsNitroConfig> {
|
|
59
|
+
if (immutableDirs.length === 0) return { publicAssets: [], plugins: [] };
|
|
60
|
+
const plugin = join(nitroDir, IMMUTABLE_ASSETS_MODULE);
|
|
61
|
+
await writeFile(plugin, generateImmutableAssetsModule(immutableDirs));
|
|
62
|
+
return {
|
|
63
|
+
publicAssets: immutableDirs.map((dir) => ({
|
|
64
|
+
dir: join(nitroDir, 'public', dir),
|
|
65
|
+
baseURL: `/${dir}`,
|
|
66
|
+
fallthrough: false,
|
|
67
|
+
})),
|
|
68
|
+
plugins: [plugin],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The lines timber's Nitro entry needs to answer a request under the
|
|
74
|
+
* content-hashed directories itself: an import, and a guard to run before
|
|
75
|
+
* the handler, with the h3 event in scope as `event`. Empty when the build
|
|
76
|
+
* has no such directories, which also means `prepareImmutableAssets()`
|
|
77
|
+
* writes no module to import.
|
|
78
|
+
*/
|
|
79
|
+
export function immutableAssetsEntryGuard(immutableDirs: readonly string[]): {
|
|
80
|
+
imports: string;
|
|
81
|
+
guard: string;
|
|
82
|
+
} {
|
|
83
|
+
if (immutableDirs.length === 0) return { imports: '', guard: '' };
|
|
84
|
+
return {
|
|
85
|
+
imports: `import { isImmutableAssetPath } from './${IMMUTABLE_ASSETS_MODULE}'\n`,
|
|
86
|
+
guard: ` // Under a content-hashed directory only a served file may answer; the
|
|
87
|
+
// static handler already sent any file there is. A no-store 404, never a
|
|
88
|
+
// page — see _immutable-assets.mjs.
|
|
89
|
+
if (isImmutableAssetPath(event.url.pathname)) {
|
|
90
|
+
return new Response('Not Found', {
|
|
91
|
+
status: 404,
|
|
92
|
+
headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' },
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Generate the module shared by the Nitro entry and runtime: the path matcher
|
|
101
|
+
* for the content-hashed directories, and the runtime plugin that owns
|
|
102
|
+
* Cache-Control under them — `IMMUTABLE_CACHE` on a GET or HEAD that served
|
|
103
|
+
* the file (200, or 304 revalidating it), `no-store` on everything else.
|
|
104
|
+
*
|
|
105
|
+
* Status is a sound signal only because the entry answers everything else
|
|
106
|
+
* under these directories with a 404 (see `immutableAssetsEntryGuard`). The
|
|
107
|
+
* prefixes are matched against the decoded path, the one Nitro's static
|
|
108
|
+
* handler looks the file up by.
|
|
109
|
+
*
|
|
110
|
+
* @internal Exported for testing.
|
|
111
|
+
*/
|
|
112
|
+
export function generateImmutableAssetsModule(immutableDirs: readonly string[]): string {
|
|
113
|
+
const prefixes = immutableDirs.map((dir) => `/${dir}/`);
|
|
114
|
+
return `// Generated by @timber-js/app — Cache-Control for content-hashed directories.
|
|
115
|
+
// Do not edit — this file is regenerated on each build.
|
|
116
|
+
|
|
117
|
+
const PREFIXES = ${JSON.stringify(prefixes)};
|
|
118
|
+
const IMMUTABLE_CACHE = ${JSON.stringify(IMMUTABLE_CACHE)};
|
|
119
|
+
|
|
120
|
+
export function isImmutableAssetPath(pathname) {
|
|
121
|
+
let path = pathname;
|
|
122
|
+
try {
|
|
123
|
+
path = decodeURI(pathname);
|
|
124
|
+
} catch {
|
|
125
|
+
// Malformed escapes: match the path as received.
|
|
126
|
+
}
|
|
127
|
+
return PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default function immutableAssets(nitroApp) {
|
|
131
|
+
// Hooks are off only if a user's nitroConfig disables them; files then go
|
|
132
|
+
// without the long-lived header rather than failing every request.
|
|
133
|
+
nitroApp.hooks?.hook('response', (res, event) => {
|
|
134
|
+
if (!isImmutableAssetPath(event.url.pathname)) return;
|
|
135
|
+
const method = event.req.method;
|
|
136
|
+
const served =
|
|
137
|
+
(method === 'GET' || method === 'HEAD') && (res.status === 200 || res.status === 304);
|
|
138
|
+
res.headers.set('Cache-Control', served ? IMMUTABLE_CACHE : 'no-store');
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
@@ -74,8 +74,9 @@ export type PreviewScriptOptions = StaticPreviewScriptOptions | ServerPreviewScr
|
|
|
74
74
|
|
|
75
75
|
interface PreviewScriptOptionsBase {
|
|
76
76
|
/**
|
|
77
|
-
* `BuildArtifacts.immutableDirs` — served with a one-year
|
|
78
|
-
* `Cache-Control`, every other file with a revalidating one.
|
|
77
|
+
* `BuildArtifacts.immutableDirs` — files there are served with a one-year
|
|
78
|
+
* immutable `Cache-Control`, every other file with a revalidating one. In
|
|
79
|
+
* a server build, a miss there is a plain `no-store` 404.
|
|
79
80
|
*/
|
|
80
81
|
immutableDirs: readonly string[];
|
|
81
82
|
/**
|
|
@@ -167,7 +168,15 @@ const { sendNodeResponse } = await import('./_send-response.mjs');
|
|
|
167
168
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
168
169
|
res.end('Not Found');
|
|
169
170
|
`
|
|
170
|
-
: `
|
|
171
|
+
: ` // A request under a content-hashed directory that names no file is a
|
|
172
|
+
// plain no-store 404, never a render of the app — as timber's Nitro entry
|
|
173
|
+
// answers it in production (TIM-1578).
|
|
174
|
+
if (pathname !== null && IMMUTABLE_PREFIXES.some((prefix) => pathname.startsWith(prefix))) {
|
|
175
|
+
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
176
|
+
res.end('Not Found');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
await handleDynamic(req, res, url);
|
|
171
180
|
`;
|
|
172
181
|
|
|
173
182
|
const dynamicHandler =
|
package/src/adapters/nitro.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
9
|
import { cp, glob, readFile, writeFile } from 'node:fs/promises';
|
|
10
10
|
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
11
|
+
import type { NitroConfig } from 'nitro/types';
|
|
11
12
|
import {
|
|
12
13
|
buildStaticDirectoryOutput,
|
|
13
14
|
runSharedBuildSteps,
|
|
@@ -15,13 +16,14 @@ import {
|
|
|
15
16
|
} from './build-output-helper.ts';
|
|
16
17
|
import { generateCompressModule } from './compress-module.ts';
|
|
17
18
|
import { generateCanonicalizeModule } from './canonicalize-module.ts';
|
|
19
|
+
import { immutableAssetsEntryGuard, prepareImmutableAssets } from './nitro-immutable-assets.ts';
|
|
18
20
|
import { LOCALLY_PREVIEWABLE, PRESET_CONFIGS, type NitroPreset } from './nitro-presets.ts';
|
|
19
21
|
import {
|
|
20
22
|
generatePreviewScript,
|
|
21
23
|
generateSendResponseModule,
|
|
22
24
|
spawnNitroPreview,
|
|
23
25
|
} from './nitro-preview.ts';
|
|
24
|
-
import { adapterBase
|
|
26
|
+
import { adapterBase } from './shared.ts';
|
|
25
27
|
import type {
|
|
26
28
|
BuildArtifacts,
|
|
27
29
|
PreviewTarget,
|
|
@@ -80,7 +82,7 @@ export interface NitroAdapterOptions {
|
|
|
80
82
|
* Additional Nitro configuration to merge into the generated config.
|
|
81
83
|
* Overrides default values for the selected preset.
|
|
82
84
|
*/
|
|
83
|
-
nitroConfig?:
|
|
85
|
+
nitroConfig?: NitroConfig;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
// ─── Adapter ─────────────────────────────────────────────────────────────────
|
|
@@ -206,7 +208,7 @@ export function nitro(options: NitroAdapterOptions = {}): TimberPlatformAdapter
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
// Generate the Nitro entry point (imports from ./rsc/ within nitro dir)
|
|
209
|
-
const entry = generateNitroEntry(preset, compress);
|
|
211
|
+
const entry = generateNitroEntry(preset, compress, artifacts.immutableDirs);
|
|
210
212
|
await writeFile(join(outDir, 'entry.ts'), entry);
|
|
211
213
|
|
|
212
214
|
// Run the Nitro build to produce a production-ready server bundle.
|
|
@@ -283,7 +285,11 @@ function importSpecifier(fromDir: string, file: string): string {
|
|
|
283
285
|
// ─── Entry Generation ────────────────────────────────────────────────────────
|
|
284
286
|
|
|
285
287
|
/** @internal Exported for testing. */
|
|
286
|
-
export function generateNitroEntry(
|
|
288
|
+
export function generateNitroEntry(
|
|
289
|
+
preset: NitroPreset,
|
|
290
|
+
compress = true,
|
|
291
|
+
immutableDirs: readonly string[] = []
|
|
292
|
+
): string {
|
|
287
293
|
// The RSC entry is the main request handler — it exports the fetch handler as default.
|
|
288
294
|
// rsc/ is copied into the nitro dir so the import is local.
|
|
289
295
|
// The manifest init is prepended to rsc/index.js before the nitro build,
|
|
@@ -344,12 +350,13 @@ export function generateNitroEntry(preset: NitroPreset, compress = true): string
|
|
|
344
350
|
|
|
345
351
|
const compressImport = compress ? "import { compressResponse } from './_compress.mjs'\n" : '';
|
|
346
352
|
const compressCall = compress ? 'compressResponse(webRequest, webResponse)' : 'webResponse';
|
|
353
|
+
const immutableAssets = immutableAssetsEntryGuard(immutableDirs);
|
|
347
354
|
|
|
348
355
|
return `// Generated by @timber-js/app/adapters/nitro
|
|
349
356
|
// Do not edit — this file is regenerated on each build.
|
|
350
357
|
|
|
351
358
|
import handler, { runWithEarlyHintsSender${waitUntilImport} } from '${serverEntryRelative}'
|
|
352
|
-
${compressImport}
|
|
359
|
+
${compressImport}${immutableAssets.imports}
|
|
353
360
|
// Set TIMBER_RUNTIME for instrumentation.ts conditional SDK initialization.
|
|
354
361
|
// See design/25-production-deployments.md §"TIMBER_RUNTIME".
|
|
355
362
|
process.env.TIMBER_RUNTIME = '${runtimeName}'
|
|
@@ -360,7 +367,7 @@ process.env.TIMBER_RUNTIME = '${runtimeName}'
|
|
|
360
367
|
// Nitro bundles h3 into its internal _libs/ directory but doesn't make
|
|
361
368
|
// it available as a bare specifier in the output's node_modules.
|
|
362
369
|
export default async function timberHandler(event) {
|
|
363
|
-
// h3 v2: event.req is the Web Request
|
|
370
|
+
${immutableAssets.guard} // h3 v2: event.req is the Web Request
|
|
364
371
|
const webRequest = event.req
|
|
365
372
|
${handlerCall}
|
|
366
373
|
return ${compressCall}
|
|
@@ -452,24 +459,27 @@ export function getPostBuildHint(preset: NitroPreset): string | null {
|
|
|
452
459
|
: null;
|
|
453
460
|
}
|
|
454
461
|
|
|
462
|
+
interface NitroBuildResult {
|
|
463
|
+
/** Resolved output.serverDir — where the server bundle + _chunks/ live. */
|
|
464
|
+
serverDir: string;
|
|
465
|
+
}
|
|
466
|
+
|
|
455
467
|
/**
|
|
456
468
|
* Run the Nitro production build using the programmatic API.
|
|
457
469
|
* Uses dynamic import so nitro is only loaded at build time.
|
|
458
470
|
* Externalizes the timber RSC/SSR output — those files are pre-built
|
|
459
471
|
* by timber and have internal references that nitro's bundler can't follow.
|
|
472
|
+
*
|
|
473
|
+
* @internal Exported for testing.
|
|
460
474
|
*/
|
|
461
|
-
|
|
462
|
-
/** Resolved output.serverDir — where the server bundle + _chunks/ live. */
|
|
463
|
-
serverDir: string;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
async function runNitroBuild(
|
|
475
|
+
export async function runNitroBuild(
|
|
467
476
|
nitroDir: string,
|
|
468
477
|
preset: NitroPreset,
|
|
469
478
|
immutableDirs: readonly string[],
|
|
470
|
-
userConfig?:
|
|
479
|
+
userConfig?: NitroConfig
|
|
471
480
|
): Promise<NitroBuildResult> {
|
|
472
481
|
const presetConfig = PRESET_CONFIGS[preset];
|
|
482
|
+
const immutableAssets = await prepareImmutableAssets(nitroDir, immutableDirs);
|
|
473
483
|
const {
|
|
474
484
|
createNitro,
|
|
475
485
|
build: nitroBuild,
|
|
@@ -485,10 +495,6 @@ async function runNitroBuild(
|
|
|
485
495
|
// Using `entry` directly would bypass the Nitro server runtime.
|
|
486
496
|
renderer: { handler: join(nitroDir, 'entry.ts') },
|
|
487
497
|
output: { dir: join(nitroDir, presetConfig.outputDir) },
|
|
488
|
-
// One rule per content-hashed directory the build recorded.
|
|
489
|
-
routeRules: Object.fromEntries(
|
|
490
|
-
immutableDirs.map((dir) => [`/${dir}/**`, { headers: { 'Cache-Control': IMMUTABLE_CACHE } }])
|
|
491
|
-
),
|
|
492
498
|
// Don't bundle the timber RSC/SSR build output — it has its own
|
|
493
499
|
// internal file references that nitro's bundler can't follow.
|
|
494
500
|
// Mark them as external so rollup leaves the imports as-is.
|
|
@@ -497,6 +503,14 @@ async function runNitroBuild(
|
|
|
497
503
|
},
|
|
498
504
|
...presetConfig.extraConfig,
|
|
499
505
|
...userConfig,
|
|
506
|
+
// The content-hashed directories the build recorded: immutable on a hit,
|
|
507
|
+
// a no-store 404 on a miss. Not route rules, which cannot tell the two
|
|
508
|
+
// apart (TIM-1578) — see nitro-immutable-assets.ts. Set after the user's
|
|
509
|
+
// config, which may add public-asset directories and plugins but not drop
|
|
510
|
+
// these: without them a handler could answer 200 under a hashed directory
|
|
511
|
+
// and be marked immutable.
|
|
512
|
+
publicAssets: [...immutableAssets.publicAssets, ...(userConfig?.publicAssets ?? [])],
|
|
513
|
+
plugins: [...immutableAssets.plugins, ...(userConfig?.plugins ?? [])],
|
|
500
514
|
});
|
|
501
515
|
|
|
502
516
|
// Drop nitro's `npx nitro preview` / `npx nitro deploy` hints —
|
|
@@ -184,6 +184,8 @@ export interface RequestContextStore {
|
|
|
184
184
|
_metadataEntries?: Array<{
|
|
185
185
|
metadata: import('./types.ts').Metadata | Promise<import('./types.ts').Metadata | null>;
|
|
186
186
|
isPage: boolean;
|
|
187
|
+
/** Index of the owning segment in the route chain. */
|
|
188
|
+
segmentIndex: number;
|
|
187
189
|
}>;
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -27,12 +27,13 @@ import { createElement, Fragment } from 'react';
|
|
|
27
27
|
import type { ReactNode } from 'react';
|
|
28
28
|
|
|
29
29
|
import { requestContextAls } from './als-registry.ts';
|
|
30
|
+
import type { RequestContextStore } from './als-registry.ts';
|
|
30
31
|
import type { Metadata } from './types.ts';
|
|
31
32
|
import type { ManifestSegmentNode } from './route-matcher.ts';
|
|
32
33
|
import { withSpan } from './tracing.ts';
|
|
33
34
|
import { resolveMetadata, renderMetadataToElements, headElementsToReact } from './metadata.ts';
|
|
34
35
|
import type { SegmentMetadataEntry } from './metadata.ts';
|
|
35
|
-
import {
|
|
36
|
+
import { findDeclaredImageOwners, linkMetadataRoutes } from './metadata-route-links.ts';
|
|
36
37
|
|
|
37
38
|
// ─── Request-scoped metadata entry store ────────────────────────────────
|
|
38
39
|
|
|
@@ -41,16 +42,13 @@ import { collectMetadataRouteHeadElements } from './metadata-routes.ts';
|
|
|
41
42
|
* concurrent resolution (TIM-1367). Dynamic metadata pushes a promise;
|
|
42
43
|
* static metadata pushes the resolved object directly.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
-
metadata: Metadata | Promise<Metadata | null>;
|
|
46
|
-
isPage: boolean;
|
|
47
|
-
}
|
|
45
|
+
type DeferredMetadataEntry = NonNullable<RequestContextStore['_metadataEntries']>[number];
|
|
48
46
|
|
|
49
47
|
function getDeferredMetadataEntries(): DeferredMetadataEntry[] {
|
|
50
48
|
const store = requestContextAls.getStore();
|
|
51
49
|
if (!store) return [];
|
|
52
50
|
store._metadataEntries ??= [];
|
|
53
|
-
return store._metadataEntries
|
|
51
|
+
return store._metadataEntries;
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
// ─── MetadataSettle ─────────────────────────────────────────────────────
|
|
@@ -76,6 +74,8 @@ export interface MetadataCollectorProps {
|
|
|
76
74
|
metadataExport: Metadata | (() => Promise<Metadata>);
|
|
77
75
|
segmentName: string;
|
|
78
76
|
isPage: boolean;
|
|
77
|
+
/** Index of the owning segment in the route chain. */
|
|
78
|
+
segmentIndex: number;
|
|
79
79
|
children: ReactNode;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -92,7 +92,7 @@ export interface MetadataCollectorProps {
|
|
|
92
92
|
* awaits the promise for error ownership.
|
|
93
93
|
*/
|
|
94
94
|
export function MetadataCollector(props: MetadataCollectorProps): ReactNode {
|
|
95
|
-
const { metadataExport, segmentName, isPage, children } = props;
|
|
95
|
+
const { metadataExport, segmentName, isPage, segmentIndex, children } = props;
|
|
96
96
|
|
|
97
97
|
if (typeof metadataExport === 'function') {
|
|
98
98
|
const promise = withSpan('timber.metadata', { 'timber.segment': segmentName }, () =>
|
|
@@ -103,12 +103,12 @@ export function MetadataCollector(props: MetadataCollectorProps): ReactNode {
|
|
|
103
103
|
// Node's unhandledRejection before they do.
|
|
104
104
|
promise.catch(() => {});
|
|
105
105
|
|
|
106
|
-
getDeferredMetadataEntries().push({ metadata: promise, isPage });
|
|
106
|
+
getDeferredMetadataEntries().push({ metadata: promise, isPage, segmentIndex });
|
|
107
107
|
|
|
108
108
|
return createElement(Fragment, null, children, createElement(MetadataSettle, { promise }));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
getDeferredMetadataEntries().push({ metadata: metadataExport, isPage });
|
|
111
|
+
getDeferredMetadataEntries().push({ metadata: metadataExport, isPage, segmentIndex });
|
|
112
112
|
return children;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -152,26 +152,24 @@ export async function MetadataHead(props: MetadataHeadProps): Promise<ReactNode>
|
|
|
152
152
|
e.metadata instanceof Promise ? e.metadata : Promise.resolve(e.metadata)
|
|
153
153
|
)
|
|
154
154
|
);
|
|
155
|
-
const entries: SegmentMetadataEntry[] = [];
|
|
155
|
+
const entries: (SegmentMetadataEntry & { segmentIndex: number })[] = [];
|
|
156
156
|
for (let i = 0; i < settled.length; i++) {
|
|
157
157
|
const s = settled[i];
|
|
158
158
|
if (s.status === 'fulfilled' && s.value) {
|
|
159
|
-
|
|
159
|
+
const { isPage, segmentIndex } = deferredEntries[i];
|
|
160
|
+
entries.push({ metadata: s.value, isPage, segmentIndex });
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
const resolved = resolveMetadata(entries);
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const autoLinked = collectMetadataRouteHeadElements(
|
|
165
|
+
const { metadata, elements } = linkMetadataRoutes(
|
|
167
166
|
segments,
|
|
168
|
-
Infinity,
|
|
169
167
|
resolved,
|
|
168
|
+
findDeclaredImageOwners(entries, resolved),
|
|
170
169
|
new URL(requestUrl),
|
|
171
170
|
rawSegmentParams,
|
|
172
171
|
metadataRouteHashes
|
|
173
172
|
);
|
|
174
|
-
headElements.push(...autoLinked);
|
|
175
173
|
|
|
176
|
-
return headElementsToReact(
|
|
174
|
+
return headElementsToReact([...renderMetadataToElements(metadata), ...elements]);
|
|
177
175
|
}
|