@sigil-dev/grimoire 0.9.27 → 0.9.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/client/router.ts +15 -4
- package/src/dev/compile-module.ts +1 -1
- package/src/server/build.ts +34 -1
- package/src/server/client-dir.ts +6 -0
- package/test/client-router.test.ts +33 -0
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"module": "index.ts",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"private": false,
|
|
14
|
-
"version": "0.9.
|
|
14
|
+
"version": "0.9.28",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./index.ts",
|
|
17
17
|
"./server": "./server.ts",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@sigil-dev/compiler": "0.9.
|
|
39
|
-
"@sigil-dev/runtime": "0.9.
|
|
38
|
+
"@sigil-dev/compiler": "0.9.28",
|
|
39
|
+
"@sigil-dev/runtime": "0.9.28",
|
|
40
40
|
"vite": "^8.0.16"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
package/src/client/router.ts
CHANGED
|
@@ -60,10 +60,21 @@ async function resolveRoute(pattern: string): Promise<PageComponent | null> {
|
|
|
60
60
|
// plain function: eager component or an HMR hot-swap — always wins over cache
|
|
61
61
|
if (typeof entry === "function") return entry;
|
|
62
62
|
if (!resolvedRoutes[pattern]) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
63
|
+
let mod: { default: PageComponent; loading?: PageComponent["loading"] };
|
|
64
|
+
try {
|
|
65
|
+
mod = await entry.__lazy();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// The chunk is gone: a rebuild (dev) or a deploy (prod) replaced it
|
|
68
|
+
// while this tab kept the old bundle, which still names it. null
|
|
69
|
+
// sends every caller down its full-page-load path, which fetches
|
|
70
|
+
// fresh HTML that names the current chunks. Not cached, so a later
|
|
71
|
+
// navigation retries the import.
|
|
72
|
+
console.warn(
|
|
73
|
+
`[grimoire] could not load the page for ${pattern}; loading it from the server`,
|
|
74
|
+
e,
|
|
75
|
+
);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
67
78
|
// `loading` is a named export of the page module; navigation looks
|
|
68
79
|
// for it on the component, and never saw it before
|
|
69
80
|
if (mod.loading && !mod.default.loading) mod.default.loading = mod.loading;
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
} from "@sigil-dev/compiler/css";
|
|
11
11
|
import type { DevGraph } from "./graph";
|
|
12
12
|
import { normalizePath } from "./paths";
|
|
13
|
+
import { RUNTIME_URL } from "../server/client-dir";
|
|
13
14
|
import { absoluteAliases, resolveProjectImport } from "./resolve";
|
|
14
15
|
|
|
15
|
-
const RUNTIME_URL = "/__grimoire__/runtime.js";
|
|
16
16
|
const MODULES_BASE = "/__grimoire__/m/";
|
|
17
17
|
const DEPS_BASE = "/__grimoire__/dep/";
|
|
18
18
|
|
package/src/server/build.ts
CHANGED
|
@@ -7,7 +7,12 @@ import { scanRoutes } from "../routing/scanner";
|
|
|
7
7
|
import { transformRoutes } from "../routing/transform-routes";
|
|
8
8
|
import { generateTypes } from "../typegen";
|
|
9
9
|
import type { BuildResult, GrimoireConfig, GrimoirePlugin } from "../types";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
clientDir,
|
|
12
|
+
pruneClientDir,
|
|
13
|
+
RUNTIME_URL,
|
|
14
|
+
resetClientDir,
|
|
15
|
+
} from "./client-dir";
|
|
11
16
|
import { recordClientEntry } from "./client-entry";
|
|
12
17
|
import { runHook } from "./plugins";
|
|
13
18
|
import { projectAliases, resolverPlugin } from "./resolver";
|
|
@@ -21,6 +26,29 @@ const makeRoutesPlugin = (manifestPath: string) => ({
|
|
|
21
26
|
},
|
|
22
27
|
});
|
|
23
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Dev only: the client bundles import the runtime from RUNTIME_URL, the file
|
|
31
|
+
* HMR-swapped modules import, instead of each carrying a copy.
|
|
32
|
+
*
|
|
33
|
+
* Two copies are two sets of module state. The one that broke: the router
|
|
34
|
+
* collects a re-render's effects with `collectEffects`, which sets a flag on
|
|
35
|
+
* globalThis that every copy reads, but queues into its own module. A swapped
|
|
36
|
+
* layout's effects (`{children}`, any prop in text) went into the other copy's
|
|
37
|
+
* queue, which nothing flushes, so the page vanished from the layout. Signals,
|
|
38
|
+
* context and effect scopes don't cross copies either.
|
|
39
|
+
*
|
|
40
|
+
* Production has no swapped modules, so it keeps bundling the runtime.
|
|
41
|
+
*/
|
|
42
|
+
const sharedDevRuntime = {
|
|
43
|
+
name: "grimoire-shared-dev-runtime",
|
|
44
|
+
setup(build: any) {
|
|
45
|
+
build.onResolve({ filter: /^@sigil-dev\/runtime$/ }, () => ({
|
|
46
|
+
path: RUNTIME_URL,
|
|
47
|
+
external: true,
|
|
48
|
+
}));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
24
52
|
/**
|
|
25
53
|
* Rebuild the client bundles in dev.
|
|
26
54
|
*
|
|
@@ -74,6 +102,7 @@ export async function rebuildClient(
|
|
|
74
102
|
// lazy route entries in the manifest use dynamic import()
|
|
75
103
|
splitting: true,
|
|
76
104
|
plugins: [
|
|
105
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
77
106
|
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
78
107
|
makeRoutesPlugin(hydrateManifest),
|
|
79
108
|
resolverPlugin(config, "browser"),
|
|
@@ -87,6 +116,7 @@ export async function rebuildClient(
|
|
|
87
116
|
throw: false,
|
|
88
117
|
splitting: true,
|
|
89
118
|
plugins: [
|
|
119
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
90
120
|
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
91
121
|
makeRoutesPlugin(domManifest),
|
|
92
122
|
resolverPlugin(config, "browser"),
|
|
@@ -186,6 +216,7 @@ export async function buildProject(
|
|
|
186
216
|
// lazy route entries in the manifest use dynamic import()
|
|
187
217
|
splitting: true,
|
|
188
218
|
plugins: [
|
|
219
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
189
220
|
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
190
221
|
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
191
222
|
makeRoutesPlugin(hydrateManifest),
|
|
@@ -220,6 +251,7 @@ export async function buildProject(
|
|
|
220
251
|
// lazy route entries in the manifest use dynamic import()
|
|
221
252
|
splitting: true,
|
|
222
253
|
plugins: [
|
|
254
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
223
255
|
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
224
256
|
makeRoutesPlugin(hydrateManifest),
|
|
225
257
|
resolverPlugin(config, "browser"),
|
|
@@ -233,6 +265,7 @@ export async function buildProject(
|
|
|
233
265
|
throw: false,
|
|
234
266
|
splitting: true,
|
|
235
267
|
plugins: [
|
|
268
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
236
269
|
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
237
270
|
makeRoutesPlugin(domManifest),
|
|
238
271
|
resolverPlugin(config, "browser"),
|
package/src/server/client-dir.ts
CHANGED
|
@@ -8,6 +8,12 @@ const logger = log.scope("build");
|
|
|
8
8
|
/** The URL the browser bundle is served under. */
|
|
9
9
|
export const CLIENT_URL = "/__grimoire__/";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* In dev, the one copy of @sigil-dev/runtime every browser module shares: the
|
|
13
|
+
* client bundles and HMR-swapped modules alike. See sharedDevRuntime.
|
|
14
|
+
*/
|
|
15
|
+
export const RUNTIME_URL = `${CLIENT_URL}runtime.js`;
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* Where the browser bundle is written: hydrate.js, the client router, their
|
|
13
19
|
* chunks, and in dev the runtime. Generated output, so it lives in .grimoire/
|
|
@@ -198,6 +198,39 @@ describe("navigate — loading export", () => {
|
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
+
describe("navigate — a route chunk that fails to load", () => {
|
|
202
|
+
// After a rebuild or a deploy, an open tab's bundle still names the old
|
|
203
|
+
// chunks, and those are gone. The import rejects; the router must load the
|
|
204
|
+
// page from the server instead of dying on an unhandled rejection.
|
|
205
|
+
test("falls back to a full page load", async () => {
|
|
206
|
+
const root = document.createElement("div");
|
|
207
|
+
root.id = "grimoire-root";
|
|
208
|
+
document.body.appendChild(root);
|
|
209
|
+
const fetchShim = captureFetch();
|
|
210
|
+
const href = location.href;
|
|
211
|
+
try {
|
|
212
|
+
router.initRouter(
|
|
213
|
+
{
|
|
214
|
+
"/gone": {
|
|
215
|
+
__lazy: async () => {
|
|
216
|
+
throw new TypeError(
|
|
217
|
+
"error loading dynamically imported module: /__grimoire__/chunk-old.js",
|
|
218
|
+
);
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
[],
|
|
223
|
+
);
|
|
224
|
+
await router.navigate("/gone");
|
|
225
|
+
expect(location.pathname).toBe("/gone");
|
|
226
|
+
} finally {
|
|
227
|
+
fetchShim.restore();
|
|
228
|
+
root.remove();
|
|
229
|
+
location.href = href;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
201
234
|
describe("navigate — view transitions", () => {
|
|
202
235
|
test("falls back to direct swap when startViewTransition is missing", async () => {
|
|
203
236
|
const root = document.createElement("div");
|