netjes 0.0.4 → 0.0.6

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.
Files changed (123) hide show
  1. package/README.md +12 -8
  2. package/cli/commands.mjs +94 -15
  3. package/cli/process-io.mjs +2 -2
  4. package/cli/scaffold.mjs +89 -8
  5. package/dist/actions.d.ts +3 -2
  6. package/dist/actions.d.ts.map +1 -1
  7. package/dist/actions.js +5 -4
  8. package/dist/actions.js.map +1 -1
  9. package/dist/client-entry.js +4 -1
  10. package/dist/client-entry.js.map +1 -1
  11. package/dist/document.d.ts +3 -1
  12. package/dist/document.d.ts.map +1 -1
  13. package/dist/document.js +4 -3
  14. package/dist/document.js.map +1 -1
  15. package/dist/index.d.ts +4 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/lang.d.ts +10 -0
  20. package/dist/lang.d.ts.map +1 -0
  21. package/dist/lang.js +26 -0
  22. package/dist/lang.js.map +1 -0
  23. package/dist/link.d.ts +15 -3
  24. package/dist/link.d.ts.map +1 -1
  25. package/dist/link.js +15 -9
  26. package/dist/link.js.map +1 -1
  27. package/dist/locale.d.ts +5 -0
  28. package/dist/locale.d.ts.map +1 -1
  29. package/dist/locale.js +4 -0
  30. package/dist/locale.js.map +1 -1
  31. package/dist/metadata.d.ts +81 -4
  32. package/dist/metadata.d.ts.map +1 -1
  33. package/dist/metadata.js +129 -7
  34. package/dist/metadata.js.map +1 -1
  35. package/dist/modules.d.ts +6 -1
  36. package/dist/modules.d.ts.map +1 -1
  37. package/dist/modules.js +15 -1
  38. package/dist/modules.js.map +1 -1
  39. package/dist/mounted.d.ts +3 -7
  40. package/dist/mounted.d.ts.map +1 -1
  41. package/dist/mounted.js.map +1 -1
  42. package/dist/navigation-guard.d.ts +59 -0
  43. package/dist/navigation-guard.d.ts.map +1 -0
  44. package/dist/navigation-guard.js +116 -0
  45. package/dist/navigation-guard.js.map +1 -0
  46. package/dist/offline.d.ts +11 -0
  47. package/dist/offline.d.ts.map +1 -0
  48. package/dist/offline.js +98 -0
  49. package/dist/offline.js.map +1 -0
  50. package/dist/payload.d.ts +38 -2
  51. package/dist/payload.d.ts.map +1 -1
  52. package/dist/payload.js +54 -7
  53. package/dist/payload.js.map +1 -1
  54. package/dist/render-document.d.ts +8 -1
  55. package/dist/render-document.d.ts.map +1 -1
  56. package/dist/render-document.js +2 -0
  57. package/dist/render-document.js.map +1 -1
  58. package/dist/root.d.ts.map +1 -1
  59. package/dist/root.js +10 -1
  60. package/dist/root.js.map +1 -1
  61. package/dist/route-tree.d.ts +2 -1
  62. package/dist/route-tree.d.ts.map +1 -1
  63. package/dist/route-tree.js +14 -7
  64. package/dist/route-tree.js.map +1 -1
  65. package/dist/router.d.ts +101 -20
  66. package/dist/router.d.ts.map +1 -1
  67. package/dist/router.js +590 -68
  68. package/dist/router.js.map +1 -1
  69. package/dist/schema.d.ts +2 -0
  70. package/dist/schema.d.ts.map +1 -1
  71. package/dist/schema.js +5 -0
  72. package/dist/schema.js.map +1 -1
  73. package/dist/service-worker.d.ts +81 -0
  74. package/dist/service-worker.d.ts.map +1 -0
  75. package/dist/service-worker.js +584 -0
  76. package/dist/service-worker.js.map +1 -0
  77. package/dist/testing.d.ts +18 -0
  78. package/dist/testing.d.ts.map +1 -1
  79. package/dist/testing.js +63 -22
  80. package/dist/testing.js.map +1 -1
  81. package/package.json +16 -5
  82. package/sidecar/server.mjs +105 -16
  83. package/skills/netjes/SKILL.md +5 -3
  84. package/skills/netjes/references/caching-and-streaming.md +22 -1
  85. package/skills/netjes/references/data-and-actions.md +5 -4
  86. package/skills/netjes/references/deployment.md +3 -3
  87. package/skills/netjes/references/routing.md +14 -6
  88. package/skills/netjes/references/testing.md +6 -3
  89. package/src/actions.tsx +5 -4
  90. package/src/client-entry.tsx +4 -1
  91. package/src/document.tsx +17 -5
  92. package/src/index.ts +12 -2
  93. package/src/lang.ts +28 -0
  94. package/src/link.tsx +37 -9
  95. package/src/locale.ts +5 -0
  96. package/src/metadata.tsx +207 -11
  97. package/src/modules.ts +19 -3
  98. package/src/mounted.tsx +3 -3
  99. package/src/navigation-guard.ts +136 -0
  100. package/src/offline.ts +97 -0
  101. package/src/payload.ts +78 -8
  102. package/src/render-document.tsx +10 -1
  103. package/src/root.tsx +22 -10
  104. package/src/route-tree.tsx +18 -7
  105. package/src/router.tsx +765 -104
  106. package/src/schema.ts +11 -0
  107. package/src/service-worker.ts +632 -0
  108. package/src/testing-vitest.ts +1 -1
  109. package/src/testing.tsx +68 -15
  110. package/template/Dockerfile +1 -1
  111. package/template/Dockerfile.pnpm +68 -0
  112. package/template/Dockerfile.workspace +52 -0
  113. package/template/Dockerfile.workspace.dockerignore +15 -0
  114. package/template/README.md +6 -2
  115. package/template/_AGENTS.md +9 -3
  116. package/template/app/layout.tsx +0 -1
  117. package/template/docker-compose.override.yml +15 -3
  118. package/template/generated/netjes.ts +1 -1
  119. package/tsconfig.strict-app.json +27 -0
  120. package/vite/packages.mjs +97 -0
  121. package/vite/plugin.d.ts +8 -1
  122. package/vite/plugin.mjs +156 -9
  123. /package/template/{public/favicon.svg → app/icon.svg} +0 -0
