@warlock.js/web 5.1.0 → 5.2.0

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 (219) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/README.md +126 -12
  3. package/esm/build/contribution.d.mts +11 -14
  4. package/esm/build/contribution.mjs +46 -58
  5. package/esm/build/contribution.mjs.map +1 -1
  6. package/esm/build/discover-pages.mjs +105 -45
  7. package/esm/build/discover-pages.mjs.map +1 -1
  8. package/esm/build/generate-client-registry.mjs +47 -13
  9. package/esm/build/generate-client-registry.mjs.map +1 -1
  10. package/esm/build/generate-pages-barrel.mjs +55 -13
  11. package/esm/build/generate-pages-barrel.mjs.map +1 -1
  12. package/esm/build/page-default-export.mjs +48 -0
  13. package/esm/build/page-default-export.mjs.map +1 -0
  14. package/esm/build/page-routes-manifest.mjs +21 -0
  15. package/esm/build/page-routes-manifest.mjs.map +1 -0
  16. package/esm/build/public-files.mjs +45 -0
  17. package/esm/build/public-files.mjs.map +1 -0
  18. package/esm/build/read-route-exports.mjs +1 -1
  19. package/esm/build/read-route-exports.mjs.map +1 -1
  20. package/esm/client/build-hydrated-tree.mjs +40 -9
  21. package/esm/client/build-hydrated-tree.mjs.map +1 -1
  22. package/esm/client/hydrate-page.mjs +1 -1
  23. package/esm/client/hydrate-page.mjs.map +1 -1
  24. package/esm/client/navigation/current-route.d.mts +1 -1
  25. package/esm/client/navigation/current-route.mjs +1 -1
  26. package/esm/client/navigation/current-route.mjs.map +1 -1
  27. package/esm/client/navigation/fetch-page-data.mjs +1 -1
  28. package/esm/client/navigation/fetch-page-data.mjs.map +1 -1
  29. package/esm/client/navigation/navigation-root.mjs +1 -1
  30. package/esm/client/navigation/navigation-root.mjs.map +1 -1
  31. package/esm/client/navigation/prefetch.mjs +1 -1
  32. package/esm/client/navigation/prefetch.mjs.map +1 -1
  33. package/esm/client/navigation/refresh.d.mts +1 -1
  34. package/esm/client/navigation/refresh.mjs +1 -1
  35. package/esm/client/navigation/refresh.mjs.map +1 -1
  36. package/esm/client/navigation/scroll-to-fragment.mjs +1 -1
  37. package/esm/client/navigation/scroll-to-fragment.mjs.map +1 -1
  38. package/esm/client/navigation/verbs.d.mts +1 -1
  39. package/esm/client/navigation/verbs.mjs +1 -1
  40. package/esm/client/navigation/verbs.mjs.map +1 -1
  41. package/esm/client/runtime/index.d.mts +2 -1
  42. package/esm/client/runtime/index.mjs +2 -1
  43. package/esm/client/runtime/manifest.d.mts +1 -1
  44. package/esm/client/runtime/manifest.mjs +3 -2
  45. package/esm/client/runtime/manifest.mjs.map +1 -1
  46. package/esm/client/runtime/matcher.d.mts +13 -1
  47. package/esm/client/runtime/matcher.mjs +13 -1
  48. package/esm/client/runtime/matcher.mjs.map +1 -1
  49. package/esm/client/runtime/types.d.mts +15 -2
  50. package/esm/components/default-app.mjs +1 -1
  51. package/esm/components/default-app.mjs.map +1 -1
  52. package/esm/components/document-context.d.mts +40 -2
  53. package/esm/components/document-context.mjs +1 -1
  54. package/esm/components/document-context.mjs.map +1 -1
  55. package/esm/components/head.d.mts +1 -1
  56. package/esm/components/head.mjs +1 -1
  57. package/esm/components/head.mjs.map +1 -1
  58. package/esm/components/link.d.mts +1 -1
  59. package/esm/components/link.mjs +1 -1
  60. package/esm/components/link.mjs.map +1 -1
  61. package/esm/components/scripts.d.mts +1 -1
  62. package/esm/components/scripts.mjs +4 -2
  63. package/esm/components/scripts.mjs.map +1 -1
  64. package/esm/context.d.mts +6 -102
  65. package/esm/hydration/index.mjs +1 -1
  66. package/esm/hydration/index.mjs.map +1 -1
  67. package/esm/hydration-payload.d.mts +1 -1
  68. package/esm/hydration-payload.mjs +37 -8
  69. package/esm/hydration-payload.mjs.map +1 -1
  70. package/esm/index.d.mts +4 -3
  71. package/esm/loaders.d.mts +7 -36
  72. package/esm/metadata.d.mts +1 -1
  73. package/esm/metadata.mjs +1 -1
  74. package/esm/metadata.mjs.map +1 -1
  75. package/esm/props.d.mts +16 -8
  76. package/esm/route.d.mts +2 -17
  77. package/esm/routing/compose-route-path.d.mts +1 -1
  78. package/esm/routing/compose-route-path.mjs +1 -1
  79. package/esm/routing/compose-route-path.mjs.map +1 -1
  80. package/esm/routing/data-request.mjs +1 -1
  81. package/esm/routing/data-request.mjs.map +1 -1
  82. package/esm/routing/filesystem-route.mjs +45 -0
  83. package/esm/routing/filesystem-route.mjs.map +1 -0
  84. package/esm/routing/layout-policy.mjs +1 -1
  85. package/esm/routing/layout-policy.mjs.map +1 -1
  86. package/esm/routing/navigator.mjs +1 -1
  87. package/esm/routing/navigator.mjs.map +1 -1
  88. package/esm/routing/query-string.d.mts +1 -1
  89. package/esm/routing/query-string.mjs +1 -1
  90. package/esm/routing/query-string.mjs.map +1 -1
  91. package/esm/routing/route-identity.mjs +1 -1
  92. package/esm/routing/route-identity.mjs.map +1 -1
  93. package/esm/routing/route-table.d.mts +1 -1
  94. package/esm/routing/route-table.mjs +1 -1
  95. package/esm/routing/route-table.mjs.map +1 -1
  96. package/esm/routing/router-events.d.mts +1 -1
  97. package/esm/routing/router-events.mjs +1 -1
  98. package/esm/routing/router-events.mjs.map +1 -1
  99. package/esm/routing/url-fragment.mjs +1 -1
  100. package/esm/routing/url-fragment.mjs.map +1 -1
  101. package/esm/runtime/register-modules.d.mts +19 -0
  102. package/esm/runtime/register-modules.mjs +22 -0
  103. package/esm/runtime/register-modules.mjs.map +1 -0
  104. package/esm/server/build-hydration-payload.mjs +2 -1
  105. package/esm/server/build-hydration-payload.mjs.map +1 -1
  106. package/esm/server/client-asset-url-prefix.d.mts +1 -1
  107. package/esm/server/client-asset-url-prefix.mjs +1 -1
  108. package/esm/server/client-asset-url-prefix.mjs.map +1 -1
  109. package/esm/server/create-page-module-loader.d.mts +1 -1
  110. package/esm/server/create-page-module-loader.mjs +2 -1
  111. package/esm/server/create-page-module-loader.mjs.map +1 -1
  112. package/esm/server/create-page-route-handler.d.mts +31 -6
  113. package/esm/server/create-page-route-handler.mjs +128 -43
  114. package/esm/server/create-page-route-handler.mjs.map +1 -1
  115. package/esm/server/dev-server.mjs +2 -13
  116. package/esm/server/dev-server.mjs.map +1 -1
  117. package/esm/server/error-page.d.mts +14 -0
  118. package/esm/server/error-page.mjs +39 -0
  119. package/esm/server/error-page.mjs.map +1 -0
  120. package/esm/server/execute-page-request.d.mts +7 -4
  121. package/esm/server/execute-page-request.mjs +79 -80
  122. package/esm/server/execute-page-request.mjs.map +1 -1
  123. package/esm/server/execute-page-request.types.d.mts +33 -92
  124. package/esm/server/hydration-client-url.d.mts +1 -1
  125. package/esm/server/hydration-client-url.mjs +2 -2
  126. package/esm/server/hydration-client-url.mjs.map +1 -1
  127. package/esm/server/index.d.mts +5 -5
  128. package/esm/server/index.mjs +3 -4
  129. package/esm/server/install-page-routes-from-manifest.d.mts +17 -7
  130. package/esm/server/install-page-routes-from-manifest.mjs +71 -10
  131. package/esm/server/install-page-routes-from-manifest.mjs.map +1 -1
  132. package/esm/server/install-page-routes.d.mts +32 -15
  133. package/esm/server/install-page-routes.mjs +91 -39
  134. package/esm/server/install-page-routes.mjs.map +1 -1
  135. package/esm/server/install-production-page-routes.mjs +3 -36
  136. package/esm/server/install-production-page-routes.mjs.map +1 -1
  137. package/esm/server/match-page-route.mjs +2 -2
  138. package/esm/server/match-page-route.mjs.map +1 -1
  139. package/esm/server/not-found-page.d.mts +1 -1
  140. package/esm/server/not-found-page.mjs +2 -2
  141. package/esm/server/not-found-page.mjs.map +1 -1
  142. package/esm/server/page-context.d.mts +3 -9
  143. package/esm/server/page-context.mjs +3 -16
  144. package/esm/server/page-context.mjs.map +1 -1
  145. package/esm/server/page-file-change.mjs +77 -0
  146. package/esm/server/page-file-change.mjs.map +1 -0
  147. package/esm/server/page-manifest.d.mts +25 -10
  148. package/esm/server/page-manifest.mjs +1 -1
  149. package/esm/server/page-manifest.mjs.map +1 -1
  150. package/esm/server/page-render-bundle.mjs +38 -0
  151. package/esm/server/page-render-bundle.mjs.map +1 -0
  152. package/esm/server/page-route-reload.mjs +54 -0
  153. package/esm/server/page-route-reload.mjs.map +1 -0
  154. package/esm/server/register-production-public-files.mjs +40 -0
  155. package/esm/server/register-production-public-files.mjs.map +1 -0
  156. package/esm/server/render-page.d.mts +11 -14
  157. package/esm/server/render-page.mjs +154 -28
  158. package/esm/server/render-page.mjs.map +1 -1
  159. package/esm/server/resolve-page-metadata.mjs +2 -2
  160. package/esm/server/resolve-page-metadata.mjs.map +1 -1
  161. package/esm/server/resolve-validation-data.mjs +1 -1
  162. package/esm/server/resolve-validation-data.mjs.map +1 -1
  163. package/esm/server/settle-page-response.d.mts +58 -1
  164. package/esm/server/settle-page-response.mjs +111 -46
  165. package/esm/server/settle-page-response.mjs.map +1 -1
  166. package/esm/server/stylesheet-urls.d.mts +41 -30
  167. package/esm/server/stylesheet-urls.mjs +137 -52
  168. package/esm/server/stylesheet-urls.mjs.map +1 -1
  169. package/esm/server/unregistered-pages.mjs +42 -0
  170. package/esm/server/unregistered-pages.mjs.map +1 -0
  171. package/esm/server/web-connector-factory.d.mts +2 -3
  172. package/esm/server/web-connector-factory.mjs +7 -6
  173. package/esm/server/web-connector-factory.mjs.map +1 -1
  174. package/esm/server/web-connector.d.mts +1 -1
  175. package/esm/server/web-connector.mjs +138 -18
  176. package/esm/server/web-connector.mjs.map +1 -1
  177. package/esm/shared.d.mts +18 -3
  178. package/esm/shared.mjs +3 -7
  179. package/esm/shared.mjs.map +1 -1
  180. package/esm/validation.d.mts +1 -1
  181. package/esm/vite/app-convention-aliases.mjs +1 -1
  182. package/esm/vite/app-convention-aliases.mjs.map +1 -1
  183. package/esm/vite/build-client.d.mts +1 -1
  184. package/esm/vite/build-client.mjs +2 -2
  185. package/esm/vite/build-client.mjs.map +1 -1
  186. package/esm/vite/gate-a-resolve.d.mts +1 -1
  187. package/esm/vite/gate-a-resolve.mjs +67 -13
  188. package/esm/vite/gate-a-resolve.mjs.map +1 -1
  189. package/esm/vite/gate-b-secrets.d.mts +1 -1
  190. package/esm/vite/gate-b-secrets.mjs +35 -17
  191. package/esm/vite/gate-b-secrets.mjs.map +1 -1
  192. package/esm/vite/gate-c-verify.d.mts +1 -1
  193. package/esm/vite/gate-c-verify.mjs +6 -6
  194. package/esm/vite/gate-c-verify.mjs.map +1 -1
  195. package/esm/vite/hydration-entries.d.mts +1 -1
  196. package/esm/vite/hydration-entries.mjs +2 -2
  197. package/esm/vite/hydration-entries.mjs.map +1 -1
  198. package/esm/vite/index.d.mts +9 -6
  199. package/esm/vite/index.mjs +124 -11
  200. package/esm/vite/index.mjs.map +1 -1
  201. package/esm/vite/page-registry-plugin.d.mts +22 -3
  202. package/esm/vite/page-registry-plugin.mjs +48 -14
  203. package/esm/vite/page-registry-plugin.mjs.map +1 -1
  204. package/esm/vite/projection.d.mts +2 -2
  205. package/esm/vite/projection.mjs +38 -15
  206. package/esm/vite/projection.mjs.map +1 -1
  207. package/llms-full.txt +220 -56
  208. package/llms.txt +5 -3
  209. package/package.json +3 -3
  210. package/skills/add-web-to-an-app/SKILL.md +3 -3
  211. package/skills/create-a-page/SKILL.md +117 -10
  212. package/skills/load-page-data/SKILL.md +92 -12
  213. package/skills/navigate-on-the-client/SKILL.md +1 -1
  214. package/skills/serve-styles/SKILL.md +13 -12
  215. package/skills/use-layouts/SKILL.md +14 -8
  216. package/skills/write-the-root/SKILL.md +3 -1
  217. package/esm/server/buffered-response.d.mts +0 -58
  218. package/esm/server/buffered-response.mjs +0 -115
  219. package/esm/server/buffered-response.mjs.map +0 -1
