@sigil-dev/grimoire 0.9.29 → 0.9.30

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 (105) hide show
  1. package/bin/sigil.ts +4 -0
  2. package/index.ts +16 -10
  3. package/package.json +14 -6
  4. package/server.ts +2 -2
  5. package/src/adapters/bun.ts +17 -17
  6. package/src/adapters/static.ts +41 -41
  7. package/src/adapters/types.ts +36 -36
  8. package/src/base.ts +4 -1
  9. package/src/client/csrf.ts +47 -47
  10. package/src/client/deferred.ts +1 -4
  11. package/src/client/enhance.ts +160 -160
  12. package/src/client/router.ts +927 -926
  13. package/src/config-file.ts +84 -0
  14. package/src/dev/compile-module.ts +199 -193
  15. package/src/dev/hmr-client.ts +229 -229
  16. package/src/dev/hmr-server.ts +274 -266
  17. package/src/dev/loader.ts +144 -144
  18. package/src/dev/runtime-bundle.ts +5 -3
  19. package/src/duration.ts +46 -0
  20. package/src/env/modules.ts +62 -62
  21. package/src/env/required.ts +42 -42
  22. package/src/env/typegen.ts +61 -61
  23. package/src/headers.ts +105 -105
  24. package/src/logger/transports.ts +117 -117
  25. package/src/plugin-order.ts +88 -0
  26. package/src/rendering/head.ts +49 -49
  27. package/src/rendering/hydrate.ts +162 -162
  28. package/src/rendering/images.ts +43 -43
  29. package/src/rendering/preload.ts +22 -8
  30. package/src/rendering/ssrPlugin.ts +107 -107
  31. package/src/rendering/timing.ts +40 -40
  32. package/src/routing/route-ids.ts +65 -0
  33. package/src/routing/route.ts +65 -0
  34. package/src/routing/router.ts +84 -32
  35. package/src/routing/scanner.ts +18 -5
  36. package/src/routing/transform-routes.ts +102 -102
  37. package/src/server/after-response.ts +206 -206
  38. package/src/server/asset-cache.ts +57 -57
  39. package/src/server/build.ts +304 -295
  40. package/src/server/cached.ts +114 -114
  41. package/src/server/client-address.ts +82 -82
  42. package/src/server/client-dir.ts +63 -63
  43. package/src/server/client-entry.ts +44 -44
  44. package/src/server/context.ts +18 -10
  45. package/src/server/cookie-utils.ts +80 -80
  46. package/src/server/coordinator.ts +476 -476
  47. package/src/server/hooks.ts +122 -122
  48. package/src/server/index.ts +8 -0
  49. package/src/server/plugins.ts +172 -172
  50. package/src/server/prerender.ts +473 -473
  51. package/src/server/reserved.ts +17 -17
  52. package/src/server/resolver.ts +149 -123
  53. package/src/server/rewrite.ts +28 -28
  54. package/src/server/warm.ts +9 -3
  55. package/src/server/with-headers.ts +27 -27
  56. package/src/server/worker.ts +2 -6
  57. package/src/server-only.ts +78 -0
  58. package/src/testing/dom.ts +73 -73
  59. package/src/testing/index.ts +169 -169
  60. package/src/testing/server.ts +1 -0
  61. package/src/typegen/index.ts +97 -2
  62. package/src/types.ts +140 -19
  63. package/test/after-response.test.ts +132 -132
  64. package/test/asset-cache-policy.test.ts +6 -2
  65. package/test/base.test.ts +20 -6
  66. package/test/cached.test.ts +126 -126
  67. package/test/client-address.test.ts +78 -78
  68. package/test/client-csrf.test.ts +61 -61
  69. package/test/client-dir.test.ts +101 -101
  70. package/test/client-router.test.ts +37 -5
  71. package/test/config-file.test.ts +84 -0
  72. package/test/coordinator.test.ts +9 -2
  73. package/test/deferred.test.ts +4 -2
  74. package/test/dev-loader.test.ts +30 -30
  75. package/test/env.test.ts +171 -171
  76. package/test/force-production.test.ts +7 -2
  77. package/test/images.test.ts +20 -8
  78. package/test/locals-header.test.ts +61 -61
  79. package/test/middleware.test.ts +243 -243
  80. package/test/parser-plugins.test.ts +98 -92
  81. package/test/plugin-handle.test.ts +62 -62
  82. package/test/plugin-order.test.ts +98 -0
  83. package/test/plugin-routes.test.ts +47 -42
  84. package/test/plugin-services-context.test.ts +7 -2
  85. package/test/preload.test.ts +4 -1
  86. package/test/prerender.test.ts +3 -1
  87. package/test/rendering.test.ts +3 -2
  88. package/test/required-env.test.ts +32 -32
  89. package/test/resolver-windows.test.ts +22 -23
  90. package/test/rewrite-html.test.ts +90 -90
  91. package/test/route-group-layouts.test.ts +38 -36
  92. package/test/route.test.ts +103 -0
  93. package/test/routing.test.ts +225 -197
  94. package/test/scanning.test.ts +53 -33
  95. package/test/server-context.test.ts +22 -0
  96. package/test/server-only.test.ts +110 -0
  97. package/test/server.test.ts +640 -640
  98. package/test/services.test.ts +3 -3
  99. package/test/streaming.test.ts +11 -6
  100. package/test/testing-helpers.test.ts +166 -166
  101. package/test/typegen.test.ts +209 -112
  102. package/test/warm.test.ts +96 -96
  103. package/test/worker-context.test.ts +59 -59
  104. package/test/workspace-files.test.ts +26 -10
  105. package/test/workspace-versions.test.ts +146 -131