package/src/payload.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { isLanguageTag } from './lang.ts';
1
2
  import type { Metadata } from './metadata.tsx';
2
3
 
3
4
  // The JSON contract with the .NET side (src/Netjes/Rendering/PagePayload.cs). Keep the two in sync.
@@ -12,6 +13,11 @@ export const ANTIFORGERY_HEADER = 'X-Netjes-Antiforgery';
12
13
  * pages the router keeps for back and forward show the app as it was before.
13
14
  */
14
15
  export const COOKIES_HEADER = 'X-Netjes-Cookies';
16
+ /**
17
+ * `1` on the router's request for the URL a redirect sent it to (a redirect payload, or a server action's redirect):
18
+ * where no page answers that URL, the server answers `{ kind: 'document' }` without running the endpoint.
19
+ */
20
+ export const REDIRECTED_HEADER = 'X-Netjes-Redirected';
15
21
  export const DATA_ELEMENT_ID = '__NETJES_DATA__';
16
22
  /** The id of the empty element that ends the body of every server-rendered document, and so the shell. */
17
23
  export const SHELL_END_ID = '__NETJES_SHELL_END__';
@@ -46,6 +52,8 @@ export type SegmentRef = {
46
52
  depth?: number | undefined;
47
53
  /** Each slot page's own route values (its parameter names can differ from the page's). */
48
54
  slotParams?: Record<string, Params> | undefined;
55
+ /** The layout loader's `PageMetadata.Lang`. A reused segment's is the one the client holds, as its props. */
56
+ lang?: string | undefined;
49
57
  };
50
58
 
51
59
  export type SpecialPageRef = { page: string; segments: SegmentRef[] };