package/llms-full.txt CHANGED
@@ -2,17 +2,7 @@
2
2
 
3
3
  > Package: `@warlock.js/web`
4
4
 
5
- > SSR React pages served by the same Warlock HTTP server that serves the API a backend framework that renders React, not a React framework.
6
-
7
- > First published release: 5.0.0. `@warlock.js/web` had never been published to npm before this release.
8
-
9
- > Use 5.1 or newer. In an installed 5.0.0–5.0.2 app no client JavaScript ran at all: the dev server served `react-dom/client` as raw CommonJS, so `hydrateRoot` was missing and hydration failed on import — dead `useState`, no HMR, `<Link>` falling back to full page loads. Pages still server-rendered, which is why it looked like a React problem.
10
-
11
- > Consumer entry points: `@warlock.js/web`, `@warlock.js/web/client/runtime`, `@warlock.js/web/connector`, and `@warlock.js/web/vite`. The published `@warlock.js/web/hydration` subpath is a framework build input; application code never imports it.
12
-
13
- > Deliberate non-goals: server actions are a v2 design decision rather than a missing v1 feature; page routes reject regex parameters, optional parameters, and multiple parameters in one segment.
14
-
15
- > Hand-maintained. Concatenates every SKILL.md and reference file under `@warlock.js/web/skills/`. Update this file by hand when the package's public API changes.
5
+ > Generated artifact. Concatenates every SKILL.md and reference file under `@warlock.js/web/skills/`. Re-run `node scripts/generate-llms.mjs` after any change.
16
6
 
17
7
  ## add-web-to-an-app `@warlock.js/web/add-web-to-an-app/SKILL.md`
18
8
 
@@ -28,7 +18,7 @@ description: 'Install the SSR page layer with `warlock add web`: add React/Vite
28
18
  ## The shape
29
19
 
30
20
  ```bash
31
- yarn warlock add web
21
+ pnpm warlock add web
32
22
  ```
33
23
 
34
24
  On the ordinary path it leaves this application-owned shape:
@@ -99,8 +89,8 @@ On the refusal path, free `/` yourself and create a page with either `route = "/
99
89
  Read the files rather than assuming the command could patch every application shape:
100
90
 
101
91
  ```bash
