netjes 0.0.5 → 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 (85) hide show
  1. package/README.md +12 -8
  2. package/cli/commands.mjs +62 -9
  3. package/cli/process-io.mjs +2 -2
  4. package/cli/scaffold.mjs +89 -8
  5. package/dist/client-entry.js +4 -1
  6. package/dist/client-entry.js.map +1 -1
  7. package/dist/document.d.ts.map +1 -1
  8. package/dist/document.js +1 -1
  9. package/dist/document.js.map +1 -1
  10. package/dist/index.d.ts +3 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/locale.d.ts +5 -0
  15. package/dist/locale.d.ts.map +1 -1
  16. package/dist/locale.js +4 -0
  17. package/dist/locale.js.map +1 -1
  18. package/dist/metadata.d.ts +81 -4
  19. package/dist/metadata.d.ts.map +1 -1
  20. package/dist/metadata.js +129 -7
  21. package/dist/metadata.js.map +1 -1
  22. package/dist/modules.d.ts +6 -1
  23. package/dist/modules.d.ts.map +1 -1
  24. package/dist/modules.js +15 -1
  25. package/dist/modules.js.map +1 -1
  26. package/dist/offline.d.ts +11 -0
  27. package/dist/offline.d.ts.map +1 -0
  28. package/dist/offline.js +98 -0
  29. package/dist/offline.js.map +1 -0
  30. package/dist/payload.d.ts +18 -0
  31. package/dist/payload.d.ts.map +1 -1
  32. package/dist/payload.js +29 -6
  33. package/dist/payload.js.map +1 -1
  34. package/dist/render-document.d.ts +8 -1
  35. package/dist/render-document.d.ts.map +1 -1
  36. package/dist/render-document.js +2 -0
  37. package/dist/render-document.js.map +1 -1
  38. package/dist/root.d.ts.map +1 -1
  39. package/dist/root.js +9 -1
  40. package/dist/root.js.map +1 -1
  41. package/dist/route-tree.d.ts +2 -1
  42. package/dist/route-tree.d.ts.map +1 -1
  43. package/dist/route-tree.js +14 -7
  44. package/dist/route-tree.js.map +1 -1
  45. package/dist/router.d.ts.map +1 -1
  46. package/dist/router.js +1 -1
  47. package/dist/router.js.map +1 -1
  48. package/dist/service-worker.d.ts +81 -0
  49. package/dist/service-worker.d.ts.map +1 -0
  50. package/dist/service-worker.js +584 -0
  51. package/dist/service-worker.js.map +1 -0
  52. package/dist/testing.d.ts +1 -0
  53. package/dist/testing.d.ts.map +1 -1
  54. package/dist/testing.js.map +1 -1
  55. package/package.json +12 -5
  56. package/sidecar/server.mjs +25 -2
  57. package/skills/netjes/SKILL.md +3 -1
  58. package/skills/netjes/references/caching-and-streaming.md +22 -1
  59. package/skills/netjes/references/deployment.md +2 -2
  60. package/skills/netjes/references/routing.md +5 -1
  61. package/src/client-entry.tsx +4 -1
  62. package/src/document.tsx +6 -1
  63. package/src/index.ts +3 -2
  64. package/src/locale.ts +5 -0
  65. package/src/metadata.tsx +207 -11
  66. package/src/modules.ts +19 -3
  67. package/src/offline.ts +97 -0
  68. package/src/payload.ts +41 -5
  69. package/src/render-document.tsx +10 -1
  70. package/src/root.tsx +21 -11
  71. package/src/route-tree.tsx +18 -7
  72. package/src/router.tsx +1 -0
  73. package/src/service-worker.ts +632 -0
  74. package/src/testing.tsx +1 -0
  75. package/template/Dockerfile.pnpm +68 -0
  76. package/template/Dockerfile.workspace +52 -0
  77. package/template/Dockerfile.workspace.dockerignore +15 -0
  78. package/template/README.md +5 -1
  79. package/template/_AGENTS.md +5 -1
  80. package/template/app/layout.tsx +0 -1
  81. package/tsconfig.strict-app.json +27 -0
  82. package/vite/packages.mjs +97 -0
  83. package/vite/plugin.d.ts +8 -1
  84. package/vite/plugin.mjs +156 -9
  85. /package/template/{public/favicon.svg → app/icon.svg} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA,mHAAmH;AACnH,6GAA6G;AAC7G,uFAAuF;AACvF,OAAO,EAAuB,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAk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C,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrD,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,KAAK,KAAK,IAAI;oBAC3C,CAAC,CAAC;wBACE,WAAW,EAAE;4BACX,MAAM,EAAE,KAAK;4BACb,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,IAAI,GAAG;4BAC7C,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM;4BACtC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,IAAI,EAAE;yBAC7C;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAEV,OAAO,CACL,KAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW,YACtC,KAAC,oBAAoB,IAAC,KAAK,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE,YACrD,MAAC,cAAc,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAC/I,KAAC,oBAAoB,IAAC,MAAM,EAAE,YAAY,GAAI,EAC7C,QAAQ,IACM,GACI,GACH,CACvB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netjes",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Build React apps and sites on ASP.NET Core: the Next.js App Router conventions, C# loaders and server actions, streaming SSR and types from C# to the browser",
5
5
  "keywords": [
6
6
  "react",
@@ -60,6 +60,10 @@
60
60
  "types": "./dist/zod.d.ts",
61
61
  "default": "./dist/zod.js"
62
62
  },
63
+ "./service-worker": {
64
+ "types": "./dist/service-worker.d.ts",
65
+ "default": "./dist/service-worker.js"
66
+ },
63
67
  "./client-entry": {
64
68
  "types": "./dist/client-entry.d.ts",
65
69
  "default": "./dist/client-entry.js"
@@ -68,7 +72,8 @@
68
72
  "types": "./dist/server-entry.d.ts",
69
73
  "default": "./dist/server-entry.js"
70
74
  },