@@ -1,266 +1,274 @@
1
- import { relative } from "node:path";
2
- import type { ServerWebSocket } from "bun";
3
- import { log } from "../logger/instance";
4
- import { cacheDevModule, compileForBrowser } from "./compile-module";
5
- import type { DevGraph } from "./graph";
6
- import { normalizePath } from "./paths";
7
- import { isServerOnly, isSourceFile } from "./resolve";
8
- import { crawlFrom } from "./scan";
9
- import { safeRead } from "./watcher";
10
-
11
- const logger = log.scope("hmr");
12
-
13
- export class HmrServer {
14
- private clients = new Set<ServerWebSocket<unknown>>();
15
- private v = 0;
16
- get clientCount() {
17
- return this.clients.size;
18
- }
19
- addClient(ws: ServerWebSocket<unknown>) {
20
- this.clients.add(ws);
21
- ws.send(JSON.stringify({ type: "connected" }));
22
- }
23
-
24
- removeClient(ws: ServerWebSocket<unknown>) {
25
- this.clients.delete(ws);
26
- }
27
-
28
- send(msg: object) {
29
- const s = JSON.stringify(msg);
30
- for (const c of this.clients) c.send(s);
31
- }
32
-
33
- batch(payloads: object[]) {
34
- this.send({ type: "batch", payloads, v: ++this.v });
35
- }
36
-
37
- reload() {
38
- logger.info("sending reload to", this.clients.size, "clients");
39
- this.batch([{ kind: "reload" }]);
40
- }
41
-
42
- error(message: string, loc?: { file: string; line: number; col: number }) {
43
- this.send({ type: "error", message, loc });
44
- }
45
- }
46
-
47
- interface ErrorLoc {
48
- file: string;
49
- line: number;
50
- col: number;
51
- }
52
-
53
- function extractLoc(e: unknown, filePath: string): ErrorLoc | undefined {
54
- // Babel errors carry loc.line / loc.column
55
- if (e && typeof e === "object" && "loc" in e) {
56
- const loc = e.loc;
57
- if (loc && typeof loc === "object" && "line" in loc) {
58
- const line = Number(loc.line);
59
- const col = "column" in loc ? Number(loc.column) : 0;
60
- if (Number.isFinite(line))
61
- return { file: filePath, line, col: Number.isFinite(col) ? col : 0 };
62
- }
63
- }
64
- // fallback: parse a trailing "file:line:col" out of the message
65
- const m = errorMessage(e).match(/:(\d+):(\d+)$/);
66
- return m
67
- ? { file: filePath, line: Number(m[1]), col: Number(m[2]) }
68
- : undefined;
69
- }
70
-
71
- function errorMessage(e: unknown): string {
72
- if (e instanceof Error) return e.message;
73
- if (e && typeof e === "object" && "message" in e) return String(e.message);
74
- return String(e);
75
- }
76
-
77
- export interface DevContext {
78
- graph: DevGraph;
79
- hmr: HmrServer;
80
- projectRoot: string;
81
- /** GrimoireConfig.alias — prefix → project-relative directory. */
82
- aliases: Record<string, string>;
83
- /** Route/layout/server files the graph is crawled from. */
84
- entries: () => string[];
85
- /**
86
- * Rescan routes and rebuild the client bundles. Awaited before a full
87
- * reload: `hydrate.js` is built once at startup, so reloading without a
88
- * rebuild would serve the browser the code from before the edit.
89
- */
90
- rebuild: () => Promise<void>;
91
- /**
92
- * Same rebuild, off the critical path. Runs after a hot swap so that a
93
- * later manual refresh — which loads the prebuilt bundle, not the swapped
94
- * modules — shows the same code the running page already has.
95
- */
96
- scheduleRebuild: () => void;
97
- }
98
-
99
- /** `src/lib/Card.tsx` → the `/__grimoire__/m/` path the client imports. */
100
- const clientModulePath = (filePath: string, projectRoot: string): string =>
101
- `${relative(projectRoot, filePath).replace(/\\/g, "/")}.js`;
102
-
103
- interface RouteEntryPayload {
104
- pattern: string;
105
- modUrl: string;
106
- version: number;
107
- }
108
-
109
- interface LayoutEntryPayload {
110
- path: string;
111
- modUrl: string;
112
- version: number;
113
- }
114
-
115
- /**
116
- * Does an edit to this file change what a `load` returns? Route modules own
117
- * their data loaders, so a swap alone would re-render the new component
118
- * against data produced by the old loader.
119
- */
120
- function affectsData(filePath: string, source: string): boolean {
121
- if (isServerOnly(filePath)) return true;
122
- return /\bexport\s+(async\s+)?(function\s+load\b|const\s+load\b|const\s+actions\b|function\s+canMatch\b|const\s+canMatch\b)/.test(
123
- source,
124
- );
125
- }
126
-
127
- async function fullReload(ctx: DevContext): Promise<void> {
128
- await ctx.rebuild();
129
- ctx.hmr.reload();
130
- }
131
-
132
- export async function handleChange(
133
- filePath: string,
134
- ctx: DevContext,
135
- ): Promise<void> {
136
- const { graph, hmr, projectRoot } = ctx;
137
- const key = normalizePath(filePath);
138
-
139
- if (!isSourceFile(filePath)) {
140
- logger.info("non-source change, reloading:", filePath);
141
- await fullReload(ctx);
142
- return;
143
- }
144
-
145
- const source = await safeRead(filePath);
146
- if (source === null) {
147
- // deleted or unreadable — the module graph can't be trusted any more
148
- await fullReload(ctx);
149
- return;
150
- }
151
-
152
- if (!graph.get(key)) {
153
- // a brand-new file, or one that just became imported: recrawl from the
154
- // route entries before giving up on a targeted update
155
- await crawlFrom(ctx.entries(), {
156
- graph,
157
- projectRoot,
158
- aliases: ctx.aliases,
159
- });
160
- }
161
- if (!graph.get(key)) {
162
- logger.info("file outside the route graph, reloading:", filePath);
163
- await fullReload(ctx);
164
- return;
165
- }
166
-
167
- // the edit may have added imports — pick them up before propagating
168
- await crawlFrom([filePath], { graph, projectRoot, aliases: ctx.aliases });
169
-
170
- // error pages render on the server only: compiling one for the browser can
171
- // fail on code that never ships there, and a failure would throw the edit
172
- // away before the SSR loader ever saw the new version
173
- const reaches = graph.affectedRoutes(key);
174
- const isClient =
175
- !isServerOnly(filePath) && reaches.some((r) => r.type !== "error");
176
- let css: { hash: string; text: string } | null = null;
177
- let compiled: string | null = null;
178
-
179
- if (isClient) {
180
- // compile the edited source before bumping anything: on a syntax error
181
- // the overlay goes up and every previous version stays live, in the
182
- // browser and in SSR alike. Never read the cache here — the whole point
183
- // is to see what the developer just typed.
184
- try {
185
- const result = await compileForBrowser(filePath, {
186
- projectRoot,
187
- aliases: ctx.aliases,
188
- graph,
189
- });
190
- compiled = result.js;
191
- if (result.css) css = { hash: result.cssHash, text: result.css };
192
- } catch (e: unknown) {
193
- const message = errorMessage(e);
194
- logger.error("compile error:", message);
195
- hmr.error(message, extractLoc(e, filePath));
196
- return;
197
- }
198
- }
199
-
200
- // bump this module and every importer up to the routes, invalidating the
201
- // SSR loader's cache and every stamped browser URL along the way
202
- graph.invalidate(key);
203
- if (compiled !== null) {
204
- // dep versions are untouched by the bump, so the output just compiled
205
- // is exactly what this new version should serve
206
- cacheDevModule(
207
- filePath,
208
- graph.get(key)?.version ?? 0,
209
- projectRoot,
210
- compiled,
211
- );
212
- }
213
-
214
- const affected = reaches;
215
- if (affected.length === 0) {
216
- logger.info("no route reaches this module, reloading:", filePath);
217
- await fullReload(ctx);
218
- return;
219
- }
220
-
221
- const routeEntries: RouteEntryPayload[] = [];
222
- const layoutEntries: LayoutEntryPayload[] = [];
223
- let serverTouched = false;
224
- let needsReload = false;
225
-
226
- for (const route of affected) {
227
- const modUrl = clientModulePath(route.filePath, projectRoot);
228
- const version = graph.get(route.filePath)?.version ?? 0;
229
- if (route.type === "page" || route.type === "simple") {
230
- routeEntries.push({ pattern: route.path, modUrl, version });
231
- } else if (route.type === "layout") {
232
- layoutEntries.push({ path: route.path, modUrl, version });
233
- } else if (route.type === "error") {
234
- // error pages are never in the client route table — only a document
235
- // request re-renders one
236
- needsReload = true;
237
- } else {
238
- // +page.server / +layout.server / +server: nothing the client can
239
- // swap, but the data behind the current page just changed
240
- serverTouched = true;
241
- }
242
- }
243
-
244
- if (needsReload) {
245
- await fullReload(ctx);
246
- return;
247
- }
248
-
249
- const payloads: object[] = [];
250
- if (css) payloads.push({ kind: "css", ...css });
251
- if (routeEntries.length)
252
- payloads.push({ kind: "routes", entries: routeEntries });
253
- if (layoutEntries.length)
254
- payloads.push({ kind: "layouts", entries: layoutEntries });
255
- if (serverTouched || affectsData(filePath, source))
256
- payloads.push({ kind: "invalidate" });
257
-
258
- const summary = affected.map((r) => `${r.type} ${r.path}`).join(", ");
259
- logger.info(
260
- `changed ${relative(projectRoot, filePath).replace(/\\/g, "/")} → ${summary}`,
261
- );
262
- hmr.batch(payloads);
263
- // the prebuilt bundles still hold pre-edit code; refresh them so a manual
264
- // reload agrees with the hot-swapped page
265
- ctx.scheduleRebuild();
266
- }
1
+ import { relative } from "node:path";
2
+ import type { ServerWebSocket } from "bun";
3
+ import { log } from "../logger/instance";
4
+ import { serverOnlyReason } from "../server-only";
5
+ import { cacheDevModule, compileForBrowser } from "./compile-module";
6
+ import type { DevGraph } from "./graph";
7
+ import { normalizePath } from "./paths";
8
+ import { isSourceFile } from "./resolve";
9
+ import { crawlFrom } from "./scan";
10
+ import { safeRead } from "./watcher";
11
+
12
+ const logger = log.scope("hmr");
13
+
14
+ export class HmrServer {
15
+ private clients = new Set<ServerWebSocket<unknown>>();
16
+ private v = 0;
17
+ get clientCount() {
18
+ return this.clients.size;
19
+ }
20
+ addClient(ws: ServerWebSocket<unknown>) {
21
+ this.clients.add(ws);
22
+ ws.send(JSON.stringify({ type: "connected" }));
23
+ }
24
+
25
+ removeClient(ws: ServerWebSocket<unknown>) {
26
+ this.clients.delete(ws);
27
+ }
28
+
29
+ send(msg: object) {
30
+ const s = JSON.stringify(msg);
31
+ for (const c of this.clients) c.send(s);
32
+ }
33
+
34
+ batch(payloads: object[]) {
35
+ this.send({ type: "batch", payloads, v: ++this.v });
36
+ }
37
+
38
+ reload() {
39
+ logger.info("sending reload to", this.clients.size, "clients");
40
+ this.batch([{ kind: "reload" }]);
41
+ }
42
+
43
+ error(message: string, loc?: { file: string; line: number; col: number }) {
44
+ this.send({ type: "error", message, loc });
45
+ }
46
+ }
47
+
48
+ interface ErrorLoc {
49
+ file: string;
50
+ line: number;
51
+ col: number;
52
+ }
53
+
54
+ function extractLoc(e: unknown, filePath: string): ErrorLoc | undefined {
55
+ // Babel errors carry loc.line / loc.column
56
+ if (e && typeof e === "object" && "loc" in e) {
57
+ const loc = e.loc;
58
+ if (loc && typeof loc === "object" && "line" in loc) {
59
+ const line = Number(loc.line);
60
+ const col = "column" in loc ? Number(loc.column) : 0;
61
+ if (Number.isFinite(line))
62
+ return { file: filePath, line, col: Number.isFinite(col) ? col : 0 };
63
+ }
64
+ }
65
+ // fallback: parse a trailing "file:line:col" out of the message
66
+ const m = errorMessage(e).match(/:(\d+):(\d+)$/);
67
+ return m
68
+ ? { file: filePath, line: Number(m[1]), col: Number(m[2]) }
69
+ : undefined;
70
+ }
71
+
72
+ function errorMessage(e: unknown): string {
73
+ if (e instanceof Error) return e.message;
74
+ if (e && typeof e === "object" && "message" in e) return String(e.message);
75
+ return String(e);
76
+ }
77
+
78
+ export interface DevContext {
79
+ graph: DevGraph;
80
+ hmr: HmrServer;
81
+ projectRoot: string;
82
+ /** GrimoireConfig.alias — prefix → project-relative directory. */
83
+ aliases: Record<string, string>;
84
+ /** Route/layout/server files the graph is crawled from. */
85
+ entries: () => string[];
86
+ /**
87
+ * Rescan routes and rebuild the client bundles. Awaited before a full
88
+ * reload: `hydrate.js` is built once at startup, so reloading without a
89
+ * rebuild would serve the browser the code from before the edit.
90
+ */
91
+ rebuild: () => Promise<void>;
92
+ /**
93
+ * Same rebuild, off the critical path. Runs after a hot swap so that a
94
+ * later manual refresh — which loads the prebuilt bundle, not the swapped
95
+ * modules — shows the same code the running page already has.
96
+ */
97
+ scheduleRebuild: () => void;
98
+ }
99
+
100
+ /** `src/lib/Card.tsx` → the `/__grimoire__/m/` path the client imports. */
101
+ const clientModulePath = (filePath: string, projectRoot: string): string =>
102
+ `${relative(projectRoot, filePath).replace(/\\/g, "/")}.js`;
103
+
104
+ interface RouteEntryPayload {
105
+ pattern: string;
106
+ modUrl: string;
107
+ version: number;
108
+ }
109
+
110
+ interface LayoutEntryPayload {
111
+ path: string;
112
+ modUrl: string;
113
+ version: number;
114
+ }
115
+
116
+ /**
117
+ * Does an edit to this file change what a `load` returns? Route modules own
118
+ * their data loaders, so a swap alone would re-render the new component
119
+ * against data produced by the old loader.
120
+ */
121
+ function affectsData(
122
+ filePath: string,
123
+ source: string,
124
+ projectRoot: string,
125
+ ): boolean {
126
+ if (serverOnlyReason(filePath, projectRoot)) return true;
127
+ return /\bexport\s+(async\s+)?(function\s+load\b|const\s+load\b|const\s+actions\b|function\s+canMatch\b|const\s+canMatch\b)/.test(
128
+ source,
129
+ );
130
+ }
131
+
132
+ async function fullReload(ctx: DevContext): Promise<void> {
133
+ await ctx.rebuild();
134
+ ctx.hmr.reload();
135
+ }
136
+
137
+ export async function handleChange(
138
+ filePath: string,
139
+ ctx: DevContext,
140
+ ): Promise<void> {
141
+ const { graph, hmr, projectRoot } = ctx;
142
+ const key = normalizePath(filePath);
143
+
144
+ if (!isSourceFile(filePath)) {
145
+ logger.info("non-source change, reloading:", filePath);
146
+ await fullReload(ctx);
147
+ return;
148
+ }
149
+
150
+ const source = await safeRead(filePath);
151
+ if (source === null) {
152
+ // deleted or unreadable — the module graph can't be trusted any more
153
+ await fullReload(ctx);
154
+ return;
155
+ }
156
+
157
+ if (!graph.get(key)) {
158
+ // a brand-new file, or one that just became imported: recrawl from the
159
+ // route entries before giving up on a targeted update
160
+ await crawlFrom(ctx.entries(), {
161
+ graph,
162
+ projectRoot,
163
+ aliases: ctx.aliases,
164
+ });
165
+ }
166
+ if (!graph.get(key)) {
167
+ logger.info("file outside the route graph, reloading:", filePath);
168
+ await fullReload(ctx);
169
+ return;
170
+ }
171
+
172
+ // the edit may have added imports — pick them up before propagating
173
+ await crawlFrom([filePath], { graph, projectRoot, aliases: ctx.aliases });
174
+
175
+ // error pages render on the server only: compiling one for the browser can
176
+ // fail on code that never ships there, and a failure would throw the edit
177
+ // away before the SSR loader ever saw the new version
178
+ const reaches = graph.affectedRoutes(key);
179
+ // server-only code (a server file, src/lib/server/) never ships to the
180
+ // browser, so it is never compiled for it
181
+ const isClient =
182
+ !serverOnlyReason(filePath, projectRoot) &&
183
+ reaches.some((r) => r.type !== "error");
184
+ let css: { hash: string; text: string } | null = null;
185
+ let compiled: string | null = null;
186
+
187
+ if (isClient) {
188
+ // compile the edited source before bumping anything: on a syntax error
189
+ // the overlay goes up and every previous version stays live, in the
190
+ // browser and in SSR alike. Never read the cache here — the whole point
191
+ // is to see what the developer just typed.
192
+ try {
193
+ const result = await compileForBrowser(filePath, {
194
+ projectRoot,
195
+ aliases: ctx.aliases,
196
+ graph,
197
+ });
198
+ compiled = result.js;
199
+ if (result.css) css = { hash: result.cssHash, text: result.css };
200
+ } catch (e: unknown) {
201
+ const message = errorMessage(e);
202
+ logger.error("compile error:", message);
203
+ hmr.error(message, extractLoc(e, filePath));
204
+ return;
205
+ }
206
+ }
207
+
208
+ // bump this module and every importer up to the routes, invalidating the
209
+ // SSR loader's cache and every stamped browser URL along the way
210
+ graph.invalidate(key);
211
+ if (compiled !== null) {
212
+ // dep versions are untouched by the bump, so the output just compiled
213
+ // is exactly what this new version should serve
214
+ cacheDevModule(
215
+ filePath,
216
+ graph.get(key)?.version ?? 0,
217
+ projectRoot,
218
+ compiled,
219
+ );
220
+ }
221
+
222
+ const affected = reaches;
223
+ if (affected.length === 0) {
224
+ logger.info("no route reaches this module, reloading:", filePath);
225
+ await fullReload(ctx);
226
+ return;
227
+ }
228
+
229
+ const routeEntries: RouteEntryPayload[] = [];
230
+ const layoutEntries: LayoutEntryPayload[] = [];
231
+ let serverTouched = false;
232
+ let needsReload = false;
233
+
234
+ for (const route of affected) {
235
+ const modUrl = clientModulePath(route.filePath, projectRoot);
236
+ const version = graph.get(route.filePath)?.version ?? 0;
237
+ if (route.type === "page" || route.type === "simple") {
238
+ routeEntries.push({ pattern: route.path, modUrl, version });
239
+ } else if (route.type === "layout") {
240
+ layoutEntries.push({ path: route.path, modUrl, version });
241
+ } else if (route.type === "error") {
242
+ // error pages are never in the client route table — only a document
243
+ // request re-renders one
244
+ needsReload = true;
245
+ } else {
246
+ // +page.server / +layout.server / +server: nothing the client can
247
+ // swap, but the data behind the current page just changed
248
+ serverTouched = true;
249
+ }
250
+ }
251
+
252
+ if (needsReload) {
253
+ await fullReload(ctx);
254
+ return;
255
+ }
256
+
257
+ const payloads: object[] = [];
258
+ if (css) payloads.push({ kind: "css", ...css });
259
+ if (routeEntries.length)
260
+ payloads.push({ kind: "routes", entries: routeEntries });
261
+ if (layoutEntries.length)
262
+ payloads.push({ kind: "layouts", entries: layoutEntries });
263
+ if (serverTouched || affectsData(filePath, source, projectRoot))
264
+ payloads.push({ kind: "invalidate" });
265
+
266
+ const summary = affected.map((r) => `${r.type} ${r.path}`).join(", ");
267
+ logger.info(
268
+ `changed ${relative(projectRoot, filePath).replace(/\\/g, "/")} → ${summary}`,
269
+ );
270
+ hmr.batch(payloads);
271
+ // the prebuilt bundles still hold pre-edit code; refresh them so a manual
272
+ // reload agrees with the hot-swapped page
273
+ ctx.scheduleRebuild();
274
+ }