102
- yarn warlock routes --method GET --path /
103
- yarn warlock routes --method GET --path /welcome
92
+ pnpm warlock routes --method GET --path /
93
+ pnpm warlock routes --method GET --path /welcome
104
94
  ```
105
95
 
106
96
  The desired result is one page route at `/` and, when the stock JSON route existed, one API route at `/welcome`.
@@ -124,16 +114,16 @@ The desired result is one page route at `/` and, when the stock JSON route exist
124
114
 
125
115
  ---
126
116
  name: create-a-page
127
- description: 'Create an SSR React page under `src/web/**` or `src/app/<module>/web/**` with a literal `route`, a default component, an optional typed `loader`, and page `metadata`; know when a dev edit gets Fast Refresh vs. a full reload. Triggers: `*.page.tsx`, `route`, `PageLoader`, `PageProps`, `PageMetadata`, Fast Refresh, HMR; "create a page", "add an SSR route", "make a React page", "type page loader data", "why did my edit reload the page"; typical import `import type { PageLoader, PageProps } from "@warlock.js/web"`. Skip: root document shell — `@warlock.js/web/write-the-root/SKILL.md`; layout wrappers and prefixes — `@warlock.js/web/use-layouts/SKILL.md`; loader lifecycle and `shared` — `@warlock.js/web/load-page-data/SKILL.md`; competing frameworks `next`, `remix`, `react-router` file routes.'
117
+ description: 'Create an SSR React page under `src/web/**`, with either a literal `route` or a filesystem-derived one, a default component, an optional typed `loader`, page `metadata`, the `error.page.tsx` boundary, and the universal `register()` hook. Triggers: `*.page.tsx`, `route`, `PageLoader`, `PageProps`, `PageMetadata`, `error.page.tsx`, `register`, `[...slug]`; "create a page", "add an SSR route", "make a React page", "type page loader data", "add an error boundary", "catch-all route", "page renders blank 200", "page has no default export"; typical import `import type { PageLoader, PageProps } from "@warlock.js/web"`. Skip: root document shell — `@warlock.js/web/write-the-root/SKILL.md`; layout wrappers and prefixes — `@warlock.js/web/use-layouts/SKILL.md`; loader lifecycle and `shared` — `@warlock.js/web/load-page-data/SKILL.md`; competing frameworks `next`, `remix`, `react-router` file routes.'
128
118
  ---
129
119
 
130
120
  # Warlock — create a page
131
121
 
132
- A page is any `*.page.tsx` beneath the global `src/web/` tree or a module's `src/app/<module>/web/` tree. Its URL is declared by `route`; its default export renders React.
122
+ A page is any `*.page.tsx` beneath `src/web/` the only page root. (A per-module `src/app/<module>/web/` tree is not scanned; move any page that lived there into `src/web/`, a subdirectory if you like.) Its URL is either a declared `route` or one derived from its own location; its default export renders React.
133
123
 
134
124
  ## The shape
135
125
 
136
- ```tsx title="src/app/products/web/product-details.page.tsx"
126
+ ```tsx title="src/web/products/product-details.page.tsx"
137
127
  import type { PageLoader, PageMetadata, PageProps } from "@warlock.js/web";
138
128
 
139
129
  export const route = {
@@ -186,9 +176,28 @@ export default function ContactPage() {
186
176
  }
187
177
  ```
188
178
 
189
- The `route` export is required, and a page without one is **refused, not skipped**. `warlock dev` and the production discovery pass throw the same `MissingRouteExportError`, naming the file, because a page with no route is a page nothing can ever reach.
179
+ `route` is optional. A page that omits it derives both its path and its name from where the file sits beneath `src/web` ([filesystem routing](#filesystem-routing), below). A page that declares `route` uses that instead — an explicit `route` always wins over the derived one, for both the path and (when it sets `name`) the name.
180
+
181
+ Changed in 5.2: through 5.1 an omitted `route` was refused — `warlock dev` and the production discovery pass threw `MissingRouteExportError`, naming the file. That error class is gone; the same file now resolves to a real, browsable URL.
182
+
183
+ ### The default export is required
184
+
185
+ `route` is optional; the default export is not. A `*.page.tsx` that exports only named bindings is a **hard discovery/build failure naming the file**:
186
+
187
+ ```
188
+ The page "src/web/contact.page.tsx" has no runtime default export. Every `*.page.tsx`
189
+ file must default-export the React component it renders. For example:
190
+ `export default function Page() { return <main />; }`
191
+ ```
190
192
 
191
- Changed in 5.1: through 5.0.2 the dev server silently skipped a route-less page, so the file you had just written 404'd with nothing said. Dev and build now reach the same verdict from the same condition.
193
+ Changed in 5.2: such a file used to be discovered and registered anyway, then serve a blank `200` at its URL a page that looked deployed and rendered nothing, with no error anywhere. It now stops the build.
194
+
195
+ Two details worth knowing:
196
+
197
+ - **`export { Page as default }` satisfies the rule** — the check is for a runtime default binding, not for the `export default` keyword form specifically.
198
+ - **`export default interface Page {}` does not.** A type-only default is erased at compile time, so there is no component at runtime; it is treated as missing.
199
+
200
+ A file that cannot be parsed reports separately — `Cannot inspect the default export of "<file>": the file could not be parsed (…). Fix the syntax error and discovery will continue.` — so a syntax error never masquerades as a missing export.
192
201
 
193
202
  ## Route declarations
194
203
 
@@ -205,18 +214,44 @@ export const route = {
205
214
  } as const;
206
215
  ```
207
216
 
208
- Prefer an explicit stable `name` for links. Without one, Warlock derives a name from the module and declared path: a module page gets `<module>.<path-as-dots>`, a global root page gets `index`, and another global page gets its dotted path.
217
+ Prefer an explicit stable `name` for links. Without one, Warlock derives a name from the declared path a global root page gets `index`, another global page gets its dotted path — the same derivation [filesystem routing](#filesystem-routing) uses when there is no `route` at all.
209
218
 
210
- **Only the route NAME is ever derived — never the route PATH.** There is no filename-to-URL convention in Warlock and there never has been. Omitting `route` does not fall back to the file's location; it fails (see above). Every segment of a page's URL is written down somewhere: the page's own `route.path`, prefixed by the literal `prefix` exports of the positional layouts above it ([use-layouts](../use-layouts/SKILL.md)). Where the file sits decides which layouts are above it — never what the path spells.
219
+ Every segment of a page's URL is written down somewhere: `route.path` (or the derived filesystem path), prefixed by the literal `prefix` exports of the positional layouts above it ([use-layouts](../use-layouts/SKILL.md)). Where the file sits always decides which layouts are above it, and only when `route` is absent — the path segments too.
211
220
 
212
221
  The build reads `route` without executing application code. Declare it directly with `export const` and literal strings. Variables, function calls, computed object keys, spreads, and `export { route }` are refused.
213
222
 
223
+ ## Filesystem routing
224
+
225
+ Omit `route` and the URL comes from the page's own path beneath `src/web`:
226
+
227
+ - Every directory contributes a segment, in order — `src/web/products/featured.page.tsx` derives `/products/featured`.
228
+ - A `(group)` directory — parentheses, not braces — contributes nothing to the URL, only to organization: `src/web/(marketing)/pricing.page.tsx` derives `/pricing`.
229
+ - `index.page.tsx` claims its own directory rather than adding a segment: `src/web/products/index.page.tsx` derives `/products`. This is the ONLY filename with special meaning — `home.page.tsx` is not magic and derives `/home`.
230
+ - `[id]` becomes `:id`: `src/web/products/[id].page.tsx` derives `/products/:id`.
231
+ - A layout `prefix` on the page's ancestry composes in front of the derived path exactly as it does for an explicit `route.path` ([use-layouts](../use-layouts/SKILL.md)).
232
+
233
+ Two pages that derive (or declare) the same effective path is a build error naming both files.
234
+
235
+ ### Catch-all segments are NOT supported
236
+
237
+ **`[...slug].page.tsx` does not do what it looks like.** There is no catch-all / rest-parameter form in filesystem routing. Only `[name]` — a plain identifier in square brackets — is recognized as a dynamic segment; `[...slug]` fails that pattern and is taken as an ordinary **literal** segment.
238
+
239
+ So `src/web/docs/[...slug].page.tsx` derives the route path `/docs/[...slug]` and the route name `docs.[...slug]`. It registers, it builds, and it serves — at the literal URL `/docs/%5B...slug%5D` and nowhere else. `/docs/a/b` does not match it.
240
+
241
+ ⚠ **Nothing warns you.** There is no build error, no dev warning, and no refusal; the page simply answers a URL nobody will ever request. If you came from Next.js or Remix expecting `[...slug]` to work, this is the failure mode to recognize.
242
+
243
+ Until a catch-all exists, use the terminal wildcard with an explicit `route`:
244
+
245
+ ```tsx
246
+ export const route = { path: "/docs/*", name: "docs.catchAll" } as const;
247
+ ```
248
+
214
249
  ## Page-route grammar
215
250
 
216
251
  Page routes deliberately accept less than API routes:
217
252
 
218
253
  - Supported: `/`, static segments, whole-segment params such as `/products/:id`, the exact wildcard `*`, and a terminal wildcard such as `/docs/*`.
219
- - Not supported: regex params, optional params, multiple params in one segment, params mixed with text, doubled or trailing slashes, and non-terminal wildcards.
254
+ - Not supported: regex params, optional params, multiple params in one segment, params mixed with text, doubled or trailing slashes, non-terminal wildcards, and catch-all/rest segments (`[...slug]`).
220
255
 
221
256
  Write two pages for an optional segment. Validate a constrained parameter in the page instead of putting a regex in its path.
222
257
 
@@ -240,6 +275,39 @@ export const metadata: PageMetadata = {
240
275
 
241
276
  Supported fields are `title`, `description`, `keywords`, `canonical`, `robots`, `openGraph`, and `twitter`. Function metadata runs after a successful loader. If a loader fails, Warlock uses error metadata instead of calling the page function with missing data.
242
277
 
278
+ ## The error boundary — `error.page.tsx`
279
+
280
+ `error.page.tsx` anywhere beneath `src/web` is the application's one error boundary — exactly two page filenames are special in Warlock, this and `404.page.tsx`. A second `error.page.tsx` is a build error naming both files. Like `404.page.tsx`, it declares no `route` — it has no URL of its own and is reached only when something throws.
281
+
282
+ ```tsx title="src/web/error.page.tsx"
283
+ import type { ErrorPageProps } from "@warlock.js/web";
284
+
285
+ export default function ErrorPage({ error, status }: ErrorPageProps) {
286
+ return (
287
+ <main>
288
+ <h1>Something went wrong</h1>
289
+ <p>Status: {status}</p>
290
+ </main>
291
+ );
292
+ }
293
+ ```
294
+
295
+ During SSR the component receives the real thrown value in `error`. After hydration it receives the JSON-safe `{ name, message, stack? }` shape instead — the original value does not survive the wire. `robots: noindex` is a framework default on this path that an app-supplied `metadata` cannot remove.
296
+
297
+ If the failure happens before any page module could even load — a module-load or `register()` throw — there is no trustworthy server composition left to hydrate against, so Warlock renders a plain framework fallback (your `error.page.tsx` if it can still be loaded, otherwise a minimal built-in boundary) with no hydration script at all rather than risk hydrating client code against markup nothing can vouch for.
298
+
299
+ ## The `register()` hook
300
+
301
+ `root.tsx`, `layout.tsx`, and `*.page.tsx` may each export `register`: a synchronous, no-argument, side-effect hook that runs once per module namespace instance, on both the server and the browser, before that module's middleware or loader. Unlike `route`/`middleware`/`validation`/`loader`/`metadata`, it is not stripped from the client — it is meant to run on both sides.
302
+
303
+ ```tsx
304
+ export function register() {
305
+ // one-time setup for this module namespace; must not return a Promise
306
+ }
307
+ ```
308
+
309
+ Returning a Promise (or anything thenable) throws — `register()` must finish before the module is usable.
310
+
243
311
  ## The client boundary
244
312
 
245
313
  The browser boundary is decided by the import graph, not by the file's location. A `*.page.tsx` is universal:
@@ -259,13 +327,22 @@ Keep server-only repository and service reads inside `loader`. Do not read them
259
327
  - **A `metadata`-only edit reloads the document.** `metadata` sits outside the skeleton's masked region, so the edit moves it. Warlock sends a full reload, which re-runs SSR and rebuilds `<head>`. Component state is lost — that is the price of seeing the new `<title>` without touching the browser.
260
328
  - **Any module-level change reloads, not just `metadata`.** An edited import, a module-level declaration, or an edit confined to `route`, `middleware`, `validation`, or `loader` all move the skeleton the same way and take the same full-reload path.
261
329
  - **A helper function used only by the JSX still reloads if it is declared at module level.** The rule does not try to prove which half of a shared declaration the edit was "really" for — it over-approximates deliberately, because a false reload only costs component state, while a missed one ships a stale `<head>` and calls it a hot update.
262
- - Creating or deleting a page file is page-graph churn, not an in-place edit; Vite handles it on its own.
330
+ - Creating, deleting, or renaming a page file, or editing its `route` export, is page-GRAPH churn, not a skeleton edit see below, not Fast Refresh.
263
331
 
264
332
  Changed in 5.1: a metadata-only edit previously left a stale `<head>` until you refreshed the browser by hand. The current skeleton-comparison rule replaces that earlier, narrower "metadata-only" special case.
265
333
 
334
+ ## Route-table changes in development
335
+
336
+ Creating a page, deleting one, or editing its `route` export's path is a different kind of dev edit from the skeleton comparison above — it changes which URLs exist, not just how one already-registered URL renders. `warlock dev` re-registers the affected route(s) in the live route table, atomically and with no dev-server restart, so the new file (or new path) is reachable on the very next request with no manual restart.
337
+
338
+ Changed in 5.2: through 5.1 the route table was built once at boot and never again. Creating a page 404'd forever; deleting one kept it reachable at its old URL; editing `route` served the OLD path from the old file and 404'd the new one — the running server silently disagreed with the source on disk. All three are now live.
339
+
266
340
  ## Gotchas
267
341
 
268
- - **Do not expect URLs to be derived from filenames.** No such convention exists. The file's location chooses discovery and which layout prefixes apply; `route` chooses the rest of the public URL. A page with no `route` is refused, not mounted at its path.
342
+ - **A page with no `route` is not unreachable.** It derives a real URL from its file location see [Filesystem routing](#filesystem-routing). Nothing about a route-less page is refused anymore.
343
+ - **A page with no default export IS refused.** Named exports alone fail the build naming the file, instead of serving a blank 200.
344
+ - **`[...slug]` is not a catch-all.** It is read as a literal path segment and silently produces an unreachable route — see [Catch-all segments are NOT supported](#catch-all-segments-are-not-supported).
345
+ - **`process.env` is refused in the client/universal graph, `PUBLIC_` prefix included.** Read env values in a loader and return them as page data; see [`load-page-data/SKILL.md`](../load-page-data/SKILL.md).
269
346
  - **Keep `route` literal.** A computed route cannot be discovered without executing app code and is refused.
270
347
  - **Do not annotate the loader with `: PageLoader`.** That erases the return type `PageProps` needs.
271
348
  - **Components receive data, not HTTP objects.** `request` and `response` belong to loaders; the component also renders in the browser.
@@ -284,16 +361,86 @@ Changed in 5.1: a metadata-only edit previously left a stale `<head>` until you
284
361
 
285
362
  ---
286
363
  name: load-page-data
287
- description: 'Load App, Layout, and Page data with `AppLoader`, `LayoutLoader`, and `PageLoader`; type component `data`, validate page input, short-circuit with the buffered response, and publish request-scoped browser-safe values through `shared`. Triggers: `PageLoader`, `LayoutLoader`, `AppLoader`, `PageProps`, `shared`, `useShared`, `validation`, `request.validated`; "load page data", "pass server data to React", "share request data", "redirect from a loader". Skip: page module basics — `@warlock.js/web/create-a-page/SKILL.md`; layouts — `@warlock.js/web/use-layouts/SKILL.md`; mutation follow-up — `@warlock.js/web/navigate-on-the-client/SKILL.md`; competing loaders Next data functions, Remix loaders, React Server Components.'
364
+ description: 'Load App, Layout, and Page data with `AppLoader`, `LayoutLoader`, and `PageLoader`; type component `data`, validate page input, short-circuit with the buffered response, and publish request-scoped browser-safe values through `shared`. Triggers: `PageLoader`, `LayoutLoader`, `AppLoader`, `PageProps`, `shared`, `useShared`, `validation`, `request.validated`, `process.env`, `env("PUBLIC_...")`, `import.meta.env.PUBLIC_`; "load page data", "pass server data to React", "share request data", "redirect from a loader", "read an environment variable in a page", "process.env refused in the client build", "loader execution order", "return a Response from a loader". Skip: page module basics — `@warlock.js/web/create-a-page/SKILL.md`; layouts — `@warlock.js/web/use-layouts/SKILL.md`; mutation follow-up — `@warlock.js/web/navigate-on-the-client/SKILL.md`; competing loaders Next data functions, Remix loaders, React Server Components.'
288
365
  ---
289
366
 
290
367
  # Warlock — load page data
291
368
 
292
369
  Loaders run on the server and return serializable data to their own component level. Use the level-specific loader type with `satisfies`, then pass `typeof loader` to the matching props type.
293
370
 
371
+ ## Pass environment values through loader data
372
+
373
+ **`process.env` is refused outright in the client/universal graph, and there is
374
+ no `PUBLIC_` exception to it — static or computed.** `env("PUBLIC_X")` does not
375
+ work client-side either. **The supported pattern is: read the value in a loader,
376
+ which is server code, and return it as page data.**
377
+
378
+ ```tsx
379
+ import { env } from "@warlock.js/core";
380
+ import type { PageLoader, PageProps } from "@warlock.js/web";
381
+
382
+ export const loader = (async () => ({
383
+ siteName: env("PUBLIC_SITE_NAME"),
384
+ })) satisfies PageLoader;
385
+
386
+ export default function HomePage({ data }: PageProps<typeof loader>) {
387
+ return <h1>{data.siteName}</h1>;
388
+ }
389
+ ```
390
+
391
+ Loaders are server-only and may read configuration normally. Their return is
392
+ serialized to the browser, so include only values that are safe to expose.
393
+
394
+ ### What is refused, and where
395
+
396
+ Every one of these fails the build when it is reachable from a default page or
397
+ layout component, `register()`, or any helper they import:
398
+
399
+ ```tsx
400
+ process.env.API_URL; // static key — refused
401
+ process.env.PUBLIC_API_URL; // a PUBLIC_ prefix changes nothing — refused
402
+ process.env[key]; // computed key — refused
403
+ const { API_URL } = process.env; // bare value-read — refused
404
+ const all = { ...process.env }; // bare value-read — refused
405
+ Object.keys(process.env); // bare value-read — refused
406
+ JSON.stringify(process.env); // bare value-read — refused
407
+ env("PUBLIC_API_URL"); // pulls in @warlock.js/core, a server package — refused
408
+ ```
409
+
410
+ Bare value-reads matter as much as keyed ones: `process` does not exist in a
411
+ browser, so referencing the object at all — assigned, destructured, spread, or
412
+ passed as an argument — is already broken, and passing the whole object to a
413
+ component is how a server secret reaches a page in one line.
414
+
415
+ **Enforcement covers dev SSR as well as the client bundle, and a violation
416
+ fails the build.** It is not a production-only check you can discover late: the
417
+ same refusal fires under `warlock dev`.
418
+
419
+ Reads inside `loader`, `route`, `middleware`, `validation`, and `metadata` are
420
+ never affected — those exports are stripped before the client graph is formed.
421
+ Server-side code is unrestricted.
422
+
423
+ ### The one client-side escape hatch
424
+
425
+ If a value genuinely has to be inlined into browser code rather than passed
426
+ through loader data, the supported spelling is `import.meta.env.PUBLIC_*` with a
427
+ **static** key:
428
+
429
+ ```tsx
430
+ export default function HomePage() {
431
+ return <h1>{import.meta.env.PUBLIC_SITE_NAME}</h1>;
432
+ }
433
+ ```
434
+
435
+ `import.meta.env` is the Vite surface, not Node's, and only the `PUBLIC_` prefix
436
+ (plus Vite's own `MODE`, `DEV`, `PROD`, `BASE_URL`, `SSR`) is allowed through. It
437
+ is inlined at build time, so it cannot vary per request or per deployment of the
438
+ same bundle — which is why loader data remains the default answer, and the only
439
+ one for anything request-scoped.
440
+
294
441
  ## The shape
295
442
 
296
- ```tsx title="src/app/products/web/product-details.page.tsx"
443
+ ```tsx title="src/web/products/product-details.page.tsx"
297
444
  import { v } from "@warlock.js/seal";
298
445
  import type { PageLoader, PageProps } from "@warlock.js/web";
299
446
 
@@ -340,11 +487,11 @@ export default function ProductDetailsPage({ data }: PageProps<typeof loader>) {
340
487
 
341
488
  ## Three loader levels
342
489
 
343
- | Module | Contract | Component props |
344
- | --- | --- | --- |
345
- | `src/web/root.tsx` | `AppLoader` | `AppProps<typeof loader>` |
490
+ | Module | Contract | Component props |
491
+ | ----------------------- | -------------- | ---------------------------- |
492
+ | `src/web/root.tsx` | `AppLoader` | `AppProps<typeof loader>` |
346
493
  | positional `layout.tsx` | `LayoutLoader` | `LayoutProps<typeof loader>` |
347
- | `*.page.tsx` | `PageLoader` | `PageProps<typeof loader>` |
494
+ | `*.page.tsx` | `PageLoader` | `PageProps<typeof loader>` |
348
495
 
349
496
  All receive one context object with `request`, `response`, and `shared`. Page loaders add generics that connect their sibling `validation` and `route` exports to `request.validated()` and `request.input()`.
350
497
 
@@ -359,9 +506,17 @@ When `validating` is absent or empty, pages validate query + params, with params
359
506
 
360
507
  `request.validated()` uses the schema's output type, so fields with `.default(...)` are present. `request.input("id")` is narrowed from a literal route path when the loader uses `typeof route`.
361
508
 
509
+ ## Execution order
510
+
511
+ Loaders run **sequentially, root to leaf, each one awaited before the next starts**: `root.tsx`'s `AppLoader`, then the layout's `LayoutLoader`, then the page's `PageLoader`. There are exactly three levels — a page has at most one _rendering_ layout (nested rendering layouts are a build error), so there is no outer-layout/inner-layout loader chain to reason about. Layout _middleware_ still composes across the whole ancestry; only the loader levels are capped at three.
512
+
513
+ **The first core `Response` a loader returns is terminal.** Returning a `Response` object stops the pipeline immediately: no lower loader starts, `metadata` is not resolved, and that response is sent as-is. It is more terminal than a short-circuit — because the response is returned whole, the buffered header/cookie writes made at that same level are discarded along with everything below it. Use `response.redirect()` / `response.notFound()` (which produce a `LoaderShortCircuit`, committing that level's buffer inclusively) when you want your buffered writes to survive; return a raw `Response` only when you mean "this exact response, nothing else."
514
+
515
+ A loader that **throws** is also terminal: it stops lower loaders, discards its own level's buffer, and commits only the levels above it.
516
+
362
517
  ## Loader response surface
363
518
 
364
- Each loader gets its own buffered response because App, Layout, and Page loaders execute in parallel. The public loader methods are:
519
+ Each loader gets its own buffered response never the live one so that a level discarded by a short-circuit or a throw cannot leak half-written headers onto a response it no longer owns. The public loader methods are:
365
520
 
366
521
  ```ts
367
522
  response.header("cache-control", "private, max-age=60");
@@ -426,7 +581,7 @@ The request pipeline is:
426
581
 
427
582
  1. App, layout, and page middleware run outermost first and write `shared`.
428
583
  2. `shared` is normalized, checked, and sealed.
429
- 3. App, layout, and page loaders run in parallel and may only read it.
584
+ 3. App, layout, and page loaders run in order, root to leaf, and may only read it.
430
585
  4. Components receive a readonly snapshot through props or `useShared()`.
431
586
 
432
587
  Use `useShared()` in a deep component that is not already receiving level props:
@@ -443,12 +598,12 @@ export function LocaleLabel() {
443
598
 
444
599
  Only put browser-safe data in `shared`: scalars, arrays, plain objects, or values with a valid `toJSON()` contract. Functions, `Date`, `Map`, `Set`, and arbitrary class instances are rejected. Prefer a narrow Resource output over a model.
445
600
 
446
- ## Parallelism rules
601
+ ## Level isolation rules
447
602
 
448
- - App, Layout, and Page loaders cannot read each other's return values.
603
+ - App, Layout, and Page loaders cannot read each other's return values. They run in order, but no channel is provided between them — a lower loader is not handed what an upper one returned. Put anything a lower level needs into `shared` from middleware instead.
449
604
  - A loader may read `shared` because middleware completed and it was sealed first.
450
605
  - A loader must not write `shared`; a post-seal write throws.
451
- - Loader response mutations are buffered per level and settled deterministically.
606
+ - Loader response mutations are buffered per level and settled deterministically, root to leaf.
452
607
 
453
608
  ## Gotchas
454
609
 
@@ -456,7 +611,9 @@ Only put browser-safe data in `shared`: scalars, arrays, plain objects, or value
456
611
  - **Return client-safe data.** Components render again in the browser; models and server handles do not survive the wire.
457
612
  - **Write `shared` in middleware only.** Loaders run after the seal.
458
613
  - **Required shared keys need unconditional writers.** The type is a promise for every request.
459
- - **Do not use loader return values as cross-level communication.** The loaders run in parallel.
614
+ - **Do not use loader return values as cross-level communication.** Levels run in order but are not wired to each other; use `shared`, written in middleware.
615
+ - **`404.page.tsx` never runs its own loader.** The not-found page's module is registered and rendered for real — `register()` and its middleware still run — but the page loader is omitted from the request in both dev and production, so a missing URL cannot trigger application data work or fail a second time. Its ancestry contributes nothing either: the 404 page renders with an empty layout chain by construction. **The root `AppLoader` in `root.tsx` still runs** for a 404 request, so keep it cheap and make sure it tolerates a request that matched nothing.
616
+ - **`process.env` is refused in the client/universal graph, with no `PUBLIC_` exception.** Read it in a loader and return it as page data.
460
617
  - **Server actions are not supported.** POST to an ordinary Warlock API route and call `refresh()` after success.
461
618
 
462
619
  ## See also
@@ -576,7 +733,7 @@ export function CheckoutButtons() {
576
733
 
577
734
  The public primitive is `refresh()`. There is no `revalidate()` export.
578
735
 
579
- ```tsx title="src/app/products/web/delete-product-button.tsx"
736
+ ```tsx title="src/web/products/delete-product-button.tsx"
580
737
  import { refresh } from "@warlock.js/web";
581
738
 
582
739
  export function DeleteProductButton({ id }: { id: string }) {
@@ -721,7 +878,7 @@ Root imports ending in `.css`, `.scss`, `.sass`, `.less`, or `.styl` are recogni
721
878
 
722
879
  A page may import CSS directly:
723
880
 
724
- ```tsx title="src/app/products/web/products.page.tsx"
881
+ ```tsx title="src/web/products/products.page.tsx"
725
882
  import "./products.css";
726
883
 
727
884
  export const route = {
@@ -738,7 +895,7 @@ export default function ProductsPage() {
738
895
  }
739
896
  ```
740
897
 
741
- ```css title="src/app/products/web/products.css"
898
+ ```css title="src/web/products/products.css"
742
899
  .products-page {
743
900
  display: grid;
744
901
  gap: 1rem;
@@ -747,7 +904,7 @@ export default function ProductsPage() {
747
904
 
748
905
  Recognized asset imports survive the page's client projection. The client boundary is determined by the import graph, not by the file living under `web/`.
749
906
 
750
- In development, only root stylesheet imports are converted into render-blocking document links. A page-local import is loaded by Vite's client module graph around hydration, so it still applies but is not guaranteed before first paint. Move above-the-fold or site-wide rules into a stylesheet imported by `root.tsx` when avoiding a flash matters.
907
+ For each matched handler, Warlock builds one ordered CSS chain: `[root, ...matched layouts, page]`. A stylesheet imported directly by any member of that chain becomes a render-blocking link in the initial document in both development and production. Unrelated pages and layouts do not contribute CSS to this response.
751
908
 
752
909
  ## Production delivery
753
910
 
@@ -757,9 +914,9 @@ The production client build enables Vite's manifest. Vite records emitted CSS ag
757
914
  <build.outdir>/client/.vite/manifest.json
758
915
  ```
759
916
 
760
- It collects every valid `css` asset across all manifest entries, deduplicates them in manifest order, and emits each as a render-blocking link before `</head>`.
917
+ For each source in the matched handler chain, Warlock finds that source's manifest entry, collects its own CSS plus CSS from statically imported chunks, and emits the ordered, deduplicated result as render-blocking links before `</head>`. It does not follow `dynamicImports`, because doing so would pull unrelated lazy pages into the response.
761
918
 
762
- That means both root-imported and page-imported CSS are linked in the initial production document. The current implementation collects across the whole client manifest rather than selecting only the matched route's CSS, so every page receives the emitted stylesheet set.
919
+ That means root-, matched-layout-, and page-imported CSS are linked in the initial production document without shipping another page's stylesheet set.
763
920
 
764
921
  Only manifest URLs under the one client asset prefix are emitted; a stylesheet outside the mounted asset directory is dropped instead of producing a dead link.
765
922
 
@@ -780,17 +937,16 @@ The hydration entry is built from the projected client graph. CSS imports are kn
780
937
 
781
938
  ## Diagnose missing or late CSS
782
939
 
783
- 1. For global CSS in development, confirm `root.tsx` uses a bare import such as `import "./app.css";`.
940
+ 1. In development, confirm the root, matched layout, or page imports the stylesheet directly with a bare import such as `import "./app.css";`.
784
941
  2. Confirm the rendered document contains a closing `</head>` and a stylesheet URL ending in `?direct`.
785
- 3. For page-local CSS in development, expect Vite's client graph to apply it after hydration; move critical rules to the root import if first paint matters.
786
- 4. In production, confirm `.vite/manifest.json` has `css` arrays and the referenced files live under the client asset prefix.
942
+ 3. If CSS is imported indirectly through another JavaScript module in development, Vite's client graph still applies it, but Warlock's source scan cannot promote it to a render-blocking link; import critical CSS directly from a chain member.
943
+ 4. In production, confirm `.vite/manifest.json` has a source entry for the matched root/layout/page and that its `css` arrays reference files under the client asset prefix.
787
944
  5. Do not hand-author a link to a hashed production asset; its name belongs to the Vite manifest.
788
945
 
789
946
  ## Gotchas
790
947
 
791
- - **Root CSS and page CSS differ in dev.** Root imports are render-blocking; page imports are client-injected.
792
- - **Production currently links all emitted CSS on every page.** It is safe for first paint but not route-minimal.
793
- - **Use a bare root import.** `devStylesheetUrls` scans `import "./app.css"`, not a bound CSS-module import.
948
+ - **CSS is scoped to the matched handler chain.** Root CSS is shared; only the current route's matched layouts and page add their direct imports.
949
+ - **Use a bare direct import.** `devStylesheetUrls` scans `import "./app.css"` in each chain member, not a bound CSS-module import or an import hidden behind another JavaScript module.
794
950
  - **Keep a closing `</head>`.** Automatic link installation has nowhere safe to write without it.
795
951
  - **Do not remove `?direct` from a dev stylesheet link.** Vite otherwise responds with JavaScript.
796
952
  - **Do not import the hydration entry yourself.** The connector owns dev serving and production asset URLs.
@@ -805,7 +961,7 @@ The hydration entry is built from the projected client graph. CSS imports are kn
805
961
 
806
962
  ---
807
963
  name: use-layouts
808
- description: 'Wrap pages with positional `layout.tsx` modules, compose literal `prefix` exports, load typed layout data with `LayoutLoader` / `LayoutProps`, preserve layout state during client navigation, and know why `404.page.tsx` never receives a layout. Triggers: `layout.tsx`, `prefix`, `LayoutLoader`, `LayoutProps`, `children`, `404.page.tsx`; "add a page layout", "share navigation between pages", "prefix page routes", "keep a layout mounted", "404 page has no layout". Skip: full-document root — `@warlock.js/web/write-the-root/SKILL.md`; page route export — `@warlock.js/web/create-a-page/SKILL.md`; loader and shared lifecycle — `@warlock.js/web/load-page-data/SKILL.md`; competing layout systems `next/layout`, React Router outlets, Remix nested routes.'
964
+ description: 'Wrap pages with positional `layout.tsx` modules, compose literal `prefix` exports, load typed layout data with `LayoutLoader` / `LayoutProps`, and preserve layout state during client navigation. Triggers: `layout.tsx`, `prefix`, `LayoutLoader`, `LayoutProps`, `children`; "add a page layout", "share navigation between pages", "prefix page routes", "keep a layout mounted". Skip: full-document root — `@warlock.js/web/write-the-root/SKILL.md`; page route export — `@warlock.js/web/create-a-page/SKILL.md`; loader and shared lifecycle — `@warlock.js/web/load-page-data/SKILL.md`; competing layout systems `next/layout`, React Router outlets, Remix nested routes.'
809
965
  ---
810
966
 
811
967
  # Warlock — use layouts
@@ -814,7 +970,7 @@ A positional `layout.tsx` applies to pages in its directory and descendant direc
814
970
 
815
971
  ## The shape
816
972
 
817
- ```tsx title="src/app/products/web/layout.tsx"
973
+ ```tsx title="src/web/products/layout.tsx"
818
974
  import type { LayoutLoader, LayoutProps } from "@warlock.js/web";
819
975
 
820
976
  export const prefix = "/products";
@@ -849,7 +1005,7 @@ export default function ProductsLayout({
849
1005
 
850
1006
  A page beside it can declare its path relative to the prefix:
851
1007
 
852
- ```tsx title="src/app/products/web/index.page.tsx"
1008
+ ```tsx title="src/web/products/index.page.tsx"
853
1009
  export const route = {
854
1010
  path: "/",
855
1011
  name: "products.index",
@@ -864,17 +1020,17 @@ The effective URL is `/products`. A page with `route.path = "/:id"` under the sa
864
1020
 
865
1021
  ## Prefix composition
866
1022
 
867
- Every positional layout on the page's directory ancestry may export a literal `prefix`. Prefixes compose outermost first, then the page's own route path.
1023
+ Every positional layout on the page's directory ancestry may export a literal `prefix`. Prefixes compose outermost first, then the page's own route path — never appended to the directory's own name, so a layout `prefix` OVERRIDES its directory's segment rather than adding to it.
868
1024
 
869
- ```tsx title="src/app/users/web/layout.tsx"
1025
+ ```tsx title="src/web/users/layout.tsx"
870
1026
  export const prefix = "/users";
871
1027
  ```
872
1028
 
873
- ```tsx title="src/app/users/web/account/layout.tsx"
1029
+ ```tsx title="src/web/users/account/layout.tsx"
874
1030
  export const prefix = "/account";
875
1031
  ```
876
1032
 
877
- ```tsx title="src/app/users/web/account/settings.page.tsx"
1033
+ ```tsx title="src/web/users/account/settings.page.tsx"
878
1034
  export const route = {
879
1035
  path: "/settings",
880
1036
  name: "users.account.settings",
@@ -903,6 +1059,8 @@ A `404.page.tsx` renders with no layouts, even when it sits in a directory with
903
1059
 
904
1060
  This is scoped to the not-found page: an ordinary page in the same directory still gets its full layout chain, and nested-layout refusal on the 404's own path is still enforced exactly as it is for any other page.
905
1061
 
1062
+ `error.page.tsx` — the application's other special page, its one error boundary ([create-a-page](../create-a-page/SKILL.md)) — is excluded from discovery's layout-chain analysis the same way: neither special page has a layout chain of its own.
1063
+
906
1064
  ## Why layout state persists
907
1065
 
908
1066
  Client navigation rebuilds the Layout + Page element tree at the same `#root` position. When the next page uses the same layout component type in the same position, React reconciles it instead of remounting it. Layout state such as open menus, scroll containers, and media survives.
@@ -915,11 +1073,15 @@ Client navigation rebuilds the Layout + Page element tree at the same `#root` po
915
1073
 
916
1074
  Use `shared` when multiple levels need one request-derived value, and write it in middleware before loaders run. See [load-page-data](../load-page-data/SKILL.md).
917
1075
 
1076
+ ## The client boundary
1077
+
1078
+ A layout is projected for the browser the same way a page is: `prefix`, `middleware`, `loader`, and (page-only) `validation`/`route` never reach the client bundle — `prefix` joins that stripped set for a layout the way `route` does for a page. The default export and any other surviving exports form the client graph. `register()` is the one export that is NOT stripped — it runs once per module namespace on both the server and the browser; see [create-a-page](../create-a-page/SKILL.md).
1079
+
918
1080
  ## Gotchas
919
1081
 
920
1082
  - **`layout.tsx` is positional.** It applies by directory ancestry; moving a page can change its layout and URL prefix together.
921
1083
  - **Only one layout on a path may render.** Multiple prefix/middleware-only layouts are fine; multiple default exports are not.
922
- - **A layout prefix changes the registered URL.** Check the composed path, not only the page's `route.path`.
1084
+ - **A layout prefix changes the registered URL, and overrides its directory's segment rather than adding to it.** Check the composed path, not only the page's `route.path`.
923
1085
  - **Keep `prefix` literal.** The build parses it without executing the module.
924
1086
  - **Use `LayoutProps<typeof loader>`.** Bare `LayoutProps` is for a layout with no loader and gives `data` as `undefined`.
925
1087
  - **Layout persistence is type-and-position based.** Changing to another layout component remounts it, as normal React reconciliation requires.
@@ -983,6 +1145,8 @@ Because App is outside the hydrated subtree, put client state that must survive
983
1145
 
984
1146
  **Requires 5.1 in an installed app.** In 5.0.0–5.0.2 the dev server handed the browser `react-dom/client` as raw CommonJS, so `hydrateRoot` was not there as a named export and the hydration entry died on import — no client JavaScript ran at all. The symptoms were a page that server-rendered correctly but had dead `useState`, no HMR, and `<Link>` doing full page loads. The fix pre-bundles React through Vite's `optimizeDeps`. If you are debugging this against a checkout of the framework itself, note that the defect never reproduced there: inside the monorepo the hydration entry resolves outside `node_modules` and React was always optimized normally.
985
1147
 
1148
+ If `root.tsx` (or any module it needs) fails to load or its `register()` throws, there is no trustworthy Layout+Page composition left to hydrate — Warlock falls back to a plain document with no hydration script at all rather than hydrate the browser against markup nothing can vouch for. See [create-a-page](../create-a-page/SKILL.md) for the app's own `error.page.tsx` boundary, which is tried first.
1149
+
986
1150
  ## `<Head />`
987
1151
 
988
1152
  `<Head />` renders the resolved page metadata at that position. It takes no props and emits:
package/llms.txt CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  > Package: `@warlock.js/web`
4
4
 
5
+ > Warlock.js web layer for the SSR page pipeline and client runtime.
6
+
5
7
  > SSR React pages served by the same Warlock HTTP server that serves the API — a backend framework that renders React, not a React framework.
6
8
 
7
9
  > First published release: 5.0.0. `@warlock.js/web` had never been published to npm before this release.
@@ -15,9 +17,9 @@
15
17
  ## Skills
16
18
 
17
19
  - [add-web-to-an-app](@warlock.js/web/add-web-to-an-app/SKILL.md): Install the SSR page layer with `warlock add web`: add React/Vite peers, scaffold `src/web/root.tsx` and `src/web/home.page.tsx`, register `webConnector()`, and safely relocate the stock top-level `GET "/"` JSON route to `/welcome`. Triggers: `warlock add web`, `webConnector`, `src/web/root.tsx`, `src/web/home.page.tsx`, `GET "/welcome"`; "add web to an app", "install Warlock web", "scaffold SSR", "homepage route collision". Skip: author a page — `@warlock.js/web/create-a-page/SKILL.md`; customize the document — `@warlock.js/web/write-the-root/SKILL.md`; dev/build/start commands — `@warlock.js/core/run-app/SKILL.md`; competing installers `create-next-app`, `vite create`, `remix init`.
18
- - [create-a-page](@warlock.js/web/create-a-page/SKILL.md): Create an SSR React page under `src/web/**` or `src/app/<module>/web/**` with a literal `route`, a default component, an optional typed `loader`, and page `metadata`; know when a dev edit gets Fast Refresh vs. a full reload. Triggers: `*.page.tsx`, `route`, `PageLoader`, `PageProps`, `PageMetadata`, Fast Refresh, HMR; "create a page", "add an SSR route", "make a React page", "type page loader data", "why did my edit reload the page"; typical import `import type { PageLoader, PageProps } from "@warlock.js/web"`. Skip: root document shell — `@warlock.js/web/write-the-root/SKILL.md`; layout wrappers and prefixes — `@warlock.js/web/use-layouts/SKILL.md`; loader lifecycle and `shared` — `@warlock.js/web/load-page-data/SKILL.md`; competing frameworks `next`, `remix`, `react-router` file routes.
19
- - [load-page-data](@warlock.js/web/load-page-data/SKILL.md): Load App, Layout, and Page data with `AppLoader`, `LayoutLoader`, and `PageLoader`; type component `data`, validate page input, short-circuit with the buffered response, and publish request-scoped browser-safe values through `shared`. Triggers: `PageLoader`, `LayoutLoader`, `AppLoader`, `PageProps`, `shared`, `useShared`, `validation`, `request.validated`; "load page data", "pass server data to React", "share request data", "redirect from a loader". Skip: page module basics — `@warlock.js/web/create-a-page/SKILL.md`; layouts — `@warlock.js/web/use-layouts/SKILL.md`; mutation follow-up — `@warlock.js/web/navigate-on-the-client/SKILL.md`; competing loaders Next data functions, Remix loaders, React Server Components.
20
+ - [create-a-page](@warlock.js/web/create-a-page/SKILL.md): Create an SSR React page under `src/web/**`, with either a literal `route` or a filesystem-derived one, a default component, an optional typed `loader`, page `metadata`, the `error.page.tsx` boundary, and the universal `register()` hook. Triggers: `*.page.tsx`, `route`, `PageLoader`, `PageProps`, `PageMetadata`, `error.page.tsx`, `register`, `[...slug]`; "create a page", "add an SSR route", "make a React page", "type page loader data", "add an error boundary", "catch-all route", "page renders blank 200", "page has no default export"; typical import `import type { PageLoader, PageProps } from "@warlock.js/web"`. Skip: root document shell — `@warlock.js/web/write-the-root/SKILL.md`; layout wrappers and prefixes — `@warlock.js/web/use-layouts/SKILL.md`; loader lifecycle and `shared` — `@warlock.js/web/load-page-data/SKILL.md`; competing frameworks `next`, `remix`, `react-router` file routes.
21
+ - [load-page-data](@warlock.js/web/load-page-data/SKILL.md): Load App, Layout, and Page data with `AppLoader`, `LayoutLoader`, and `PageLoader`; type component `data`, validate page input, short-circuit with the buffered response, and publish request-scoped browser-safe values through `shared`. Triggers: `PageLoader`, `LayoutLoader`, `AppLoader`, `PageProps`, `shared`, `useShared`, `validation`, `request.validated`, `process.env`, `env("PUBLIC_...")`, `import.meta.env.PUBLIC_`; "load page data", "pass server data to React", "share request data", "redirect from a loader", "read an environment variable in a page", "process.env refused in the client build", "loader execution order", "return a Response from a loader". Skip: page module basics — `@warlock.js/web/create-a-page/SKILL.md`; layouts — `@warlock.js/web/use-layouts/SKILL.md`; mutation follow-up — `@warlock.js/web/navigate-on-the-client/SKILL.md`; competing loaders Next data functions, Remix loaders, React Server Components.
20
22
  - [navigate-on-the-client](@warlock.js/web/navigate-on-the-client/SKILL.md): Navigate hydrated pages with `<Link>`, resolve named URLs with `href()`, use `navigateTo` / `navigateBack`, prefetch on interaction, inspect the server match with `currentRoute()`, and re-fetch loaders after a mutation with `refresh()`. Triggers: `Link`, `href`, `navigateTo`, `navigateBack`, `refresh`, `currentRoute`, `previousRoute`; "navigate without a reload", "link to a named route", "refresh page data", "revalidate loaders", "client-side back"; typical import `import { Link, refresh } from "@warlock.js/web"`. Skip: define a page route — `@warlock.js/web/create-a-page/SKILL.md`; loader mechanics — `@warlock.js/web/load-page-data/SKILL.md`; root hydration boundary — `@warlock.js/web/write-the-root/SKILL.md`; competing routers `@mongez/react-router`, `react-router-dom`, Next navigation.
21
23
  - [serve-styles](@warlock.js/web/serve-styles/SKILL.md): Serve CSS imported by `root.tsx` or `*.page.tsx`, with render-blocking `<link rel="stylesheet">` delivery from Vite source URLs in development and Vite manifest assets in production. Triggers: `import "./app.css"`, page CSS, `?direct`, `manifest.json`, stylesheet flash, FOUC, `<head>`; "add global styles", "style a page", "CSS missing in SSR", "page flashes unstyled", "serve CSS in production". Skip: root document markup — `@warlock.js/web/write-the-root/SKILL.md`; page authoring — `@warlock.js/web/create-a-page/SKILL.md`; client navigation — `@warlock.js/web/navigate-on-the-client/SKILL.md`; competing styling systems CSS-in-JS, Next CSS, styled-components.
22
- - [use-layouts](@warlock.js/web/use-layouts/SKILL.md): Wrap pages with positional `layout.tsx` modules, compose literal `prefix` exports, load typed layout data with `LayoutLoader` / `LayoutProps`, preserve layout state during client navigation, and know why `404.page.tsx` never receives a layout. Triggers: `layout.tsx`, `prefix`, `LayoutLoader`, `LayoutProps`, `children`, `404.page.tsx`; "add a page layout", "share navigation between pages", "prefix page routes", "keep a layout mounted", "404 page has no layout". Skip: full-document root — `@warlock.js/web/write-the-root/SKILL.md`; page route export — `@warlock.js/web/create-a-page/SKILL.md`; loader and shared lifecycle — `@warlock.js/web/load-page-data/SKILL.md`; competing layout systems `next/layout`, React Router outlets, Remix nested routes.
24
+ - [use-layouts](@warlock.js/web/use-layouts/SKILL.md): Wrap pages with positional `layout.tsx` modules, compose literal `prefix` exports, load typed layout data with `LayoutLoader` / `LayoutProps`, and preserve layout state during client navigation. Triggers: `layout.tsx`, `prefix`, `LayoutLoader`, `LayoutProps`, `children`; "add a page layout", "share navigation between pages", "prefix page routes", "keep a layout mounted". Skip: full-document root — `@warlock.js/web/write-the-root/SKILL.md`; page route export — `@warlock.js/web/create-a-page/SKILL.md`; loader and shared lifecycle — `@warlock.js/web/load-page-data/SKILL.md`; competing layout systems `next/layout`, React Router outlets, Remix nested routes.
23
25
  - [write-the-root](@warlock.js/web/write-the-root/SKILL.md): Author `src/web/root.tsx`, the full-document application root that owns `<html>`, `<head>`, and `<body>`, places page metadata with `<Head />`, renders the hydrated subtree inside `#root`, and emits the payload with `<Scripts />`. Triggers: `root.tsx`, `AppProps`, `AppLoader`, `Head`, `Scripts`, `id="root"`; "customize the root document", "add html lang", "add an app provider", "where do Head and Scripts go"; typical import `import { Head, Scripts, type AppProps } from "@warlock.js/web"`. Skip: page component contract — `@warlock.js/web/create-a-page/SKILL.md`; layout wrappers — `@warlock.js/web/use-layouts/SKILL.md`; CSS delivery — `@warlock.js/web/serve-styles/SKILL.md`; competing roots `next/layout`, Remix `root`, React `createRoot`.
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@vitejs/plugin-react": "^5.2.0",
14
- "@warlock.js/core": "5.1.0",
15
- "@warlock.js/seal": "5.1.0",
14
+ "@warlock.js/core": "5.2.0",
15
+ "@warlock.js/seal": "5.2.0",
16
16
  "react": "*",
17
17
  "react-dom": "*",
18
18
  "vite": ">=7.3.5 <8"
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "author": "hassanzohdy",
39
39
  "license": "MIT",
40
- "version": "5.1.0",
40
+ "version": "5.2.0",
41
41
  "type": "module",
42
42
  "main": "./esm/index.mjs",
43
43
  "module": "./esm/index.mjs",
@@ -10,7 +10,7 @@ description: 'Install the SSR page layer with `warlock add web`: add React/Vite
10
10
  ## The shape
11
11
 
12
12
  ```bash
13
- yarn warlock add web
13
+ pnpm warlock add web
14
14
  ```
15
15
 
16
16
  On the ordinary path it leaves this application-owned shape:
@@ -81,8 +81,8 @@ On the refusal path, free `/` yourself and create a page with either `route = "/
81
81
  Read the files rather than assuming the command could patch every application shape:
82
82
 
83
83
  ```bash
84
- yarn warlock routes --method GET --path /
85
- yarn warlock routes --method GET --path /welcome
84
+ pnpm warlock routes --method GET --path /
85
+ pnpm warlock routes --method GET --path /welcome
86
86
  ```
87
87
 
88
88
  The desired result is one page route at `/` and, when the stock JSON route existed, one API route at `/welcome`.