71
- "./sidecar": "./sidecar/server.mjs"
75
+ "./sidecar": "./sidecar/server.mjs",
76
+ "./tsconfig.strict-app.json": "./tsconfig.strict-app.json"
72
77
  },
73
78
  "bin": {
74
79
  "netjes": "./bin/netjes.mjs"
@@ -82,17 +87,19 @@
82
87
  "cli",
83
88
  "skills",
84
89
  "template",
90
+ "tsconfig.strict-app.json",
85
91
  "README.md",
86
92
  "LICENSE"
87
93
  ],
88
94
  "scripts": {
89
- "build": "tsc -p tsconfig.build.json",
95
+ "build": "tsc -p tsconfig.build.json && tsc -p tsconfig.service-worker.json",
90
96
  "prepack": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && npm run build",
91
97
  "test": "vitest run",
92
- "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.strict-app.json"
98
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.strict-src.json && tsc -p tsconfig.service-worker.json --noEmit && tsc -p test/fixtures/service-worker/tsconfig.json"
93
99
  },
94
100
  "dependencies": {
95
- "@vitejs/plugin-react": "^6.1.2"
101
+ "@vitejs/plugin-react": "^6.1.2",
102
+ "yaml": "^2.9.1"
96
103
  },
97
104
  "peerDependencies": {
98
105
  "@tailwindcss/vite": "^4.0.0",
@@ -18,7 +18,9 @@
18
18
  // {"reason":"vite-failed","message","code"} for anything else, such as an error in vite.config or a package it imports
19
19
  // that is not installed (message in plain text; code is the error's when it has one, such as ERR_MODULE_NOT_FOUND, or
20
20
  // MODULE_NOT_FOUND from a CommonJS config).
21
+ import { readFileSync } from 'node:fs';
21
22
  import http from 'node:http';
23
+ import { createRequire } from 'node:module';
22
24
  import path from 'node:path';
23
25
  import { createInterface } from 'node:readline';
24
26
  import { pipeline } from 'node:stream/promises';
@@ -88,13 +90,34 @@ const viteFailed = (error) =>
88
90
  code: error instanceof Error && 'code' in error && typeof error.code === 'string' ? error.code : undefined,
89
91
  });
90
92
 