@@ -68,9 +76,14 @@ export type AntiforgeryToken = {
68
76
  /** A TanStack Query cache entry seeded by the C# loader (`PageResult.WithQuery`). `updatedAt` is Unix milliseconds. */
69
77
  export type SeededQuery = { key: readonly unknown[]; data: unknown; updatedAt: number };
70
78
 
71
- /** Left by a server action posted without JavaScript that failed validation; the form's page renders with it. */
79
+ /**
80
+ * Left by a form post that failed (a page action's, or a server action's posted without JavaScript); the form's page
81
+ * renders with it. `status` is 422 after a failed validation and 429 after the rate limiter refused the post
82
+ * (`Page.TooManyRequests`); 422 when absent.
83
+ */
72
84
  export type ActionStateRef = {
73
85
  action: string;
86
+ status?: number;
74
87
  errors: Record<string, string[]>;
75
88
  values: Record<string, string | string[]>;
76
89
  };
@@ -115,12 +128,16 @@ export type PagePayload = {
115
128
  intercepts?: InterceptRef[];
116
129
  /** From the C# loader (`.WithMetadata(...)`), merged over the files' `export const metadata`. */
117
130
  metadata?: Metadata;
131
+ /** The page loader's `PageMetadata.Lang`: the document's lang, before its layouts' and the root's (`documentLang`). */
132
+ lang?: string;
118
133
  /** The page was rendered in draft mode. */
119
134
  draftMode?: boolean;
120
135
  /** `UsePathBase`'s base path, when the app is not mounted at the root; `url` includes it. */
121
136
  basePath?: string;
122
137
  /** The request culture, with `AddNetjesLocalization`. */
123
138
  locale?: string;
139
+ /** The current page’s alternate locale URLs, relative to the app root. */
140
+ localeAlternates?: Record<string, string>;
124
141
  /**
125
142
  * Each mounted page package's URL for this request, by npm name, without the base path: `/help`, `/acme/help`, or `/`
126
143
  * for a package mounted at the root. Null when the request has no value for one of the prefix's parameters. Left out
@@ -137,6 +154,12 @@ export type PagePayload = {
137
154
  /** The `<Image>` optimizer: its path and the widths it serves (Netjes:Images). */
138
155
  export type ImageConfigInfo = { path: string; widths: number[]; qualities?: number[]; basePath?: string };
139
156
 
157
+ /** A link to one of the app's icon files: `rel` is `icon` or `apple-touch-icon`. */
158
+ export type HeadIcon = { rel: string; href: string; type?: string; sizes?: string };
159
+
160
+ /** The links to the app's metadata files (favicon.ico, icon*, apple-icon*, the web app manifest), under the base path. */
161
+ export type DocumentHead = { icons: HeadIcon[]; manifest?: string };
162
+
140
163
  export type DocumentInfo = {
141
164
  lang: string;
142
165
  assets: DocumentAssets;
@@ -154,13 +177,20 @@ export type DocumentInfo = {
154
177
  * it instead of hydrating.
155
178
  */
156
179
  clientRender?: boolean;
180
+ /** The links to the app's metadata files, which the document writes in its head. */
181
+ head?: DocumentHead;
182
+ /** The server's `NetjesOptions.SiteUrl`: the metadata base relative metadata URLs resolve against. */
183
+ siteUrl?: string;
157
184
  };
158
185
 
159
186
  export type InitialPayload = PagePayload & { document: DocumentInfo };
160
187
 
161
188
  export type RedirectPayload = { kind: 'redirect'; location: string; version: string };
162
189
 
163
- export type NavigationPayload = PagePayload | RedirectPayload;
190
+ /** The answer to a request a redirect led to (`REDIRECTED_HEADER`) when no page answers its URL: load it as a document. */
191
+ export type LoadDocumentPayload = { kind: 'document' };
192
+
193
+ export type NavigationPayload = PagePayload | RedirectPayload | LoadDocumentPayload;
164
194
 
165
195
  export class PayloadError extends Error {
166
196
  override name = 'PayloadError';
@@ -221,6 +251,13 @@ function optionalString(value: unknown, what: string): string | undefined {
221
251
  return value === undefined || value === null ? undefined : string(value, what);
222
252
  }
223
253
 
254
+ /** A language tag's shape (`PageMetadata.Lang`), since the router writes it on `<html>`. */
255
+ function languageTag(value: unknown, what: string): string {
256
+ const tag = string(value, what);
257
+ if (!isLanguageTag(tag)) fail(`${what} must be a language tag, such as nl or en-GB`);
258
+ return tag;
259
+ }
260
+
224
261
  function segments(value: unknown, what: string): SegmentRef[] {
225
262
  if (!Array.isArray(value)) fail(`${what} must be an array`);
226
263
  return value.map((item, i) => {
@@ -234,6 +271,7 @@ function segments(value: unknown, what: string): SegmentRef[] {
234
271
  const key = optionalString(json.key, `${what}[${i}].key`);
235
272
  if (key !== undefined) segment.key = key;
236
273
  if (json.reused === true) segment.reused = true;
274
+ if (json.lang !== undefined && json.lang !== null) segment.lang = languageTag(json.lang, `${what}[${i}].lang`);
237
275
  if (json.depth !== undefined && json.depth !== null) {
238
276
  if (typeof json.depth !== 'number' || !Number.isInteger(json.depth) || json.depth < 0) {
239
277
  throw new PayloadError(`${what}[${i}].depth must be a whole number`);
@@ -268,7 +306,12 @@ function actionState(value: unknown): ActionStateRef {
268
306
  for (const [key, item] of Object.entries(object(json.values ?? {}, 'actionState.values'))) {
269
307
  values[key] = Array.isArray(item) ? strings(item, `actionState.values.${key}`) : string(item, `actionState.values.${key}`);
270
308
  }
271
- return { action: string(json.action, 'actionState.action'), errors: errorMap(json.errors ?? {}, 'actionState.errors'), values };
309
+ return {
310
+ action: string(json.action, 'actionState.action'),
311
+ ...(json.status !== undefined && json.status !== null ? { status: number(json.status, 'actionState.status') } : {}),
312
+ errors: errorMap(json.errors ?? {}, 'actionState.errors'),
313
+ values,
314
+ };
272
315
  }
273
316
 
274
317
  export function parseActionResponse(value: unknown): ActionResponse {
@@ -332,6 +375,7 @@ function pagePayload(json: Json): PagePayload {
332
375
  });
333
376
  }
334
377
  if (json.metadata !== undefined && json.metadata !== null) payload.metadata = object(json.metadata, 'metadata') as Metadata;
378
+ if (json.lang !== undefined && json.lang !== null) payload.lang = languageTag(json.lang, 'lang');
335
379
  if (json.pageKind !== undefined && json.pageKind !== null) {
336
380
  if (!PAGE_KINDS.includes(json.pageKind as PageKind)) fail(`unknown pageKind ${JSON.stringify(json.pageKind)}`);
337
381
  payload.pageKind = json.pageKind as PageKind;
@@ -339,6 +383,14 @@ function pagePayload(json: Json): PagePayload {
339
383
  if (json.renderedAt !== undefined && json.renderedAt !== null) payload.renderedAt = number(json.renderedAt, 'renderedAt');
340
384
  if (json.basePath !== undefined && json.basePath !== null) payload.basePath = string(json.basePath, 'basePath');
341
385
  if (json.locale !== undefined && json.locale !== null) payload.locale = string(json.locale, 'locale');
386
+ if (json.localeAlternates !== undefined && json.localeAlternates !== null) {
387
+ payload.localeAlternates = Object.fromEntries(
388
+ Object.entries(object(json.localeAlternates, 'localeAlternates')).map(([locale, path]) => {
389
+ const field = `localeAlternates.${locale}`;
390
+ return [languageTag(locale, field), appPath(path, field)];
391
+ }),
392
+ );
393
+ }
342
394
  if (json.mounts !== undefined && json.mounts !== null) payload.mounts = mounts(json.mounts);
343
395
  if (json.draftMode !== undefined && json.draftMode !== null) {
344
396
  if (typeof json.draftMode !== 'boolean') fail('draftMode must be a boolean');
@@ -353,11 +405,10 @@ export function isDotSegment(segment: string): boolean {
353
405
  }
354
406
 
355
407
  /**
356
- * A mount's URL as the server writes it: `/`, or `/` and segments, none empty or a dot segment, with no query, fragment,
357
- * backslash, whitespace or control character. The mounted components put it in front of their hrefs.
408
+ * A path relative to the app root as the server writes it: `/`, or `/` and segments, none empty or a dot segment, with no query, fragment,
409
+ * backslash, whitespace or control character.
358
410
  */
359
- function mountUrl(value: unknown, what: string): string | null {
360
- if (value === null) return null;
411
+ function appPath(value: unknown, what: string): string {
361
412
  const url = string(value, what);
362
413
  if (url === '/') return url;
363
414
  const [first, ...segments] = url.split('/');
@@ -368,7 +419,7 @@ function mountUrl(value: unknown, what: string): string | null {
368
419
 
369
420
  function mounts(value: unknown): Record<string, string | null> {
370
421
  const result: Record<string, string | null> = {};
371
- for (const [name, url] of Object.entries(object(value, 'mounts'))) result[name] = mountUrl(url, `mounts.${name}`);
422
+ for (const [name, url] of Object.entries(object(value, 'mounts'))) result[name] = url === null ? null : appPath(url, `mounts.${name}`);
372
423
  return result;
373
424
  }
374
425
 
@@ -379,6 +430,8 @@ export function parseNavigationPayload(value: unknown): NavigationPayload {
379
430
  return pagePayload(json);
380
431
  case 'redirect':
381
432
  return { kind: 'redirect', location: string(json.location, 'location'), version: string(json.version, 'version') };
433
+ case 'document':
434
+ return { kind: 'document' };
382
435
  default:
383
436
  return fail(`unknown kind ${JSON.stringify(json.kind)}`);
384
437
  }
@@ -429,6 +482,23 @@ export function parseInitialPayload(value: unknown): InitialPayload {
429
482
  if (document.publicConfig !== undefined && document.publicConfig !== null) {
430
483
  info.publicConfig = object(document.publicConfig, 'document.publicConfig');
431
484
  }
485
+ if (document.head !== undefined && document.head !== null) {
486
+ const head = object(document.head, 'document.head');
487
+ if (!Array.isArray(head.icons)) fail('document.head.icons must be an array');
488
+ info.head = {
489
+ icons: head.icons.map((value, i) => {
490
+ const icon = object(value, `document.head.icons[${i}]`);
491
+ return {
492
+ rel: string(icon.rel, `document.head.icons[${i}].rel`),
493
+ href: string(icon.href, `document.head.icons[${i}].href`),
494
+ ...(icon.type !== undefined && icon.type !== null ? { type: string(icon.type, `document.head.icons[${i}].type`) } : {}),
495
+ ...(icon.sizes !== undefined && icon.sizes !== null ? { sizes: string(icon.sizes, `document.head.icons[${i}].sizes`) } : {}),
496
+ };
497
+ }),
498
+ ...(head.manifest !== undefined && head.manifest !== null ? { manifest: string(head.manifest, 'document.head.manifest') } : {}),
499
+ };
500
+ }
501
+ if (document.siteUrl !== undefined && document.siteUrl !== null) info.siteUrl = string(document.siteUrl, 'document.siteUrl');
432
502
  if (document.clientRender !== undefined && document.clientRender !== null) {
433
503
  if (typeof document.clientRender !== 'boolean') fail('document.clientRender must be a boolean');
434
504
  if (document.clientRender) info.clientRender = true;
@@ -4,7 +4,7 @@
4
4
  // server's rules for the route and the segments (RouteTable and PageRenderer in src/Netjes). The two are checked
5
5
  // against the same cases, test/fixtures/segments/cases.json, so a change to either rule fails a suite until both agree.
6
6
  import { htmlSafeJson } from './deferred.ts';
7
- import type { InitialPayload, PageKind, Params, SegmentRef } from './payload.ts';
7
+ import type { DocumentHead, InitialPayload, PageKind, Params, SegmentRef } from './payload.ts';
8
8
 
9
9
  /** What {@link renderDocument} renders a page with: what the server would send with it. */
10
10
  export type RenderDocumentOptions = {
@@ -46,6 +46,13 @@ export type RenderDocumentOptions = {
46
46
  modules?: Record<string, () => Promise<unknown>>;
47
47
  /** Stops the render, which then rejects with the signal's reason: for a page that waits on a Promise that never settles. */
48
48
  signal?: AbortSignal;
49
+ /**
50
+ * The links to the app's metadata files (`favicon.ico`, `icon*`, `apple-icon*`, the manifest) the server would send,
51
+ * which the document writes in its head. Default none.
52
+ */
53
+ head?: DocumentHead;
54
+ /** The server's `NetjesOptions.SiteUrl`, the base relative metadata URLs resolve against. Default none. */
55
+ siteUrl?: string;
49
56
  };
50
57
 
51
58
  /** The options {@link documentPayload} reads, with any Promise in the props already a placeholder. */
@@ -319,6 +326,8 @@ export function documentPayload(
319
326
  errorPage: null,
320
327
  ...(options.publicConfig ? { publicConfig: options.publicConfig } : {}),
321
328
  ...(options.nonce ? { nonce: options.nonce } : {}),
329
+ ...(options.head ? { head: options.head } : {}),
330
+ ...(options.siteUrl ? { siteUrl: options.siteUrl } : {}),
322
331
  },
323
332
  };
324
333
  }
package/src/root.tsx CHANGED
@@ -2,6 +2,8 @@ import type { ReactNode } from 'react';
2
2
  import { QueryShell } from 'virtual:netjes/query';
3
3
  import { Document } from './document.tsx';
4
4
  import { ImageConfigProvider } from './image.tsx';
5
+ import { HeadContext } from './metadata.tsx';
6
+ import { documentLang } from './lang.ts';
5
7
  import { NonceProvider } from './nonce.tsx';
6
8
  import { PublicConfigProvider } from './public-config.tsx';
7
9
  import type { ModuleLoader, RouteModules } from './modules.ts';
@@ -23,17 +25,27 @@ function RootProviders({ info, children }: { info: DocumentInfo; children: React
23
25
 
24
26
  /** The same tree on the server and in the browser, so hydration matches. */
25
27
  export function Root({ payload, modules, loader, dataJson }: RootProps) {
28
+ const info = payload.document;
29
+ const head = {
30
+ siteUrl: info.siteUrl,
31
+ basePath: payload.basePath ?? '',
32
+ manifestFile: Boolean(info.head?.manifest),
33
+ iconFiles: (info.head?.icons.length ?? 0) > 0,
34
+ };
26
35
  return (
27
- <Document info={payload.document} dataJson={dataJson}>
28
- <RootProviders info={payload.document}>
29
- <RouterProvider
30
- initial={payload}
31
- initialModules={modules}
32
- loader={loader}
33
- errorPage={payload.document.errorPage}
34
- shell={QueryShell}
35
- />
36
- </RootProviders>
36
+ <Document info={info} lang={documentLang(payload, info.lang)} dataJson={dataJson}>
37
+ <HeadContext value={head}>
38
+ <RootProviders info={payload.document}>
39
+ <RouterProvider
40
+ initial={payload}
41
+ initialModules={modules}
42
+ loader={loader}
43
+ errorPage={payload.document.errorPage}
44
+ documentLang={payload.document.lang}
45
+ shell={QueryShell}
46
+ />
47
+ </RootProviders>
48
+ </HeadContext>
37
49
  </Document>
38
50
  );
39
51
  }
@@ -1,6 +1,6 @@
1
- import { Component, type ReactElement, type ReactNode, Suspense, createContext } from 'react';
1
+ import { Component, type ReactElement, type ReactNode, Suspense, createContext, use } from 'react';
2
2
  import { withheldError } from './errors.ts';
3
- import { type Metadata, MetadataTags, resolveMetadata } from './metadata.tsx';
3
+ import { HeadContext, HeadTags, type Metadata, resolveMetadata, resolveViewport, warnOnce } from './metadata.tsx';
4
4
  import type { ErrorPageProps, LoadedSegment, RouteModules } from './modules.ts';
5
5
  import type { PageKind, Params, SegmentRef } from './payload.ts';
6
6
 
@@ -22,6 +22,7 @@ type RouteTreeProps = {
22
22
  error?: ErrorPageProps['error'];
23
23
  /** Metadata from the C# loader. */
24
24
  metadata?: Metadata | undefined;
25
+ localeAlternates?: Record<string, string> | undefined;
25
26
  };
26
27
 
27
28
  /** How many URL segments the layout rendering here covers: what useSelectedLayoutSegment(s) count from. */
@@ -81,7 +82,7 @@ function serverError(props: Record<string, unknown>): ErrorPageProps['error'] {
81
82
  * layout > template > error boundary > Suspense (loading) > the next segment or the page. Layouts keep their state
82
83
  * while the page underneath changes; templates remount.
83
84
  */
84
- export function RouteTree({ modules, segments = [], props, params, status, pageKind, pageKey, retry, metadata, error }: RouteTreeProps): ReactElement {
85
+ export function RouteTree({ modules, segments = [], props, params, status, pageKind, pageKey, retry, metadata, localeAlternates, error }: RouteTreeProps): ReactElement {
85
86
  const Page = modules.page;
86
87
  const pageProps = pageKind === 'error' ? { ...props, error: error ?? serverError(props), reset: retry ?? (() => {}) } : props;
87
88
  let element: ReactElement = Page ? <Page key={pageKey} {...pageProps} /> : <BuiltInPage key={pageKey} status={status} props={props} />;
@@ -107,13 +108,23 @@ export function RouteTree({ modules, segments = [], props, params, status, pageK
107
108
  );
108
109
  }
109
110
  }
111
+ const head = use(HeadContext);
110
112
  const layoutsMetadata = modules.segments.map((segment) => segment.metadata);
111
- const hasMetadata = layoutsMetadata.some(Boolean) || Boolean(modules.pageMetadata) || Boolean(metadata);
112
- // One shape whether or not this page has metadata: the layouts stay at the same place in the tree, so React keeps
113
- // them mounted when the user navigates between a page with metadata and one without.
113
+ const hasMetadata = layoutsMetadata.some(Boolean) || Boolean(modules.pageMetadata) || Boolean(metadata) || Boolean(localeAlternates);
114
+ const resolved = hasMetadata
115
+ ? resolveMetadata(layoutsMetadata, modules.pageMetadata, metadata, { siteUrl: head.siteUrl, basePath: head.basePath, localeAlternates })
116
+ : undefined;
117
+ if (resolved?.icons && head.iconFiles) {
118
+ warnOnce(
119
+ 'icons-and-files',
120
+ 'netjes: metadata.icons sets icon links, and the app has icon files at the root of app/ as well, so the head links both. Use one or the other.',
121
+ );
122
+ }
123
+ // Always the head (every document has exactly one viewport tag, which the document itself no longer writes), and one
124
+ // shape for every page: the layouts stay at the same place in the tree, so React keeps them mounted between pages.
114
125
  return (
115
126
  <>
116
- {hasMetadata ? <MetadataTags metadata={resolveMetadata(layoutsMetadata, modules.pageMetadata, metadata)} /> : null}
127
+ <HeadTags viewport={resolveViewport(modules.segments.map((segment) => segment.viewport), modules.pageViewport)} metadata={resolved} head={head} />
117
128
  {element}
118
129
  </>
119
130
  );