@opsydyn/astro-foldkit 0.8.1 → 0.8.2
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 +8 -0
- package/README.md +32 -0
- package/dist/client.mjs +74 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.2](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.8.1...astro-foldkit-v0.8.2) (2026-10-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **astro-foldkit:** retain island runtime ownership across swaps ([a6a1753](https://github.com/opsydyn/fold-kit-experiments/commit/a6a1753a508dd7b44ad41d78f473b3e574918b25))
|
|
9
|
+
* **astro-foldkit:** sequence island restart through public embed ([3b7fbeb](https://github.com/opsydyn/fold-kit-experiments/commit/3b7fbeb66f5f9431c4475e36b9aac139b30e2d53))
|
|
10
|
+
|
|
3
11
|
## [0.8.1](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.8.0...astro-foldkit-v0.8.1) (2026-10-10)
|
|
4
12
|
|
|
5
13
|
Example-site maintenance release: Stateflow Observatory is linked from the
|
package/README.md
CHANGED
|
@@ -12,6 +12,12 @@ There are two deliberately separate entry paths:
|
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
|
+
For coding agents, the independent
|
|
16
|
+
[astro-foldkit skill](https://github.com/opsydyn/fold-kit-experiments/tree/main/skills/astro-foldkit)
|
|
17
|
+
includes consumer guidance and a standalone island/SSG example. Install the
|
|
18
|
+
complete skill folder through your agent host; it is separate from this npm
|
|
19
|
+
package and does not require the Viz skill.
|
|
20
|
+
|
|
15
21
|
```sh
|
|
16
22
|
npm install @opsydyn/astro-foldkit
|
|
17
23
|
# peer deps
|
|
@@ -99,6 +105,11 @@ execute the FoldKit application during SSR; the application is loaded and
|
|
|
99
105
|
embedded only by the client renderer. Astro still owns the outer island
|
|
100
106
|
serialisation and client directive behavior.
|
|
101
107
|
|
|
108
|
+
FoldKit replaces the inner mount, not the outer `<astro-island>`. The outer
|
|
109
|
+
element remains Astro's lifecycle owner, including for empty `client:only`
|
|
110
|
+
hosts, where the client renderer creates an inner mount. Nested islands keep
|
|
111
|
+
their own mounts.
|
|
112
|
+
|
|
102
113
|
The demo app's [`/request-diagnostics`](../../apps/web/src/pages/request-diagnostics.astro) page shows the integration boundary with a practical machine-driven chart workflow. The page uses `@opsydyn/astro-foldkit` for hydration, `@opsydyn/foldkit-viz` for chart primitives, and `foldkit/experimental/machine` in the application update layer.
|
|
103
114
|
|
|
104
115
|
The [`/comparison`](../../apps/web/src/pages/comparison.astro) example hosts
|
|
@@ -445,6 +456,27 @@ The bridge sends `coldLoad` immediately for the first mount of an island identit
|
|
|
445
456
|
|
|
446
457
|
The integration owns only lifecycle observation and port delivery. The app owns parsing `path` into its route type, mapping the event into a past-tense Message, and deciding whether an `entered` event should run a load or revalidation command. Keep that policy in `update` or a FoldKit `Transition`, so SSR props, navigation facts, and side effects remain separate. When an app uses exited to interrupt work, the interrupt key, state, and outcome policy stay in its update loop; the integration does not cancel or replace commands.
|
|
447
458
|
|
|
459
|
+
### Retained island ownership
|
|
460
|
+
|
|
461
|
+
When Astro actually retains the same client-island element during navigation,
|
|
462
|
+
the integration preserves its running FoldKit Model and resources. Repeated
|
|
463
|
+
hydration of that host shares one initialization, including while its module
|
|
464
|
+
is loading; it does not call `init` again or start another runtime. Matching a
|
|
465
|
+
`uid` for navigation events alone is not a substitute for retaining the DOM host.
|
|
466
|
+
|
|
467
|
+
Props seed `init` once per live runtime. Changes to Astro's serialized props do
|
|
468
|
+
not reseed an active retained island; use app-owned inbound ports for live data.
|
|
469
|
+
On genuine `astro:unmount`, the integration detaches its navigation bridge and
|
|
470
|
+
disposes the runtime. Unmount during module loading prevents a later detached
|
|
471
|
+
mount. Module-load or pure `init` failure releases ownership so hydration can
|
|
472
|
+
retry; asynchronous runtime startup failures remain FoldKit-owned.
|
|
473
|
+
|
|
474
|
+
Remounting the same host starts with fresh props and uses public `Runtime.embed`
|
|
475
|
+
sequencing to wait for previous teardown before restarting. The host must still
|
|
476
|
+
represent the same app, schemas, ports and update definition. This contract is
|
|
477
|
+
for `lazyApp` / `defineApp` islands, not a new retained-navigation guarantee for
|
|
478
|
+
`definePage` owners.
|
|
479
|
+
|
|
448
480
|
Pass the ports map to `makeApplication` alongside your `init`, `update`, and `view`:
|
|
449
481
|
|
|
450
482
|
```ts
|
package/dist/client.mjs
CHANGED
|
@@ -113,7 +113,18 @@ const defaultRuntime = {
|
|
|
113
113
|
hydrate: (program, options) => Runtime.hydrate(program, options)
|
|
114
114
|
};
|
|
115
115
|
const isPageOwner = (component) => typeof component === "function" && "__foldkitPage" in component && component.__foldkitPage === true;
|
|
116
|
+
const findIslandMount = (element) => {
|
|
117
|
+
const mounts = Array.from(element.querySelectorAll("[data-foldkit-island=\"true\"]")).filter((mount) => mount.closest("astro-island") === element);
|
|
118
|
+
if (mounts.length > 1) throw new Error(`Expected at most one owned FoldKit island mount inside the Astro island, found ${mounts.length}.`);
|
|
119
|
+
if (mounts[0]) return mounts[0];
|
|
120
|
+
const mount = element.ownerDocument.createElement("div");
|
|
121
|
+
mount.setAttribute("data-foldkit-island", "true");
|
|
122
|
+
element.appendChild(mount);
|
|
123
|
+
return mount;
|
|
124
|
+
};
|
|
116
125
|
function createClientRenderer(runtime = defaultRuntime, environment = {}) {
|
|
126
|
+
const islandRenders = /* @__PURE__ */ new WeakMap();
|
|
127
|
+
const islandPrograms = /* @__PURE__ */ new WeakMap();
|
|
117
128
|
return (element) => async (component, props, _slots, _meta) => {
|
|
118
129
|
const clientEnvironment = {
|
|
119
130
|
document: environment.document ?? globalThis.document,
|
|
@@ -131,32 +142,74 @@ function createClientRenderer(runtime = defaultRuntime, environment = {}) {
|
|
|
131
142
|
runtime.hydrate(application, { buildId: readFoldkitBuildId() });
|
|
132
143
|
return;
|
|
133
144
|
}
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
view,
|
|
142
|
-
container: element,
|
|
143
|
-
preserveScroll: true
|
|
145
|
+
const existingRender = islandRenders.get(element);
|
|
146
|
+
if (existingRender) return existingRender;
|
|
147
|
+
let unmountedWhileLoading = false;
|
|
148
|
+
let disposeAfterFailure = () => {};
|
|
149
|
+
const removePendingUnmount = listenOnce(element, "astro:unmount", () => {
|
|
150
|
+
unmountedWhileLoading = true;
|
|
151
|
+
islandRenders.delete(element);
|
|
144
152
|
});
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (
|
|
153
|
+
const renderIsland = async () => {
|
|
154
|
+
const config = await component.load();
|
|
155
|
+
if (unmountedWhileLoading) return;
|
|
156
|
+
removePendingUnmount();
|
|
157
|
+
const runtimeConfig = config;
|
|
158
|
+
const baseView = runtimeConfig.view;
|
|
159
|
+
const view = shouldSkipMetadata(props) ? withNoMetaView(baseView, clientEnvironment.document.title) : baseView;
|
|
160
|
+
let owner = islandPrograms.get(element);
|
|
161
|
+
const mount = owner === void 0 ? findIslandMount(element) : void 0;
|
|
162
|
+
if (mount) mount.id ||= `${element.id}--foldkit-mount`;
|
|
163
|
+
const initial = config.init(props);
|
|
164
|
+
if (owner) owner.prepare(initial, view);
|
|
165
|
+
else {
|
|
166
|
+
let boot = {
|
|
167
|
+
initial,
|
|
168
|
+
view
|
|
169
|
+
};
|
|
170
|
+
owner = {
|
|
171
|
+
program: runtime.makeApplication({
|
|
172
|
+
...runtimeConfig,
|
|
173
|
+
init: () => boot.initial,
|
|
174
|
+
view: (model, h) => boot.view(model, h),
|
|
175
|
+
container: mount,
|
|
176
|
+
preserveScroll: true
|
|
177
|
+
}),
|
|
178
|
+
prepare: (nextInitial, nextView) => {
|
|
179
|
+
boot = {
|
|
180
|
+
initial: nextInitial,
|
|
181
|
+
view: nextView
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
islandPrograms.set(element, owner);
|
|
186
|
+
}
|
|
187
|
+
const handle = runtime.embed(owner.program);
|
|
188
|
+
let disposed = false;
|
|
189
|
+
let detachNavigation = () => {};
|
|
190
|
+
const dispose = () => {
|
|
191
|
+
if (disposed) return;
|
|
155
192
|
disposed = true;
|
|
193
|
+
islandRenders.delete(element);
|
|
156
194
|
detachNavigation();
|
|
157
195
|
handle.dispose();
|
|
196
|
+
};
|
|
197
|
+
disposeAfterFailure = dispose;
|
|
198
|
+
if (config.navigation) {
|
|
199
|
+
const port = handle.ports?.[config.navigation.port];
|
|
200
|
+
if (port) detachNavigation = attachNavigationBridge(element, config.navigation, (value) => port.send(value), clientEnvironment);
|
|
201
|
+
else console.warn(`FoldKit navigation port "${config.navigation.port}" is not available`);
|
|
158
202
|
}
|
|
159
|
-
|
|
203
|
+
element.addEventListener("astro:unmount", dispose, { once: true });
|
|
204
|
+
};
|
|
205
|
+
const rendering = renderIsland().catch((error) => {
|
|
206
|
+
removePendingUnmount();
|
|
207
|
+
disposeAfterFailure();
|
|
208
|
+
if (islandRenders.get(element) === rendering) islandRenders.delete(element);
|
|
209
|
+
throw error;
|
|
210
|
+
});
|
|
211
|
+
islandRenders.set(element, rendering);
|
|
212
|
+
await rendering;
|
|
160
213
|
};
|
|
161
214
|
}
|
|
162
215
|
var client_default = createClientRenderer();
|