@sigil-dev/grimoire 0.7.1 → 0.7.3

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
5
  "private": false,
6
- "version": "0.7.1",
6
+ "version": "0.7.3",
7
7
  "devDependencies": {
8
8
  "@types/bun": "latest"
9
9
  },
@@ -28,8 +28,8 @@
28
28
  "@babel/plugin-syntax-jsx": "^8.0.0-rc.6",
29
29
  "@babel/plugin-syntax-typescript": "^8.0.0-rc.6",
30
30
  "@babel/types": "^8.0.0-rc.6",
31
- "@sigil-dev/compiler": "0.7.1",
32
- "@sigil-dev/runtime": "0.7.1",
31
+ "@sigil-dev/compiler": "0.7.3",
32
+ "@sigil-dev/runtime": "0.7.3",
33
33
  "vite": "^8.0.16"
34
34
  },
35
35
  "peerDependencies": {
@@ -4,38 +4,37 @@ let routeMap: Record<string, (props: any) => any> = {};
4
4
  let disposeCurrentPage: (() => void) | null = null;
5
5
 
6
6
  async function navigate(path: string) {
7
- const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
8
- const json = await res.json();
9
- const { data, params, pattern, head } = json;
7
+ const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
8
+ const json = await res.json();
9
+ const { data, params, pattern, head } = json;
10
+ const Page = routeMap[pattern];
11
+ if (!Page) {
12
+ window.location.href = path;
13
+ return;
14
+ }
10
15
 
11
- const Page = routeMap[pattern];
12
- if (!Page) {
13
- window.location.href = path;
14
- return;
15
- }
16
-
17
- // Tear down all effects from the previous page before mounting the next one.
18
- disposeCurrentPage?.();
19
- disposeCurrentPage = null;
16
+ disposeCurrentPage?.();
17
+ disposeCurrentPage = null;
20
18
 
21
- // SPA navigation has no SSR nodes to claim — start with an empty pool so
22
- // the hydrate-compiled components create fresh DOM instead of recycling stale nodes.
23
- (globalThis as any).__nodes = [];
19
+ // SPA navigation: empty pool so components create fresh DOM
20
+ pushHydrationNodes([]);
21
+ let node: any;
22
+ disposeCurrentPage = withEffectScope(() => {
23
+ try {
24
+ node = Page({ data, params });
25
+ } finally {
26
+ popHydrationNodes();
27
+ }
28
+ });
24
29
 
25
- let node: any;
26
- disposeCurrentPage = withEffectScope(() => {
27
- node = Page({ data, params });
28
- });
29
-
30
- const slot = document.getElementById("grimoire-page");
31
- if (!slot) return;
32
- slot.replaceChildren(node);
33
- updateHead(head);
34
- history.pushState({}, "", path);
35
- currentPath = path;
36
- window.scrollTo(0, 0);
30
+ const slot = document.getElementById("grimoire-page");
31
+ if (!slot) return;
32
+ slot.replaceChildren(node);
33
+ updateHead(head);
34
+ history.pushState({}, "", path);
35
+ currentPath = path;
36
+ window.scrollTo(0, 0);
37
37
  }
38
-
39
38
  let currentPath = location.pathname;
40
39
 
41
40
  export function initRouter(
@@ -6,17 +6,21 @@ const stateEl = document.getElementById("__grimoire_state__");
6
6
  let initialDispose: (() => void) | undefined;
7
7
 
8
8
  if (stateEl) {
9
- const state = JSON.parse(stateEl.textContent!);
10
- const Page = routes[state.pattern];
11
- if (Page) {
12
- const slot = document.getElementById("grimoire-page");
13
- if (slot) {
14
- (globalThis as any).__nodes = Array.from(slot.childNodes);
15
- initialDispose = withEffectScope(() => {
16
- Page({ data: state.data, params: state.params });
17
- });
18
- }
19
- }
9
+ const state = JSON.parse(stateEl.textContent!);
10
+ const Page = routes[state.pattern];
11
+ if (Page) {
12
+ const slot = document.getElementById("grimoire-page");
13
+ if (slot) {
14
+ pushHydrationNodes(Array.from(slot.childNodes) as ChildNode[]);
15
+ initialDispose = withEffectScope(() => {
16
+ try {
17
+ Page({ data: state.data, params: state.params });
18
+ } finally {
19
+ popHydrationNodes();
20
+ }
21
+ });
22
+ }
23
+ }
20
24
  }
21
25
 
22
26
  initRouter(routes, initialDispose);