93
+ /** @returns {Promise<typeof import('vite')>} */
94
+ async function loadVite() {
95
+ let entry;
96
+ try {
97
+ entry = createRequire(path.join(root, 'package.json')).resolve('vite');
98
+ } catch (error) {
99
+ if (!(error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND')) throw error;
100
+ return import('vite');
101
+ }
102
+ // These helpers ship with the dev sidecar. The production build copies only this script.
103
+ const { findPackage } = await import('../cli/packages.mjs');
104
+ const { satisfies } = await import('../cli/info.mjs');
105
+ const manifest = findPackage(root, 'vite');
106
+ const version = manifest ? JSON.parse(readFileSync(manifest, 'utf8')).version : undefined;
107
+ const range = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).peerDependencies.vite;
108
+ if (!satisfies(version, range, { strict: true })) {
109
+ console.warn(`netjes: the app's Vite (${version ?? 'unknown version'}) is outside the supported range (${range}); using the Vite resolved from netjes.`);
110
+ return import('vite');
111
+ }
112
+ return import(pathToFileURL(entry).href);
113
+ }
114
+
91
115
  if (mode === 'development') {
92
116
  const origin = process.env.NETJES_VITE_ORIGIN ?? `http://localhost:${vitePort}`;
93
117
  /** @type {import('vite').ViteDevServer} */
94
118
  let dev;
95
119
  try {
96
- // Vite is the app's own dependency; it fails here when it is not installed, and on an error in vite.config.
97
- const { createServer } = await import('vite');
120
+ const { createServer } = await loadVite();
98
121
  dev = await createServer({
99
122
  root,
100
123
  appType: 'custom',
@@ -74,9 +74,11 @@ export default definePage(pages['/blog/[slug]'], function Post({ title, body })
74
74
  - Server state goes through TanStack Query, seeded from the loader with `.WithQuery(key, data)`; no `useEffect` fetching.
75
75
  - Internal links use `<Link>` and `route()`; forms use `<Form>` with `useAction`, and must work without JavaScript. A form whose changes would be lost by leaving holds navigations with `useNavigationGuard` and asks ([references/routing.md](references/routing.md)).
76
76
  - Give each page a title of its own (`metadata`, or `PageMetadata` from C#), and keep the "Skip to content" link the first thing in the root layout, `app/layout.tsx`, that takes the focus, also when the root layout is kept bare and the site's chrome is in a group layout such as `app/(site)/layout.tsx`: after a client navigation the router announces the page by its title and starts the focus over at the top ([references/routing.md](references/routing.md)).
77
+ - Icons, `apple-icon.png` and `manifest.webmanifest` go at the root of `app/` and are served and linked for you; the viewport is `export const viewport`, never a `<meta>` of your own ([routing](references/routing.md#metadata)).
78
+ - Pages that must open offline opt in with `.AvailableOffline()` and a worker built on `netjes/service-worker` ([offline pages](references/caching-and-streaming.md#offline-pages)); with pnpm, `netjes new` writes a pnpm Dockerfile and runs on the host ([deployment](references/deployment.md#docker)).
77
79
  - Never edit `generated/netjes.ts`; regenerate it and commit it with the change.
78
80
  - Anything in `Netjes:PublicConfig` or shared props is sent to the browser. So is the route of each endpoint with an `endpointUrl` key, one mapped only in Development included, once any component calls `endpointUrl`: keep secrets out of routes, and authorize on the endpoint.
79
- - Caching, streaming and static export have sharp edges: read [references/caching-and-streaming.md](references/caching-and-streaming.md) before using `.CachePage`, `Page.Defer` or `netjes export`.
81
+ - Caching, streaming and static export have sharp edges: read [references/caching-and-streaming.md](references/caching-and-streaming.md) before using `.CachePage`, `Page.Defer`, `netjes export` or `netjes/service-worker` (offline pages).
80
82
  - Shipping: [references/deployment.md](references/deployment.md).
81
83
 
82
84
  ## Commands
@@ -82,6 +82,27 @@ function ActivityFeed({ activity }: { activity: PromiseLike<ActivityItem[]> }) {
82
82
  - A boundary that is ready when the shell goes out is written in place, so it shows without JavaScript too.
83
83
  - A value that fails rejects, so `use()` throws to the nearest `error.tsx`: with error details off its message is a stand-in marked `withheld`, and a cancelled task fails with "The value was cancelled".
84
84
 
85
+ ## Offline pages
86
+
87
+ A few opted-in pages can open without a network through the app's own service worker, built on `offlinePages()` from `netjes/service-worker`:
88
+
89
+ ```ts
90
+ // sw.ts, type-checked with "lib": ["ES2023", "WebWorker"]
91
+ import { offlinePages } from 'netjes/service-worker';
92
+ declare const self: ServiceWorkerGlobalScope;
93
+ const offline = offlinePages({ fallback: '/offline', basePath: '' });
94
+ self.addEventListener('install', (e) => offline.install(e));
95
+ self.addEventListener('activate', (e) => offline.activate(e));
96
+ self.addEventListener('fetch', (e) => { if (offline.handle(e)) return; /* the app's own rules */ });
97
+ self.addEventListener('message', (e) => offline.message(e));
98
+ ```
99
+
100
+ - The worker stores only what the server marked with `X-Netjes-Offline: 1` (the page endpoints opted in with `.AvailableOffline()`), in one cache per visitor and registration, and serves a stored copy when the network fails or is slower than `networkTimeout` (3000 ms). A page load it has no copy of gets the `fallback` page, a payload a network error, so the router keeps the page on screen.
101
+ - Stored pages belong to the visitor in `X-Netjes-Offline-Scope`: a page for another visitor (sign-in, sign-out, another account, `unknown`) deletes every stored page, and an answer whose request began before that is never stored. A marked page whose visitor had no cache as its request began, and has one once its answer arrives (the first opted-in page after a change, or one on its way when another page opened the cache), is fetched once more in the background, never a third time. That second request is an ordinary one: stored only when its visitor's cache existed, alone, as it began and was not deleted on its way; after a sign-out its answer is the next visitor's. A visitor whose cache existed as the original request began (even one a clear deleted on the way) gets no second request. After `await clearOffline()` resolves, nothing whose request began before it was called is stored, that second request included. On a shared device, sign out, then `await clearOffline()`: it deletes the page caches by name and needs no worker. Without Web Locks in the browser it stores and serves no pages (the fallback page is still stored).
102
+ - The fallback page is fetched without cookies and survives every change of visitor: it must show nothing personal.
103
+ - It takes only same-origin `GET`s below the base path: page loads, payload requests and files under `/assets/` named as Vite names its built files (it goes by the name alone, and fetches them without cookies). JSON endpoints, event streams and other origins are left to the app's own rules.
104
+ - `keep(urls)` (the client's `netjes:keep` message, answered on the message's port once done) stores pages ahead; `clear()` deletes every stored page.
105
+
85
106
  ## Static export
86
107
 
87
108
  `npx netjes export [dir]` builds, runs the app once in Production and writes every page as static HTML (default `out/`). `dir` must be inside the app: `netjes export` refuses any other folder before it builds. Dynamic pages need `.StaticParams(...)` (`.StaticParams<PostStore>(s => s.All.Select(p => new { slug = p.Slug }))`, arrays for catch-all parameters); pages that need a server take `.ExcludeFromExport()`. The export fails before writing anything for a dynamic page without static params, a page with a page action, or a page that requires authorization. Exported pages navigate with full page loads and carry no antiforgery token.
@@ -98,4 +119,4 @@ Leave `/_netjes/` out of `disallow`: `<Image>` serves every image through `/_net
98
119
 
99
120
  ## More
100
121
 
101
- [Caching](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/caching.md), [Rendering and streaming](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/rendering-and-streaming.md) and [Static export](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/static-export.md) in the guides.
122
+ [Rendering and streaming](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/rendering-and-streaming.md), [Caching](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/caching.md), [Offline pages](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/offline.md) and [Static export](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/static-export.md) in the guides.
@@ -18,14 +18,14 @@ For these startup failures the app logs one critical entry, saying what is wrong
18
18
 
19
19
  ## Docker
20
20
 
21
- `netjes new` writes a `Dockerfile` and Compose files:
21
+ `netjes new` writes a `Dockerfile` and, for an npm app, Compose files (a standalone pnpm app gets them with `--compose`, and a pnpm workspace app never does: it builds with `docker build -f <app>/Dockerfile .` from the workspace root):
22
22
 
23
23
  - `docker compose up`: development, with `dotnet watch` and Vite HMR, ports bound to localhost.
24
24
  - `docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d`: the production image, a non-root user on a read-only filesystem, with a health check on `/healthz` and Data Protection keys in a named volume.
25
25
  - Both publish the app on host port 8080; `APP_PORT` (in the shell or a `.env` file) moves it. Development also publishes Vite on 5173, which `VITE_PORT` moves (the same port inside and out, with `Netjes__ViteDevPort` set to it).
26
26
  - The production image runs `tini -s -- dotnet MyApp.dll`: tini is PID 1, passes `docker stop`'s SIGTERM on, and exits with the app's code, so a crash ends the container (134) and `restart: always` acts. When .NET itself is a container's PID 1, its abort does not end it. On arm64 it spins at 100% CPU and never exits; after a crash later than startup the rest of the app keeps serving and `/healthz` still passes. On x86-64 under emulation it has been seen to exit after a few seconds, with 139 instead of 134. An image of the app's own, or one from an older template, needs an init too: the template's `tini` stage, its `COPY` and the `ENTRYPOINT`, or the host's (`docker run --init`, Compose `init: true`, ECS `initProcessEnabled`).
27
27
 
28
- The image restores Netjes from NuGet and npm, so the app must reference the packages, as an app made with `npx netjes new` does (from a Netjes checkout, pass `--packages`).
28
+ The image restores Netjes from NuGet and npm, so the app must reference the packages, as an app made with `npx netjes new` does (from a Netjes checkout, pass `--packages`). For pnpm (`netjes new` picks it when pnpm launches it or a pnpm workspace is above the app, or with `--package-manager pnpm`), run `pnpm dev` on the host and build with `docker build .` from the app folder; an app in a pnpm workspace builds from the workspace root with `docker build -f <app>/Dockerfile .`. Behind a proxy, streamed responses and event streams already carry `X-Accel-Buffering: no`; an app's own value wins.
29
29
 
30
30
  ## Production settings
31
31
 
@@ -14,6 +14,7 @@ ASP.NET Core does the routing: every page file becomes an endpoint with an ordin
14
14
  | `not-found.tsx` | Rendered for `Page.NotFound()` from a loader below it, and the root one for unknown URLs, except below a page package's mount, where the package's renders. |
15
15
  | `forbidden.tsx`, `unauthorized.tsx` | Rendered for `Page.Forbidden()` / `Page.Unauthorized()` and for empty 403/401 responses from authorization; without one, the error page renders. |
16
16
  | `global-error.tsx` | In `app/` only: rendered without any layout when even the error page fails. |
17
+ | `favicon.ico`, `icon.svg` (`.png`, `.ico`, `.jpg`; `icon1.png` and on), `apple-icon.png` (and on), `manifest.webmanifest` | At the root of `app/` only: served at the site root and linked from every page (with a content hash, type and sizes, under the base path). Write no `<link>` tags or `metadata.icons` for them. The same name in `public/` stops the app; in a subfolder or a page package they are ignored with a route warning. |
17
18
 
18
19
  Built-in pages stand in for missing boundary files.
19
20
 
@@ -64,6 +65,9 @@ ASP.NET Core ranks the endpoints a URL matches by order (pages and `MapGet` endp
64
65
  - From C#: `.WithMetadata(new PageMetadata { Title = post.Title, Description = ... })` on the loader's result, merged over the files' metadata, so the layouts' title templates wrap `Title`; `AbsoluteTitle = ...` is a title they leave alone.
65
66
  - `<html lang>` is `NetjesOptions.Lang` (or the locale), and `PageMetadata.Lang = "nl"` from a loader sets it: a layout loader's for the pages below it, a page loader's wins. A client navigation updates it, and a page without one goes back to the app's. It must be a BCP 47 tag's shape, or setting it throws. Do not set `document.documentElement.lang` in an effect.
66
67
  - Below a layout that sets a title, use `metadata`, not a `<title>` element (that makes a second title).
68
+ - `export const viewport: Viewport = { themeColor: '#123', viewportFit: 'cover' }` in a layout or page sets the one `<meta name="viewport">` every document has (default `width=device-width, initial-scale=1`), the `theme-color` tags (one per `{ color, media }`) and `color-scheme`. Never render a viewport `<meta>` yourself: that makes a second one.
69
+ - An installable app is `manifest.webmanifest`, an icon and an `apple-icon.png` in `app/`, `viewport` and `metadata.appleWebApp`, and its start page opted in to offline pages with a worker ([installable app](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/metadata.md#an-installable-app)).
70
+ - Write metadata URLs relative (`alternates.canonical: '/blog'`, `openGraph.images: '/og.png'`): they resolve against `Netjes:SiteUrl` in configuration (or `metadataBase`), under the base path. `app.MapSitemap()` and `app.MapRobotsTxt()` without a URL use it too.
67
71
  - Code the first paint needs, such as a theme set on `<html>`, goes in `<Script id="theme" strategy="beforeInteractive">{code}</Script>` first in the root layout (a script takes no focus, so the skip link after it stays first): the server writes inline code where it stands and the parser runs it there. An external `beforeInteractive` script runs once the shell is parsed, in order, before the page's code; hydration waits for it, and inline code runs before it. That holds in a server-rendered document: a component that mounts in the browser, after a client navigation or when no sidecar was ready, adds its script after mounting, as `afterInteractive` does. Keep them outside Suspense boundaries. Under a hash-based policy, list the hash of the code as the document carries it, which `inlineScriptHashes` from `netjes/testing` gives, and an external script's origin in `script-src`.
68
72
 
69
73
  ## Protecting sections
@@ -85,7 +89,7 @@ A page package is an npm package and a NuGet package of one version that bring p
85
89
 
86
90
  ## Base path and locales
87
91
 
88
- `app.UsePathBase("/docs")` with `netjes({ basePath: '/docs' })`; links, forms and redirects add it, and app code is written as if at the root (`useHref(path)` for a plain `<a>`). Locale routing is a `[lang]` folder with `AddNetjesLocalization`, `UseNetjesLocalization` and `MapLocaleRedirect`; `useLocale()` reads it.
92
+ `app.UsePathBase("/docs")` with `netjes({ basePath: '/docs' })`; links, forms and redirects add it, and app code is written as if at the root (`useHref(path)` for a plain `<a>`). Locale routing is a `[lang]` folder with `AddNetjesLocalization`, `UseNetjesLocalization` and `MapLocaleRedirect`; `useLocale()` reads it. `MapLocaleRedirect` sends `/` and any URL without a locale that a localized page answers (`/about`) to the visitor's locale with a 307: the cookie `LocaleCookie` names, then `Accept-Language`, then the default. `PrefixDefaultLocale = false` serves the default locale at URLs without it (`/about` in English, `/nl/about` in Dutch) through the page's own loader, actions and authorization, and redirects `/en/about` permanently to `/about`; write default-locale links without the locale. Localized pages get `hreflang` alternates (`Alternates = false` turns them off; an explicit `alternates.languages` wins), and `useAlternateLocales()` gives a language switcher their paths.
89
93
 
90
94
  ## More
91
95
 
@@ -86,7 +86,10 @@ globals.__netjes_d = settle;
86
86
 
87
87
  const parsed = revivePayload(parseInitialPayload(JSON.parse(dataJson)), deferred.source);
88
88
  // Judge the server's seeded data as fresh as the server did when it rendered, so hydration matches.
89
- const payload = withClockOffset(parsed, parsed.renderedAt);
89
+ // A document served from offline storage keeps its original query timestamps, as a stored payload does.
90
+ const navigation = performance.getEntriesByType?.('navigation')[0] as PerformanceNavigationTiming | undefined;
91
+ const stored = navigation?.serverTiming?.some(({ name }) => name === 'netjes-stored');
92
+ const payload = stored ? parsed : withClockOffset(parsed, parsed.renderedAt);
90
93
  const loader = createModuleLoader(pages, { nameFailedImports: true });
91
94
 
92
95
  /** How long the first page waits before it tries a module that failed to load once more. */
package/src/document.tsx CHANGED
@@ -35,7 +35,12 @@ export function Document({ info, lang = info.lang, dataJson, children }: Documen
35
35
  <html lang={lang} suppressHydrationWarning>
36
36
  <head>
37
37
  <meta charSet="utf-8" />
38
- <meta name="viewport" content="width=device-width, initial-scale=1" />
38
+ {/* The app's metadata files at the root of app/, which the server found. The route tree writes the viewport tag
39
+ and the rest of the head: it knows the page's viewport and metadata. */}
40
+ {info.head?.icons.map((icon) => (
41
+ <link key={`${icon.rel}:${icon.href}`} rel={icon.rel} href={icon.href} type={icon.type} sizes={icon.sizes} />
42
+ ))}
43
+ {info.head?.manifest && <link rel="manifest" href={info.head.manifest} />}
39
44
  {/* Vite reads the nonce from here for the styles it injects. */}
40
45
  {nonce && <meta property="csp-nonce" nonce={nonce} />}
41
46
  {/* Collects Page.Defer values streamed in before the client script runs. A client render finds it in the
package/src/index.ts CHANGED
@@ -25,7 +25,7 @@ export {
25
25
  } from './href.ts';
26
26
  export { Image, type ImageProps } from './image.tsx';
27
27
  export { Link, type LinkProps } from './link.tsx';
28
- export { useLocale } from './locale.ts';
28
+ export { useAlternateLocales, useLocale } from './locale.ts';
29
29
  export type { ErrorPageProps, LayoutProps } from './modules.ts';
30
30
  export {
31
31
  type Mounted,
@@ -36,6 +36,7 @@ export {
36
36
  mounted,
37
37
  } from './mounted.tsx';
38
38
  export { useNonce } from './nonce.tsx';
39
+ export { clearOffline, keepOffline, registerServiceWorker } from './offline.ts';
39
40
  export type { PageKind, Params, SeededQuery, SegmentRef } from './payload.ts';
40
41
  export { usePublicConfig } from './public-config.tsx';
41
42
  export { Script, type ScriptProps, type ScriptStrategy } from './script.tsx';
@@ -64,4 +65,4 @@ export {
64
65
  useSharedProps,
65
66
  } from './router.tsx';
66
67
  export type { StandardSchemaV1 } from './schema.ts';
67
- export type { Metadata, MetadataImage, MetadataTitle } from './metadata.tsx';
68
+ export type { Metadata, MetadataImage, MetadataTitle, ThemeColorDescriptor, Viewport } from './metadata.tsx';
package/src/locale.ts CHANGED
@@ -4,3 +4,8 @@ import { usePagePayload } from './router.tsx';
4
4
  export function useLocale(): string | null {
5
5
  return usePagePayload().locale ?? null;
6
6
  }
7
+
8
+ /** The current page's alternate locale URLs as app-root-relative paths, including x-default when present. */
9
+ export function useAlternateLocales(): { locale: string; href: string }[] {
10
+ return Object.entries(usePagePayload().localeAlternates ?? {}).map(([locale, href]) => ({ locale, href }));
11
+ }
package/src/metadata.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  // The Next.js Metadata API: `export const metadata` from pages and layouts, plus metadata sent by the C# loader
2
2
  // (`.WithMetadata(...)`, the counterpart of generateMetadata). React 19 hoists the tags into <head>.
3
3
 
4
- import { Fragment } from 'react';
4
+ import { Fragment, createContext } from 'react';
5
5
 
6
6
  /**
7
7
  * A title, a layout's `template` (`'%s · Site'`) and `default`, or an `absolute` title that skips templates. A
@@ -38,15 +38,68 @@ export type Metadata = {
38
38
  };
39
39
  twitter?: { card?: 'summary' | 'summary_large_image' | 'app' | 'player'; site?: string; creator?: string; title?: string; description?: string; images?: MetadataImages };
40
40
  icons?: { icon?: string; apple?: string };
41
+ /** Prefer `viewport.themeColor` (`export const viewport`), which wins over this one. */
41
42
  themeColor?: string;
43
+ /**
44
+ * The base the relative URLs of `alternates`, `openGraph.url` and the Open Graph and Twitter images resolve against,
45
+ * under the app's base path. Default: the server's `NetjesOptions.SiteUrl`; `null` leaves the URLs as they are.
46
+ */
47
+ metadataBase?: string | URL | null;
48
+ /** A web app manifest's URL, linked with `<link rel="manifest">`. A `manifest.webmanifest` or `manifest.json` file at the root of `app/` wins. */
49
+ manifest?: string;
50
+ /** How the page behaves added to an iPhone's or iPad's home screen. */
51
+ appleWebApp?: {
52
+ /** Writes `<meta name="mobile-web-app-capable" content="yes">`: opened from the home screen, the page has no browser UI. */
53
+ capable?: boolean;
54
+ title?: string;
55
+ statusBarStyle?: 'default' | 'black' | 'black-translucent';
56
+ /** A startup screen's image, or one per screen size, each a URL or `{ url, media }`. */
57
+ startupImage?: string | (string | { url: string; media?: string })[];
58
+ };
42
59
  other?: Record<string, string>;
43
60
  };
44
61
 
62
+ /** A theme color, for the color schemes or screens its `media` query matches. */
63
+ export type ThemeColorDescriptor = { color: string; media?: string };
64
+
65
+ /**
66
+ * The type of `export const viewport` in layouts and pages: the `<meta name="viewport">`, `theme-color` and
67
+ * `color-scheme` tags, merged from the layouts down to the page (later fields win). Every document has exactly one
68
+ * viewport tag; without any of these it is `width=device-width, initial-scale=1`.
69
+ */
70
+ export type Viewport = {
71
+ width?: string | number;
72
+ height?: string | number;
73
+ initialScale?: number;
74
+ minimumScale?: number;
75
+ maximumScale?: number;
76
+ userScalable?: boolean;
77
+ viewportFit?: 'auto' | 'cover' | 'contain';
78
+ interactiveWidget?: 'resizes-visual' | 'resizes-content' | 'overlays-content';
79
+ /** One color, or one per color scheme: `[{ color: '#fff', media: '(prefers-color-scheme: light)' }, …]`. Wins over `metadata.themeColor`. */
80
+ themeColor?: string | ThemeColorDescriptor | ThemeColorDescriptor[];
81
+ colorScheme?: string;
82
+ };
83
+
84
+ /** What the document tells the head about the app: the metadata base, the base path and its metadata files. */
85
+ export type HeadInfo = {
86
+ /** The server's `NetjesOptions.SiteUrl`, the default metadata base. */
87
+ siteUrl?: string | undefined;
88
+ basePath: string;
89
+ /** The app has a manifest file, which the document links: `metadata.manifest` is left out. */
90
+ manifestFile: boolean;
91
+ /** The app has icon files, which the document links. */
92
+ iconFiles: boolean;
93
+ };
94
+
95
+ /** Provided by the document's root; a tree without one (a component test) has no metadata base and no files. */
96
+ export const HeadContext = createContext<HeadInfo>({ basePath: '', manifestFile: false, iconFiles: false });
97
+
45
98
  type OpenGraph = NonNullable<Metadata['openGraph']>;
46
99
  type Twitter = NonNullable<Metadata['twitter']>;
47
100
 
48
101
  /** The merged result: one title string, the images as a list, everything else merged field by field (later wins). */
49
- export type ResolvedMetadata = Omit<Metadata, 'title' | 'openGraph' | 'twitter'> & {
102
+ export type ResolvedMetadata = Omit<Metadata, 'title' | 'openGraph' | 'twitter' | 'metadataBase'> & {
50
103
  title?: string;
51
104
  openGraph?: Omit<OpenGraph, 'images'> & { images?: ResolvedImage[] };
52
105
  twitter?: Omit<Twitter, 'images'> & { images?: ResolvedImage[] };
@@ -86,13 +139,21 @@ function withImages<T extends { images?: MetadataImages }>(group: T): Omit<T, 'i
86
139
  * title and never through its own; on a layout it is the title when nothing below sets one. `title.absolute` skips
87
140
  * templates.
88
141
  */
89
- export function resolveMetadata(layouts: readonly (Metadata | undefined)[], page: Metadata | undefined, server?: Metadata): ResolvedMetadata {
142
+ export function resolveMetadata(
143
+ layouts: readonly (Metadata | undefined)[],
144
+ page: Metadata | undefined,
145
+ server?: Metadata,
146
+ base: { siteUrl?: string | undefined; basePath?: string | undefined; localeAlternates?: Record<string, string> | undefined } = {},
147
+ ): ResolvedMetadata {
90
148
  let resolved: ResolvedMetadata = {};
91
149
  let template: string | undefined;
150
+ let metadataBase: string | URL | null | undefined = base.siteUrl;
92
151
  for (const metadata of [...layouts, page, server]) {
93
152
  if (!metadata) continue;
94
- const { title, openGraph, twitter, alternates, icons, other, ...rest } = metadata;
153
+ const { title, openGraph, twitter, alternates, icons, other, metadataBase: ownBase, appleWebApp, ...rest } = metadata;
95
154
  resolved = { ...resolved, ...rest };
155
+ if (ownBase !== undefined) metadataBase = ownBase;
156
+ if (appleWebApp) resolved.appleWebApp = { ...resolved.appleWebApp, ...appleWebApp };
96
157
  if (title !== undefined) {
97
158
  // The template from above applies to every title but an absolute one, a default included. This title's own
98
159
  // template is stored after its title is written, so it applies only to the titles below.
@@ -106,7 +167,114 @@ export function resolveMetadata(layouts: readonly (Metadata | undefined)[], page
106
167
  if (icons) resolved.icons = { ...resolved.icons, ...icons };
107
168
  if (other) resolved.other = { ...resolved.other, ...other };
108
169
  }
109
- return fillTwitter(resolved);
170
+ const generatedLanguages = resolved.alternates?.languages === undefined ? base.localeAlternates : undefined;
171
+ if (generatedLanguages !== undefined) resolved.alternates = { ...resolved.alternates, languages: generatedLanguages };
172
+ return fillTwitter(withAbsoluteUrls(resolved, metadataBase ?? null, base.basePath ?? '', generatedLanguages !== undefined));
173
+ }
174
+
175
+ /** Warnings given in this process (development only): each once. */
176
+ const warned = new Set<string>();
177
+
178
+ export function warnOnce(key: string, message: string) {
179
+ if (process.env.NODE_ENV === 'production' || warned.has(key)) return;
180
+ warned.add(key);
181
+ console.warn(message);
182
+ }
183
+
184
+ /** A URL with a scheme (`https:`, `data:`): never resolved. */
185
+ const ABSOLUTE = /^[a-z][a-z\d+.-]*:/i;
186
+
187
+ /**
188
+ * The listed URLs made absolute against `base` (ADR 0073): a root-relative path under the base path, unless it starts
189
+ * with it already, as `<Link>` does; another relative one against the base path's folder. Without a base they stay as
190
+ * given, and a relative image, which a link preview cannot load, is warned about once in development.
191
+ */
192
+ function withAbsoluteUrls(resolved: ResolvedMetadata, base: string | URL | null, basePath: string, appRelativeLanguages: boolean): ResolvedMetadata {
193
+ const root = base === null ? null : String(base).replace(/\/+$/, '');
194
+ const absolute = (url: string): string => {
195
+ if (root === null || url === '' || ABSOLUTE.test(url)) return url;
196
+ // A network-path reference (//cdn.example/x) takes the base's scheme only: it names its own host.
197
+ if (url.startsWith('//')) return new URL(url, `${root}/`).href;
198
+ if (!url.startsWith('/')) return new URL(url, `${root}${basePath}/`).href;
199
+ const under = basePath && (url === basePath || url.startsWith(`${basePath}/`) || url.startsWith(`${basePath}?`) || url.startsWith(`${basePath}#`));
200
+ return `${root}${under ? '' : basePath}${url}`;
201
+ };
202
+ const images = (list: ResolvedImage[] | undefined) => {
203
+ if (root === null && list?.some((image) => !ABSOLUTE.test(image.url) && !image.url.startsWith('//'))) {
204
+ warnOnce(
205
+ 'relative-image',
206
+ 'netjes: a page has a relative og:image or twitter:image, and no metadata base to resolve it against, so link previews cannot load it. ' +
207
+ 'Set Netjes:SiteUrl on the server (NetjesOptions.SiteUrl), or metadataBase in the metadata.',
208
+ );
209
+ }
210
+ return list?.map((image) => ({ ...image, url: absolute(image.url) }));
211
+ };
212
+ const result: ResolvedMetadata = { ...resolved };
213
+ if (resolved.alternates) {
214
+ const { canonical, languages } = resolved.alternates;
215
+ // Generated paths are known to be below the app's base path, even when their first segment has the same name.
216
+ const languageUrl = (path: string) => appRelativeLanguages ? `${root ?? ''}${basePath}${path}` : absolute(path);
217
+ result.alternates = {
218
+ ...resolved.alternates,
219
+ ...(canonical !== undefined ? { canonical: absolute(canonical) } : {}),
220
+ ...(languages ? { languages: Object.fromEntries(Object.entries(languages).map(([lang, href]) => [lang, languageUrl(href)])) } : {}),
221
+ };
222
+ }
223
+ if (resolved.openGraph) {
224
+ const ogImages = images(resolved.openGraph.images);
225
+ result.openGraph = {
226
+ ...resolved.openGraph,
227
+ ...(resolved.openGraph.url !== undefined ? { url: absolute(resolved.openGraph.url) } : {}),
228
+ ...(ogImages ? { images: ogImages } : {}),
229
+ };
230
+ }
231
+ if (resolved.twitter?.images) result.twitter = { ...resolved.twitter, images: images(resolved.twitter.images)! };
232
+ return result;
233
+ }
234
+
235
+ /** The merged viewport: the layouts' and the page's, later fields winning, over `width=device-width, initial-scale=1`. */
236
+ export function resolveViewport(layouts: readonly (Viewport | undefined)[], page: Viewport | undefined): Viewport {
237
+ let resolved: Viewport = { width: 'device-width', initialScale: 1 };
238
+ for (const viewport of [...layouts, page]) if (viewport) resolved = { ...resolved, ...viewport };
239
+ return resolved;
240
+ }
241
+
242
+ /** The `content` of the viewport tag, as Next.js writes it. */
243
+ export function viewportContent(viewport: Viewport): string {
244
+ const parts: [string, string | number | boolean | undefined][] = [
245
+ ['width', viewport.width],
246
+ ['height', viewport.height],
247
+ ['initial-scale', viewport.initialScale],
248
+ ['minimum-scale', viewport.minimumScale],
249
+ ['maximum-scale', viewport.maximumScale],
250
+ ['user-scalable', viewport.userScalable === undefined ? undefined : viewport.userScalable ? 'yes' : 'no'],
251
+ ['viewport-fit', viewport.viewportFit],
252
+ ['interactive-widget', viewport.interactiveWidget],
253
+ ];
254
+ return parts.filter(([, value]) => value !== undefined && value !== '').map(([key, value]) => `${key}=${String(value)}`).join(', ');
255
+ }
256
+
257
+ function themeColors(color: Viewport['themeColor']): ThemeColorDescriptor[] {
258
+ if (color === undefined || color === '') return [];
259
+ return (Array.isArray(color) ? color : [typeof color === 'string' ? { color } : color]).filter((entry) => !!entry?.color);
260
+ }
261
+
262
+ /**
263
+ * Every tag a route puts in the head besides the document's own: the one viewport tag, the theme colors (the
264
+ * viewport's, or else the metadata's) and the color scheme, then the metadata's tags when it has any.
265
+ */
266
+ export function HeadTags({ viewport, metadata, head }: { viewport: Viewport; metadata?: ResolvedMetadata | undefined; head: HeadInfo }) {
267
+ const colors = themeColors(viewport.themeColor ?? metadata?.themeColor);
268
+ return (
269
+ <>
270
+ <meta name="viewport" content={viewportContent(viewport)} />
271
+ {colors.map((entry, index) => (
272
+ <meta key={`${index}:${entry.color}`} name="theme-color" content={entry.color} {...(entry.media ? { media: entry.media } : {})} />
273
+ ))}
274
+ {viewport.colorScheme && <meta name="color-scheme" content={viewport.colorScheme} />}
275
+ {metadata && <MetadataTags metadata={metadata} manifestFile={head.manifestFile} />}
276
+ </>
277
+ );
110
278
  }
111
279
 
112
280
  /**
@@ -139,14 +307,34 @@ function robotsContent(robots: Metadata['robots']): string | undefined {
139
307
  return `${robots.index === false ? 'noindex' : 'index'}, ${robots.follow === false ? 'nofollow' : 'follow'}`;
140
308
  }
141
309
 
142
- /** The tags for resolved metadata; rendered anywhere, React puts them in <head>. */
143
- export function MetadataTags({ metadata }: { metadata: ResolvedMetadata }) {
310
+ /**
311
+ * A `viewport` among `other`'s names, in any case: the route tree writes the one viewport tag every document has, from
312
+ * `export const viewport`, so a second one is left out, with a warning in development.
313
+ */
314
+ function isViewport(name: string): boolean {
315
+ if (name.trim().toLowerCase() !== 'viewport') return false;
316
+ warnOnce(
317
+ 'other-viewport',
318
+ "netjes: metadata.other sets a viewport, which Netjes leaves out: every document has one viewport tag. Set it with export const viewport in a layout or page.",
319
+ );
320
+ return true;
321
+ }
322
+
323
+ /**
324
+ * The tags for resolved metadata; rendered anywhere, React puts them in <head>. The theme color is written with the
325
+ * viewport (`HeadTags`), and `metadata.manifest` is left out when the app has a manifest file, which the document links.
326
+ */
327
+ export function MetadataTags({ metadata, manifestFile = false }: { metadata: ResolvedMetadata; manifestFile?: boolean }) {
144
328
  const og = metadata.openGraph;
145
329
  const twitter = metadata.twitter;
146
330
  const robots = robotsContent(metadata.robots);
147
331
  // As in Next.js, an empty Open Graph title or description counts as not set, and an empty tag is not written.
148
332
  const ogTitle = og ? og.title || metadata.title : undefined;
149
333
  const ogDescription = og ? og.description || metadata.description : undefined;
334
+ const apple = metadata.appleWebApp;
335
+ const startupImages = (apple?.startupImage === undefined ? [] : Array.isArray(apple.startupImage) ? apple.startupImage : [apple.startupImage])
336
+ .map((image) => (typeof image === 'string' ? { url: image } : image))
337
+ .filter((image): image is { url: string; media?: string } => !!image?.url);
150
338
  return (
151
339
  <>
152
340
  {metadata.title !== undefined && <title>{metadata.title}</title>}
@@ -154,13 +342,19 @@ export function MetadataTags({ metadata }: { metadata: ResolvedMetadata }) {
154
342
  {metadata.keywords && <meta name="keywords" content={metadata.keywords.join(', ')} />}
155
343
  {metadata.authors?.map((author) => <meta key={author.name} name="author" content={author.name} />)}
156
344
  {robots && <meta name="robots" content={robots} />}
157
- {metadata.themeColor && <meta name="theme-color" content={metadata.themeColor} />}
158
345
  {metadata.alternates?.canonical && <link rel="canonical" href={metadata.alternates.canonical} />}
159
346
  {Object.entries(metadata.alternates?.languages ?? {}).map(([lang, href]) => (
160
347
  <link key={lang} rel="alternate" hrefLang={lang} href={href} />
161
348
  ))}
162
349
  {metadata.icons?.icon && <link rel="icon" href={metadata.icons.icon} />}
163
350
  {metadata.icons?.apple && <link rel="apple-touch-icon" href={metadata.icons.apple} />}
351
+ {metadata.manifest && !manifestFile && <link rel="manifest" href={metadata.manifest} />}
352
+ {apple?.capable && <meta name="mobile-web-app-capable" content="yes" />}
353
+ {apple?.title && <meta name="apple-mobile-web-app-title" content={apple.title} />}
354
+ {apple?.statusBarStyle && <meta name="apple-mobile-web-app-status-bar-style" content={apple.statusBarStyle} />}
355
+ {startupImages.map((image, index) => (
356
+ <link key={`${index}:${image.url}`} rel="apple-touch-startup-image" href={image.url} {...(image.media ? { media: image.media } : {})} />
357
+ ))}
164
358
  {ogTitle && <meta property="og:title" content={ogTitle} />}
165
359
  {ogDescription && <meta property="og:description" content={ogDescription} />}
166
360
  {og?.url && <meta property="og:url" content={og.url} />}
@@ -186,9 +380,11 @@ export function MetadataTags({ metadata }: { metadata: ResolvedMetadata }) {
186
380
  {!!image.alt && <meta name="twitter:image:alt" content={image.alt} />}
187
381
  </Fragment>
188
382
  ))}
189
- {Object.entries(metadata.other ?? {}).map(([name, content]) => (
190
- <meta key={name} name={name} content={content} />
191
- ))}
383
+ {Object.entries(metadata.other ?? {})
384
+ .filter(([name]) => !isViewport(name))
385
+ .map(([name, content]) => (
386
+ <meta key={name} name={name} content={content} />
387
+ ))}
192
388
  </>
193
389
  );
194
390
  }