@opsydyn/astro-foldkit 0.10.0 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.10.0...astro-foldkit-v0.11.0) (2026-11-12)
4
+
5
+ ### Features
6
+
7
+ - **astro-foldkit:** warn about islands that fail silently ([166dc12](https://github.com/opsydyn/fold-kit-experiments/commit/166dc12f752ccb1ec499a18196b40600d0d481dd))
8
+ - **astro-foldkit:** warn about islands that fail silently ([232e940](https://github.com/opsydyn/fold-kit-experiments/commit/232e94023d5181e049d6d964a93220d364d06fff))
9
+
3
10
  ## [0.10.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.9.3...astro-foldkit-v0.10.0) (2026-11-11)
4
11
 
5
12
  ### Features
package/README.md CHANGED
@@ -152,6 +152,52 @@ Two consequences are worth knowing:
152
152
  an empty mount measures 0x0 and never intersects, so the island silently
153
153
  never hydrates. A pre-rendered island has size, and the directive works.
154
154
 
155
+ ### Choosing when JavaScript runs
156
+
157
+ Pre-rendering separates two decisions that used to be one: whether an island
158
+ appears in the HTML, and whether it ships JavaScript. Make them per island.
159
+
160
+ | Island needs | Write | JavaScript at load |
161
+ | --------------------------- | ------------------------------------------------- | ---------------------------- |
162
+ | To be read, never touched | `prerender: true`, **no directive** | none for this island |
163
+ | Interaction, below the fold | `prerender: true`, `client:visible` | none until it is scrolled to |
164
+ | Interaction, immediately | `prerender: true`, `client:load` or `client:idle` | the runtime, at load |
165
+ | A browser-only `init` | no `prerender`, `client:load` or `client:idle` | the runtime, at load |
166
+
167
+ An island with no directive is Astro's ordinary static component: Astro emits
168
+ no `<astro-island>` element and no script, so a pre-rendered FoldKit chart with
169
+ no directive is complete HTML and nothing else. Most charts in a report are
170
+ never interacted with, and this is how they should ship.
171
+
172
+ One thing decides how much any of this saves: **the FoldKit runtime is shared,
173
+ so one island that hydrates at load pays for all of it.** Making three of four
174
+ islands static saves their own chunks and serialised props, not the runtime the
175
+ fourth still needs. The large win comes when _nothing_ on the page hydrates at
176
+ load. The pattern that gets there is to pre-render everything, leave the
177
+ readable islands without a directive, and give the one interactive island
178
+ `client:visible` if it sits below the fold.
179
+
180
+ Measured on a report page with three charts and a data grid over 7,729 rows:
181
+
182
+ | Configuration | JavaScript at load | After scrolling to the grid |
183
+ | ------------------------------------------------------------- | -------------------- | --------------------------- |
184
+ | Four islands, `client:load` | 377 KB, 17 requests | — |
185
+ | Three charts static, grid `client:load` | 351 KB, 8 requests | — |
186
+ | Everything pre-rendered, charts static, grid `client:visible` | **0 KB, 0 requests** | 351 KB, 8 requests |
187
+
188
+ In the last configuration the whole report, the grid's first page included,
189
+ renders before any JavaScript runs. A chart that loses its hover readout by
190
+ going static can keep the information as a native SVG `<title>` on each mark,
191
+ which the browser shows as a tooltip and which costs no runtime.
192
+
193
+ The renderer warns at build and dev time about the two arrangements that fail
194
+ without an error, each once per component:
195
+
196
+ - an island with **no directive and no `prerender`** renders an empty mount and
197
+ ships nothing, so it never displays anything;
198
+ - an island with **`client:visible` and no `prerender`** never intersects, for
199
+ the reason above, so it never hydrates.
200
+
155
201
  FoldKit replaces the inner mount, not the outer `<astro-island>`. The outer
156
202
  element remains Astro's lifecycle owner, including for empty `client:only`
157
203
  hosts, where the client renderer creates an inner mount. Nested islands keep
package/dist/server.d.mts CHANGED
@@ -19,10 +19,19 @@ type AstroLike<Props extends AstroProps> = Readonly<{
19
19
  params?: PageParams;
20
20
  props?: Props;
21
21
  }>;
22
+ /**
23
+ * What Astro passes a renderer about the component it is rendering: its name,
24
+ * and the client directive it carries, if any. A `client:only` component never
25
+ * reaches the renderer, so it never appears here.
26
+ */
27
+ type AstroRenderMetadata = Readonly<{
28
+ displayName?: string;
29
+ hydrate?: string;
30
+ }>;
22
31
  declare function check<Component>(component: Component): Promise<boolean>;
23
- declare function renderToStaticMarkup(this: RendererThis | void, component: AstroComponentInput, props: AstroProps, slots: AstroSlots): Promise<{
32
+ declare function renderToStaticMarkup(this: RendererThis | void, component: AstroComponentInput, props: AstroProps, slots: AstroSlots, metadata?: AstroRenderMetadata): Promise<{
24
33
  html: string;
25
34
  }>;
26
35
  declare const renderer: NamedSSRLoadedRendererValue;
27
36
  //#endregion
28
- export { AstroComponentInput, AstroProps, AstroSlots, check, renderer as default, renderToStaticMarkup };
37
+ export { AstroComponentInput, AstroProps, AstroRenderMetadata, AstroSlots, check, renderer as default, renderToStaticMarkup };
package/dist/server.mjs CHANGED
@@ -45,12 +45,37 @@ const isPrerenderedApp = (value) => isFoldkitApp(value) && value.prerender === t
45
45
  const renderIsland = async (component, props) => {
46
46
  return { html: islandMount((await renderFoldkitIslandMarkup(await component.load(), props)).html) };
47
47
  };
48
+ const warnedIslands = /* @__PURE__ */ new Set();
49
+ const warnOnce = (key, message) => {
50
+ if (warnedIslands.has(key)) return;
51
+ warnedIslands.add(key);
52
+ console.warn(message);
53
+ };
54
+ /**
55
+ * Names the two ways an island that is not pre-rendered fails without an
56
+ * error, both of which leave it as the empty mount shell forever.
57
+ *
58
+ * With no client directive, nothing ever replaces the shell, so the island
59
+ * renders nothing and ships nothing. With `client:visible`, Astro observes the
60
+ * island's children because `astro-island` is `display: contents`; the empty
61
+ * mount measures 0x0, a zero-area target never intersects, and the island never
62
+ * hydrates. Other directives fire whatever the island's size.
63
+ *
64
+ * Both warn rather than fail: the shell is still valid output, and a warning
65
+ * should never be what breaks a build.
66
+ */
67
+ const diagnoseShellIsland = (metadata) => {
68
+ const name = metadata?.displayName ?? "A FoldKit island";
69
+ if (metadata?.hydrate === void 0) warnOnce(`${name}:no-directive`, `[astro-foldkit] ${name} has no client directive and is not pre-rendered, so it renders an empty mount and ships no JavaScript: it will never display anything. Pass { prerender: true } to lazyApp to render it as static HTML, or add a client directive.`);
70
+ else if (metadata.hydrate === "visible") warnOnce(`${name}:visible`, `[astro-foldkit] ${name} uses client:visible but is not pre-rendered. Astro observes an island's children, and an empty FoldKit mount measures 0x0, so it never intersects and the island never hydrates. Pass { prerender: true } to lazyApp, or use client:load or client:idle.`);
71
+ };
48
72
  async function check(component) {
49
73
  return isFoldkitApp(component) || isFoldkitPage(component);
50
74
  }
51
- async function renderToStaticMarkup(component, props, slots) {
75
+ async function renderToStaticMarkup(component, props, slots, metadata) {
52
76
  if (isFoldkitPage(component)) return renderPage(this?.result, component, props, slots);
53
77
  if (isPrerenderedApp(component)) return renderIsland(component, props);
78
+ diagnoseShellIsland(metadata);
54
79
  return { html: islandMount("") };
55
80
  }
56
81
  const renderer = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opsydyn/astro-foldkit",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Astro integration and renderer for FoldKit.",
5
5
  "keywords": [
6
6
  "astro",
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/node": "^22.0.0",
79
- "astro": "7.4.0",
79
+ "astro": "7.4.11",
80
80
  "bun-types": "^1.3.14",
81
81
  "effect": "4.1.0",
82
82
  "fast-check": "^4.8.0",