@primate/marko 0.11.2 → 0.12.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.
@@ -1,5 +1,6 @@
1
1
  import root from "#client/root";
2
2
  import request from "#request/store";
3
+ import runtime_id from "#runtime-id";
3
4
  import client from "@primate/core/client";
4
5
  import RootView from "marko:root";
5
6
  export default class MarkoApp {
@@ -9,11 +10,13 @@ export default class MarkoApp {
9
10
  return;
10
11
  let instance;
11
12
  let current = data;
12
- let initial = data.ssr;
13
13
  const key = (next) => `${next.views.join("\0")}\0${next.request.url}`;
14
14
  const render = (next, remount = false) => {
15
15
  current = next;
16
- const props = root.toProps(next);
16
+ const props = {
17
+ ...root.toProps(next),
18
+ $global: { runtimeId: runtime_id(next.group) },
19
+ };
17
20
  if (!remount && instance !== undefined) {
18
21
  instance.update?.(props);
19
22
  return;
@@ -32,14 +35,8 @@ export default class MarkoApp {
32
35
  }
33
36
  if (data.csr) {
34
37
  const start = () => client.boot("marko", (next, update) => {
35
- if (initial && key(next) === key(current)) {
36
- initial = false;
37
- current = next;
38
- update?.();
39
- return;
40
- }
41
- initial = false;
42
- render(next, instance === undefined);
38
+ const remount = key(next) !== key(current);
39
+ render(next, remount || instance === undefined);
43
40
  update?.();
44
41
  }, (url, query) => {
45
42
  request.set({
@@ -48,6 +45,11 @@ export default class MarkoApp {
48
45
  query,
49
46
  url,
50
47
  });
48
+ }, () => {
49
+ instance?.destroy?.();
50
+ instance = undefined;
51
+ for (const mod of mods)
52
+ mod.invalidate(() => undefined);
51
53
  });
52
54
  if (document.readyState === "loading") {
53
55
  window.addEventListener("DOMContentLoaded", start, { once: true });
@@ -1,5 +1,6 @@
1
1
  import create_root from "#create-root";
2
2
  import init from "#init";
3
+ import runtime_id from "#runtime-id";
3
4
  import { compileSync } from "@marko/compiler";
4
5
  import frontend from "@primate/core/frontend";
5
6
  const styles = new Map();
@@ -18,12 +19,13 @@ function resolveVirtualDependency(_from, dependency) {
18
19
  });
19
20
  return path;
20
21
  }
21
- function compile(text, file, output, root = false) {
22
+ function compile(text, file, output, root = false, group) {
22
23
  return compileSync(text, root || file.path.startsWith("root:")
23
24
  ? root_file
24
25
  : file.path, {
25
26
  output,
26
27
  resolveVirtualDependency,
28
+ ...group === undefined ? {} : { runtimeId: runtime_id(group) },
27
29
  });
28
30
  }
29
31
  const plugin = {
@@ -69,16 +71,16 @@ export default frontend({
69
71
  },
70
72
  compile: {
71
73
  server: (text, file) => compile(text, file, "html").code,
72
- client: (text, file, root, hydrate) => {
74
+ client: (text, file, root, hydrate, group) => {
73
75
  if (root && hydrate) {
74
- root_dom = compile(text, file, "dom", true).code;
76
+ root_dom = compile(text, file, "dom", true, group).code;
75
77
  return {
76
- js: `${compile(text, file, "hydrate", true).code}
78
+ js: `${compile(text, file, "hydrate", true, group).code}
77
79
  export { default } from "./root.marko";`,
78
80
  };
79
81
  }
80
82
  return {
81
- js: compile(text, file, "dom", root).code,
83
+ js: compile(text, file, "dom", root, group).code,
82
84
  };
83
85
  },
84
86
  },
@@ -1,11 +1,13 @@
1
+ import runtime_id from "#runtime-id";
1
2
  const module = {
2
3
  name: "marko",
3
4
  extensions: [".marko"],
4
5
  conditions: ["marko"],
5
6
  layouts: true,
6
7
  client: true,
7
- async render(component, props) {
8
- return { body: (await component.render(props)).toString() };
8
+ async render(component, props, { group }) {
9
+ const $global = { runtimeId: runtime_id(group) };
10
+ return { body: (await component.render({ ...props, $global })).toString() };
9
11
  },
10
12
  };
11
13
  export default module;
@@ -0,0 +1,3 @@
1
+ declare const runtime_id: (group: string) => string;
2
+ export default runtime_id;
3
+ //# sourceMappingURL=runtime-id.d.ts.map
@@ -0,0 +1,5 @@
1
+ const runtime_id = (group) => `P${[...new TextEncoder().encode(group)]
2
+ .map(byte => byte.toString(16).padStart(2, "0"))
3
+ .join("")}`;
4
+ export default runtime_id;
5
+ //# sourceMappingURL=runtime-id.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/marko",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "Marko for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/marko",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -18,15 +18,15 @@
18
18
  "!/**/*.spec.*"
19
19
  ],
20
20
  "dependencies": {
21
- "@marko/compiler": "^5.41.2",
22
- "@primate/core": "^0.9.28",
21
+ "@marko/compiler": "^5.42.3",
22
+ "@primate/core": "^0.10.0",
23
23
  "@rcompat/fs": "^0.35.1",
24
- "marko": "^6.3.3"
24
+ "marko": "^6.3.48"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rcompat/type": "^0.18.0",
28
28
  "@types/marko": "^4.6.9",
29
- "esbuild": "^0.28.1"
29
+ "esbuild": "^0.28.2"
30
30
  },
31
31
  "imports": {
32
32
  "#tags/*": {
@@ -50,7 +50,7 @@
50
50
  }
51
51
  },
52
52
  "scripts": {
53
- "build": "npm run clean && tsc",
53
+ "build": "pnpm run clean && tsc",
54
54
  "clean": "rm -rf ./lib",
55
55
  "lint": "eslint ."
56
56
  }