@lightspeed-js/core 0.4.2 → 0.4.4

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/dist/compile.js CHANGED
@@ -71,7 +71,7 @@ var START = "lsp ";
71
71
  var END = "/lsp";
72
72
  var MARKER_END = `<!--${END}-->`;
73
73
  function serializeMarker(payload) {
74
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
74
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
75
75
  return `<!--${START}${json}-->`;
76
76
  }
77
77
 
package/dist/index.js CHANGED
@@ -1275,6 +1275,11 @@ function isSlotStash(node) {
1275
1275
  function slotNodesFor(payload, between) {
1276
1276
  if (!payload.ssr)
1277
1277
  return between;
1278
+ if (payload.slot) {
1279
+ const template = document.createElement("template");
1280
+ template.innerHTML = payload.slot;
1281
+ return Array.from(template.content.childNodes);
1282
+ }
1278
1283
  const stash = between.find(isSlotStash);
1279
1284
  return stash ? Array.from(stash.content.childNodes) : [];
1280
1285
  }
@@ -2752,8 +2757,6 @@ class LightspeedRuntime {
2752
2757
  reasons.push(`${instance.models} two-way binding(s)`);
2753
2758
  if (instance.wantsMount)
2754
2759
  reasons.push("onMounted");
2755
- if (instance.updateCallbacks.length)
2756
- reasons.push("onUpdate");
2757
2760
  const cells = [...instance.runtimeCells].filter((key) => !this.cells.isBakedOnly(key) && (key !== "route" || options.routeIsLive));
2758
2761
  if (cells.length)
2759
2762
  reasons.push(`reads ${cells.join(", ")}`);
package/dist/ssg.js CHANGED
@@ -1260,7 +1260,7 @@ var START = "lsp ";
1260
1260
  var END = "/lsp";
1261
1261
  var MARKER_END = `<!--${END}-->`;
1262
1262
  function serializeMarker(payload) {
1263
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
1263
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
1264
1264
  return `<!--${START}${json}-->`;
1265
1265
  }
1266
1266
  function isMarkerStart(node) {
@@ -1298,6 +1298,11 @@ function isSlotStash(node) {
1298
1298
  function slotNodesFor(payload, between) {
1299
1299
  if (!payload.ssr)
1300
1300
  return between;
1301
+ if (payload.slot) {
1302
+ const template = document.createElement("template");
1303
+ template.innerHTML = payload.slot;
1304
+ return Array.from(template.content.childNodes);
1305
+ }
1301
1306
  const stash = between.find(isSlotStash);
1302
1307
  return stash ? Array.from(stash.content.childNodes) : [];
1303
1308
  }
@@ -2860,8 +2865,6 @@ class LightspeedRuntime {
2860
2865
  reasons.push(`${instance.models} two-way binding(s)`);
2861
2866
  if (instance.wantsMount)
2862
2867
  reasons.push("onMounted");
2863
- if (instance.updateCallbacks.length)
2864
- reasons.push("onUpdate");
2865
2868
  const cells = [...instance.runtimeCells].filter((key) => !this.cells.isBakedOnly(key) && (key !== "route" || options.routeIsLive));
2866
2869
  if (cells.length)
2867
2870
  reasons.push(`reads ${cells.join(", ")}`);
@@ -3357,7 +3360,7 @@ function readIslands(document2) {
3357
3360
  hydrate: payload?.hydrate,
3358
3361
  binds: Object.values(payload?.bind ?? {}),
3359
3362
  handlers: Object.keys(payload?.on ?? {}).length,
3360
- slotted: false,
3363
+ slotted: !!payload?.slot,
3361
3364
  children: []
3362
3365
  };
3363
3366
  (stack[stack.length - 1]?.children ?? roots).push(island);
@@ -3368,9 +3371,6 @@ function readIslands(document2) {
3368
3371
  for (let cursor = island.start.nextSibling;cursor && cursor !== island.end; cursor = cursor.nextSibling) {
3369
3372
  if (cursor.nodeType !== 1)
3370
3373
  continue;
3371
- if (cursor.hasAttribute("data-lsp-slot")) {
3372
- island.slotted = true;
3373
- }
3374
3374
  const id = cursor.getAttribute("data-lsp-instance");
3375
3375
  if (id && !island.instance)
3376
3376
  island.instance = id;
@@ -3432,13 +3432,9 @@ function markRendered(document2, slots) {
3432
3432
  continue;
3433
3433
  }
3434
3434
  payload.ssr = 1;
3435
+ if (slot.html.trim())
3436
+ payload.slot = slot.html;
3435
3437
  slot.start.data = serializeMarker(payload).slice(4, -3);
3436
- if (slot.html.trim()) {
3437
- const template = document2.createElement("template");
3438
- template.setAttribute("data-lsp-slot", "");
3439
- template.innerHTML = slot.html;
3440
- slot.start.parentNode?.insertBefore(template, slot.start.nextSibling);
3441
- }
3442
3438
  rendered++;
3443
3439
  }
3444
3440
  return { rendered, skipped };
@@ -60,11 +60,24 @@ export interface MarkerPayload {
60
60
  needs?: string[];
61
61
  /** Set by the build: the content between the markers is rendered output. */
62
62
  ssr?: number;
63
+ /**
64
+ * Set by the build: the island's slot content, as HTML, for the client to
65
+ * rebuild from - the content between the markers is output, not slot
66
+ * content.
67
+ *
68
+ * In the marker rather than in an element beside the output, because an
69
+ * element there is a sibling the page's CSS can see: a stash before each
70
+ * island broke `.item + .item` in the build's HTML, and the layout shifted
71
+ * when hydration took the stash away.
72
+ */
73
+ slot?: string;
63
74
  }
64
75
  export declare const MARKER_END = "<!--/lsp-->";
65
76
  /**
66
77
  * A comment may not contain `--`, so any run of dashes in the payload is
67
- * escaped. `-` parses back to `-`, so the round trip is lossless.
78
+ * escaped; nor `<!--`, which slot content full of nested markers would bring,
79
+ * so `<` is escaped too. Both parse back to themselves: the round trip is
80
+ * lossless.
68
81
  */
69
82
  export declare function serializeMarker(payload: MarkerPayload): string;
70
83
  export declare function isMarkerStart(node: Node): boolean;
@@ -75,13 +88,17 @@ export declare function parseMarker(node: Node): MarkerPayload | null;
75
88
  * Returns -1 if unterminated.
76
89
  */
77
90
  export declare function findMarkerEnd(nodes: Node[], start: number): number;
78
- /** The inert `<template data-lsp-slot>` a server-rendered island keeps its slot content in. */
91
+ /**
92
+ * The inert `<template data-lsp-slot>` a server-rendered island kept its slot
93
+ * content in before 0.4.4. The payload's `slot` replaced it; this stays so a
94
+ * page built by an older version still hydrates.
95
+ */
79
96
  export declare function isSlotStash(node: Node): boolean;
80
97
  /**
81
98
  * The slot content for a marker.
82
99
  *
83
100
  * For a server-rendered island the nodes between the comments are *output*,
84
- * not slot content - the original is stashed in an inert
85
- * `<template data-lsp-slot>` so the client can rebuild from it.
101
+ * not slot content - the original travels in the payload's `slot` (or, from
102
+ * builds before 0.4.4, in a `<template data-lsp-slot>` stash).
86
103
  */
87
104
  export declare function slotNodesFor(payload: MarkerPayload, between: Node[]): Node[];
package/dist/vite.js CHANGED
@@ -691,7 +691,7 @@ var START = "lsp ";
691
691
  var END = "/lsp";
692
692
  var MARKER_END = `<!--${END}-->`;
693
693
  function serializeMarker(payload) {
694
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
694
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
695
695
  return `<!--${START}${json}-->`;
696
696
  }
697
697
  function isMarkerStart(node) {
@@ -729,6 +729,11 @@ function isSlotStash(node) {
729
729
  function slotNodesFor(payload, between) {
730
730
  if (!payload.ssr)
731
731
  return between;
732
+ if (payload.slot) {
733
+ const template = document.createElement("template");
734
+ template.innerHTML = payload.slot;
735
+ return Array.from(template.content.childNodes);
736
+ }
732
737
  const stash = between.find(isSlotStash);
733
738
  return stash ? Array.from(stash.content.childNodes) : [];
734
739
  }
@@ -4251,8 +4256,6 @@ class LightspeedRuntime {
4251
4256
  reasons.push(`${instance.models} two-way binding(s)`);
4252
4257
  if (instance.wantsMount)
4253
4258
  reasons.push("onMounted");
4254
- if (instance.updateCallbacks.length)
4255
- reasons.push("onUpdate");
4256
4259
  const cells = [...instance.runtimeCells].filter((key) => !this.cells.isBakedOnly(key) && (key !== "route" || options.routeIsLive));
4257
4260
  if (cells.length)
4258
4261
  reasons.push(`reads ${cells.join(", ")}`);
@@ -4748,7 +4751,7 @@ function readIslands(document2) {
4748
4751
  hydrate: payload?.hydrate,
4749
4752
  binds: Object.values(payload?.bind ?? {}),
4750
4753
  handlers: Object.keys(payload?.on ?? {}).length,
4751
- slotted: false,
4754
+ slotted: !!payload?.slot,
4752
4755
  children: []
4753
4756
  };
4754
4757
  (stack[stack.length - 1]?.children ?? roots).push(island);
@@ -4759,9 +4762,6 @@ function readIslands(document2) {
4759
4762
  for (let cursor = island.start.nextSibling;cursor && cursor !== island.end; cursor = cursor.nextSibling) {
4760
4763
  if (cursor.nodeType !== 1)
4761
4764
  continue;
4762
- if (cursor.hasAttribute("data-lsp-slot")) {
4763
- island.slotted = true;
4764
- }
4765
4765
  const id = cursor.getAttribute("data-lsp-instance");
4766
4766
  if (id && !island.instance)
4767
4767
  island.instance = id;
@@ -4823,13 +4823,9 @@ function markRendered(document2, slots) {
4823
4823
  continue;
4824
4824
  }
4825
4825
  payload.ssr = 1;
4826
+ if (slot.html.trim())
4827
+ payload.slot = slot.html;
4826
4828
  slot.start.data = serializeMarker(payload).slice(4, -3);
4827
- if (slot.html.trim()) {
4828
- const template = document2.createElement("template");
4829
- template.setAttribute("data-lsp-slot", "");
4830
- template.innerHTML = slot.html;
4831
- slot.start.parentNode?.insertBefore(template, slot.start.nextSibling);
4832
- }
4833
4829
  rendered++;
4834
4830
  }
4835
4831
  return { rendered, skipped };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed-js/core",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Lightspeed: a compile-first framework for islands of reactivity in static HTML.",
5
5
  "keywords": [
6
6
  "lightspeed",