@opsydyn/astro-effect-ui 1.0.0-next.0 → 1.0.0-next.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/README.md ADDED
@@ -0,0 +1,537 @@
1
+ # @opsydyn/astro-effect-ui
2
+
3
+ Render [Effect UI](https://github.com/Effect-TS/ui) components in
4
+ [Astro](https://astro.build): on the server, as islands that hydrate on a schedule you
5
+ choose, or in the browser only.
6
+
7
+ Astro owns the page: its markup, request data, metadata and navigation. An Effect UI
8
+ component owns its model, messages, view and update. This package is the renderer
9
+ between the two.
10
+
11
+ ## Which package: this one, or `@opsydyn/astro-foldkit`?
12
+
13
+ **Use this one.** `@opsydyn/astro-effect-ui` holds the renderer, the hydration code and
14
+ the whole API on this page.
15
+
16
+ [`@opsydyn/astro-foldkit`](https://www.npmjs.com/package/@opsydyn/astro-foldkit) is the
17
+ name the integration was first published under, when it rendered FoldKit apps. From 1.x
18
+ it contains no renderer of its own: it re-exports the integration, `astroComponent` and
19
+ `defineIslands` from this package, at one exact version, so a project that already
20
+ installs the old name keeps working.
21
+
22
+ | | `@opsydyn/astro-effect-ui` | `@opsydyn/astro-foldkit` |
23
+ | ---------------------------- | -------------------------------------- | -------------------------------------------- |
24
+ | What it is | The renderer | The earlier name, forwarding to the renderer |
25
+ | Start a new project with it | Yes | No |
26
+ | Integration, `/component` | Yes | Yes, re-exported |
27
+ | `/runtime` (`defineIslands`) | Yes | Yes, re-exported from `1.2.0` |
28
+ | Versions | `1.0.0-next.*`, on `next` and `latest` | `1.x` forwards; `0.x` is the FoldKit runtime |
29
+
30
+ ## Install
31
+
32
+ ```sh
33
+ npm install @opsydyn/astro-effect-ui@next effect@4.1.6 https://pkg.pr.new/Effect-TS/ui/@effect/ui@1b89db4
34
+ ```
35
+
36
+ `astro`, `effect` and `@effect/ui` are peer dependencies. Your components are written
37
+ with Effect and Effect UI, so your project chooses the copy and there is only one.
38
+
39
+ | Peer | Range | Note |
40
+ | ------------ | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | `astro` | `>=5.0.0 <8` | Each release is built and checked against Astro 5, 6 and 7. |
42
+ | `effect` | `~4.1.0` | |
43
+ | `@effect/ui` | `*` | Effect UI has no npm releases yet, only snapshots installed by URL, which no range can name. `1b89db4` is the one this release was tested with. |
44
+
45
+ Node 22 or later.
46
+
47
+ ## Quick start
48
+
49
+ Register the integration:
50
+
51
+ ```ts
52
+ // astro.config.ts
53
+ import { defineConfig } from 'astro/config';
54
+ import effectUi from '@opsydyn/astro-effect-ui';
55
+
56
+ export default defineConfig({ integrations: [effectUi()] });
57
+ ```
58
+
59
+ Write a component with Effect UI:
60
+
61
+ ```ts
62
+ // src/counter/main.ts
63
+ import { UiSchema } from '@effect/ui';
64
+ import { Html } from '@effect/ui/html';
65
+ import { Schema } from 'effect';
66
+
67
+ const Message = UiSchema.TaggedEnum({ Incremented: {} });
68
+
69
+ export const Counter = Html.component({
70
+ name: 'Counter',
71
+ props: Schema.Struct({ start: Schema.Int }),
72
+ model: Schema.Int,
73
+ message: Message,
74
+ }).make({
75
+ init: ({ props }) => props.start,
76
+ update: ({ model }) => model + 1,
77
+ view: (h, count) => h.button.on('click', Message.Incremented()).children(`Count: ${count}`),
78
+ });
79
+ ```
80
+
81
+ Hand it to Astro from a TypeScript module:
82
+
83
+ ```ts
84
+ // src/counter/app.ts
85
+ import { astroComponent } from '@opsydyn/astro-effect-ui/component';
86
+
87
+ import { Counter } from './main';
88
+
89
+ export default astroComponent(Counter);
90
+ ```
91
+
92
+ Use it like any Astro component. Its props are typed from the component's schema:
93
+
94
+ ```astro
95
+ ---
96
+ import Counter from '../counter/app';
97
+ ---
98
+
99
+ <Counter client:interaction start={3} />
100
+ ```
101
+
102
+ ## Choosing when an island hydrates
103
+
104
+ Astro renders the component's markup on the server whichever you choose. The directive
105
+ decides when, or whether, it gets a browser runtime.
106
+
107
+ | Directive | The component becomes interactive |
108
+ | ------------------------------- | --------------------------------------------------------------- |
109
+ | none | Never. Static markup, and no JavaScript for it. |
110
+ | `client:load` | As the page loads. |
111
+ | `client:idle` | When the browser is next idle. |
112
+ | `client:visible` | When it scrolls into view. |
113
+ | `client:media="(query)"` | When the media query matches. |
114
+ | `client:interaction` | When a reader first presses, focuses or types in it. See below. |
115
+ | `client:only="astro-effect-ui"` | In the browser only. Nothing is rendered on the server. |
116
+
117
+ `astro-effect-ui` is the renderer's name, which `client:only` needs.
118
+
119
+ ### `client:interaction`
120
+
121
+ This directive comes with the integration. An island stays as the server rendered it,
122
+ with none of its code loaded, until someone uses it.
123
+
124
+ ```astro
125
+ <Chart client:interaction />
126
+ <Chart client:interaction={{ hover: true, preload: 'visible' }} />
127
+ ```
128
+
129
+ | Option | Type | Default | Effect |
130
+ | --------- | --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
131
+ | `hover` | `boolean` | `false` | A mouse pointer entering the island hydrates it too. Suits a chart or a card that only shows something on hover. Touch and pen do not count: they press. |
132
+ | `preload` | `'idle' \| 'visible'` | none | Fetch the island's code ahead of the first interaction. Nothing hydrates early. |
133
+
134
+ What starts hydration, inside the island:
135
+
136
+ | Event | When |
137
+ | -------------------------- | --------------------------------------------- |
138
+ | `pointerdown` | Always |
139
+ | `focusin` | Always, so keyboard users reach it by tabbing |
140
+ | `keydown` | Always |
141
+ | `pointerover` from a mouse | Only with `hover: true` |
142
+
143
+ - **Input made while the island loads is kept.** A click is held and replayed. A mouse
144
+ resting on the island is replayed as `mouseenter`, once for each element under it,
145
+ outermost first. Keys pressed in that moment are not replayed.
146
+ - **Links and native controls are left alone.** A click on a link, a label, a checkbox
147
+ or a radio button does what the browser does, while the island hydrates behind it.
148
+ - **`preload: 'idle'`** waits for `requestIdleCallback`, or 200 ms where the browser
149
+ has none. **`preload: 'visible'`** fetches when the island comes within 200 px of
150
+ the viewport.
151
+ - **`preload` costs the download.** `idle` on every island of a long page fetches all
152
+ of them. On a 100 ms, 5 Mbit/s connection a first hover answered in about 950 ms
153
+ without it and about 30 ms with it.
154
+ - **Code that does not arrive is asked for again** on the next interaction, three
155
+ times in all. See [When something fails](#when-something-fails).
156
+ - **`astro check` knows the attribute.** The integration declares its type.
157
+
158
+ ## API
159
+
160
+ The package has three entry points. Everything each one exports is listed here.
161
+
162
+ | Entry point | Exports |
163
+ | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
164
+ | `@opsydyn/astro-effect-ui` | `effectUi` (default), `EffectUiOptions` |
165
+ | `@opsydyn/astro-effect-ui/component` | `astroComponent`, `AstroComponent`, `Accepted`, `IslandProps`, `IslandRendererError`, `IslandComponent`, `asIslandComponent`, `toAstro` |
166
+ | `@opsydyn/astro-effect-ui/runtime` | `defineIslands`, `ServerRuntime`, `ClientRuntime`, `IslandFailure`, `IslandFallback`, `AnyServerRuntime`, `AnyClientRuntime` |
167
+
168
+ ### `@opsydyn/astro-effect-ui`
169
+
170
+ #### `effectUi(options?)`: default export
171
+
172
+ ```ts
173
+ function effectUi(options?: EffectUiOptions): AstroIntegration;
174
+ ```
175
+
176
+ Returns the Astro integration. It does four things:
177
+
178
+ - registers the renderer, named `astro-effect-ui`;
179
+ - registers the `client:interaction` directive and declares its type for `astro check`;
180
+ - sets up Vite (see [Vite](#vite));
181
+ - for each runtime module you name, writes an entry file into Astro's generated-code
182
+ directory that makes the renderer with it.
183
+
184
+ #### `EffectUiOptions`
185
+
186
+ ```ts
187
+ type EffectUiOptions = {
188
+ readonly interaction?: boolean;
189
+ readonly runtime?: { readonly server?: string; readonly client?: string };
190
+ };
191
+ ```
192
+
193
+ | Option | Type | Default | Meaning |
194
+ | ---------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------- |
195
+ | `interaction` | `boolean` | `true` | `false` registers neither the `client:interaction` directive nor its type. |
196
+ | `runtime.server` | `string` | none | Path from the project root to a module that default-exports a server runtime. See [Services](#services-and-the-island-runtime). |
197
+ | `runtime.client` | `string` | none | The same for the browser. |
198
+
199
+ ### `@opsydyn/astro-effect-ui/component`
200
+
201
+ #### `astroComponent(component)`
202
+
203
+ ```ts
204
+ function astroComponent<C extends Component.Any>(component: C & Accepted<C>): AstroComponent<C>;
205
+ ```
206
+
207
+ Takes an Effect UI component and returns what Astro imports. The result takes the
208
+ component's props, typed from its props schema. Astro serialises an island's props to
209
+ send them to the browser, so they must be serialisable.
210
+
211
+ It accepts only a component that needs no services beyond the HTML host. For one that
212
+ issues a `Command.Service`, or needs any other service, the call is a type error whose
213
+ one property names what is missing. For a component that needs `DeleteTodo`, the
214
+ argument would have to be:
215
+
216
+ ```ts
217
+ { readonly 'astroComponent: no island runtime provides': DeleteTodo }
218
+ ```
219
+
220
+ Use the `astroComponent` that [`defineIslands`](#defineislandsservices) returns
221
+ instead.
222
+
223
+ #### `AstroComponent<C>`
224
+
225
+ ```ts
226
+ type AstroComponent<C> = (props: Component.Props<C>) => void;
227
+ ```
228
+
229
+ What `astroComponent` returns for component `C`: to Astro, a component taking its props.
230
+
231
+ #### `Accepted<C, Provided = never>`
232
+
233
+ The check `astroComponent` applies to its argument. It is `unknown`, which changes
234
+ nothing, when the HTML host and the services `Provided` cover what `C` requires.
235
+ Otherwise it is an object type with the one property shown above. Requirements typed as
236
+ `any` are let through, since nothing can be read from them.
237
+
238
+ #### `IslandProps`
239
+
240
+ ```ts
241
+ type IslandProps = object;
242
+ ```
243
+
244
+ The props an island may take.
245
+
246
+ #### `IslandRendererError`
247
+
248
+ ```ts
249
+ class IslandRendererError extends Data.TaggedError('IslandRendererError')<{
250
+ readonly message: string;
251
+ readonly cause?: unknown;
252
+ }> {}
253
+ ```
254
+
255
+ What the renderer fails with. [Errors](#errors) lists the messages.
256
+
257
+ #### `IslandComponent`, `asIslandComponent(value)`, `toAstro(component)`
258
+
259
+ ```ts
260
+ type IslandComponent = Component.Members<
261
+ string,
262
+ IslandProps,
263
+ unknown,
264
+ never,
265
+ never,
266
+ Html.Host,
267
+ Html.Elements
268
+ >;
269
+ function asIslandComponent(value: Component.Any): IslandComponent;
270
+ function toAstro<C>(component: Component.Any): AstroComponent<C>;
271
+ ```
272
+
273
+ The renderer's own entry points use these, and an app has no need to.
274
+ `IslandComponent` is a component as the renderer runs it. `asIslandComponent` narrows
275
+ a value to one, failing with `IslandRendererError` when it is not an Effect UI
276
+ component. `toAstro` is `astroComponent` without the services check.
277
+
278
+ ### `@opsydyn/astro-effect-ui/runtime`
279
+
280
+ #### `defineIslands<Services>()`
281
+
282
+ ```ts
283
+ function defineIslands<Services = never>(): {
284
+ astroComponent: <C extends Component.Any>(
285
+ component: C & Accepted<C, Services>,
286
+ ) => AstroComponent<C>;
287
+ serverRuntime: (runtime: ServerRuntime<Services>) => ServerRuntime<Services>;
288
+ clientRuntime: (runtime: ClientRuntime<Services>) => ClientRuntime<Services>;
289
+ };
290
+ ```
291
+
292
+ Names the services an app's islands may use, once, and returns three functions typed by
293
+ them.
294
+
295
+ | Returned | Use |
296
+ | --------------------------- | --------------------------------------------------------------------------------------------------------- |
297
+ | `astroComponent(component)` | As above, but accepts a component whose needs `Services` cover. |
298
+ | `serverRuntime(runtime)` | Describes what every server render shares. Default-export the result from the `runtime.server` module. |
299
+ | `clientRuntime(runtime)` | Describes what every island on a page shares. Default-export the result from the `runtime.client` module. |
300
+
301
+ `serverRuntime` and `clientRuntime` return their argument unchanged. They exist to
302
+ check it against `Services`.
303
+
304
+ #### `ServerRuntime<Services = never>`
305
+
306
+ | Field | Type | Meaning |
307
+ | -------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
308
+ | `layer` | `Layer.Layer<Services, unknown>` | Provides the services. Required as soon as `Services` names one, optional otherwise. Built once, on the first render. |
309
+ | `budget` | `Duration.Input` | How long a render waits for Layers and queries. Effect UI's default is 500 ms. |
310
+
311
+ #### `ClientRuntime<Services = never>`
312
+
313
+ | Field | Type | Meaning |
314
+ | ---------- | ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
315
+ | `layer` | `Layer.Layer<Services, unknown>` | Provides the services. Required as soon as `Services` names one, optional otherwise. Built once, when the first island on a page starts. |
316
+ | `fallback` | `IslandFallback` | The view shown in place of an island that failed. Without it the island keeps its earlier markup. |
317
+ | `onError` | `(failure: IslandFailure) => Effect.Effect<void, never, Services>` | Runs in the page's runtime when an island fails, as well as the `effect-ui:error` event. |
318
+
319
+ #### `IslandFailure`
320
+
321
+ ```ts
322
+ type IslandFailure = Readonly<{ error: unknown; phase: 'activate' | 'run' }>;
323
+ ```
324
+
325
+ An island whose component failed: `activate` if it never came alive, `run` if it failed
326
+ later. It is what `onError` receives and the `detail` of `effect-ui:error`.
327
+
328
+ #### `IslandFallback`
329
+
330
+ ```ts
331
+ type IslandFallback = NonNullable<BrowserHost.MountOptions<Html.Elements>['fallback']>;
332
+ ```
333
+
334
+ A fallback view, as Effect UI's `BrowserHost.mount` takes it: `(result, h) => view`,
335
+ where `result.cause` is why the root failed.
336
+
337
+ #### `AnyServerRuntime`, `AnyClientRuntime`
338
+
339
+ A runtime whatever its services, as the renderer receives it. They type the default
340
+ export of a runtime module once `serverRuntime` or `clientRuntime` has checked it.
341
+
342
+ ### What the server renders
343
+
344
+ | The component has | Output |
345
+ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
346
+ | No client directive | Its markup, with nothing around it and no script. |
347
+ | A client directive | Its markup inside `<div data-effect-ui-root>`, followed by its state in `<script type="application/json" data-effect-ui-state>`. Hydration adopts both. |
348
+ | `client:only` | Nothing from the component. Astro shows any `slot="fallback"` content until the browser builds it. |
349
+
350
+ Only a component's body markup is used. Astro owns the document `<head>`, so set
351
+ titles and metadata in Astro.
352
+
353
+ ### In the browser
354
+
355
+ | When | What the renderer does |
356
+ | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
357
+ | The directive fires | Adopts the server's markup and state, or builds the component under `client:only`. |
358
+ | Astro unmounts the island (`astro:unmount`, as on a client-side navigation) | Closes the component's runtime: its scope, subscriptions and resources. |
359
+ | A kept island's `props` change | Rebuilds the component. See [Kept islands](#kept-islands). |
360
+ | The component fails | See [When something fails](#when-something-fails). |
361
+
362
+ ### Events, attributes and spans
363
+
364
+ | Name | Kind | Meaning |
365
+ | -------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------- |
366
+ | `effect-ui:error` | Event on a failed island | Bubbles and crosses shadow roots. `detail` is an `IslandFailure`. |
367
+ | `astro:hydration-error` | Event | Raised by Astro 7 when hydration rejects, and by `client:interaction` on every Astro version. |
368
+ | `data-effect-ui-failed` | Attribute on a failed island | For a style or a test to find. Removed if the island is rebuilt. |
369
+ | `data-effect-ui-root` | Attribute | The element holding a hydrating component's markup. Written and read by the renderer. |
370
+ | `data-effect-ui-state` | Attribute | The script holding its serialised state. Written and read by the renderer. |
371
+ | `astro-effect-ui.render` | Span | Around each server render, with a `component` attribute. |
372
+ | `astro-effect-ui.activate` | Span | Around each island start in the browser, with the same attribute. |
373
+
374
+ ### Errors
375
+
376
+ Each is an `IslandRendererError`.
377
+
378
+ | Message | When |
379
+ | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
380
+ | `Expected an Effect UI component.` | Something other than an Effect UI component reached the renderer. |
381
+ | `<Name> has no slot named "<slot>". It declares: <names>.` | Astro passed content for a slot the component does not declare. |
382
+ | `<Name> rendered nothing on the server and has no client directive.` | A prerendered page: the build fails. On a page rendered for a request the same text is logged, prefixed `[astro-effect-ui]`, and the page is still answered. |
383
+ | `Missing Effect UI hydration markup or state.` | An island was asked to hydrate without the root or state the server writes. |
384
+ | `The <Name> island failed.` | The component failed while running. `cause` holds why. |
385
+
386
+ ## Slots
387
+
388
+ An Effect UI component declares the places a parent can fill, and its view places them.
389
+ Astro is that parent:
390
+
391
+ ```ts
392
+ export const Card = Html.component({
393
+ name: 'Card',
394
+ props: Schema.Struct({ title: Schema.String }),
395
+ model: Schema.String,
396
+ message: Schema.Never,
397
+ slots: ['default', 'footer'],
398
+ }).make({
399
+ init: ({ props }) => props.title,
400
+ update: ({ model }) => model,
401
+ view: (h, title) =>
402
+ h.section.children(h.h2(title), h.slots.default, h.footer.children(h.slots.footer)),
403
+ });
404
+ ```
405
+
406
+ ```astro
407
+ <Card client:load title="Welcome">
408
+ <p>Rendered by Astro.</p>
409
+ <small slot="footer">And so is this.</small>
410
+ </Card>
411
+ ```
412
+
413
+ - **The content is Astro's markup**, and may hold other islands.
414
+ - **Hydration keeps the server's nodes.** A slot the view removes and places again gets
415
+ the same nodes back, so an island inside it keeps running.
416
+ - **A static component gets the content with nothing around it.**
417
+ - **An undeclared slot is an error** that names the slots the component does declare.
418
+ - **Empty content is not a slot.** A slot Astro passes with only whitespace is left out.
419
+ - **`slot="fallback"` stays Astro's.** Under `client:only` it is what shows until the
420
+ component is built, and it is never passed to the component.
421
+
422
+ ## Services and the island runtime
423
+
424
+ Name the app's services once, and use the wrapper that knows them:
425
+
426
+ ```ts
427
+ // src/islands.ts
428
+ import { defineIslands } from '@opsydyn/astro-effect-ui/runtime';
429
+
430
+ export const islands = defineIslands<DeleteTodo | Flags>();
431
+ ```
432
+
433
+ ```ts
434
+ // src/effect-ui.client.ts: everything the islands of a page share
435
+ export default islands.clientRuntime({
436
+ layer: Layer.merge(DeleteTodo.layer, Flags.layer),
437
+ fallback: (_failure, h) => h.p.class('island-failed').children('This part could not load.'),
438
+ onError: (failure) => reportToTelemetry(failure),
439
+ });
440
+ ```
441
+
442
+ ```ts
443
+ // src/effect-ui.server.ts: everything a server render shares
444
+ export default islands.serverRuntime({
445
+ layer: Layer.merge(DeleteTodo.layer, Flags.layer),
446
+ budget: '200 millis',
447
+ });
448
+ ```
449
+
450
+ ```ts
451
+ // astro.config.ts
452
+ effectUi({
453
+ runtime: { server: './src/effect-ui.server.ts', client: './src/effect-ui.client.ts' },
454
+ });
455
+ ```
456
+
457
+ Then `islands.astroComponent(TodoList)` accepts a component whose needs those services
458
+ cover.
459
+
460
+ - **One runtime on each side.** The client layer is built once, when the first island
461
+ on a page starts, and every island runs in it. The server layer is built once for the
462
+ process, or for the isolate on Cloudflare Workers.
463
+ - **Request data goes in props.** The server layer outlives a request, so it must not
464
+ hold request data. An island also runs again in the browser, where no request exists.
465
+ - **Two modules, so server code stays on the server.** A server layer often imports
466
+ code that must never reach the browser. Either module may be left out.
467
+ - **Tracing and logging use Effect's own channels.** Renders and activations run inside
468
+ the spans listed above, and the renderer's log lines go through Effect's logger, so a
469
+ tracer or a logger in the layer sees them.
470
+ - **Requirements typed as `any` are let through**, since nothing can be read from them.
471
+
472
+ ## When something fails
473
+
474
+ A page keeps working when one island does not.
475
+
476
+ - **The code does not arrive.** `client:interaction` leaves the island as the server
477
+ rendered it and asks again on the next interaction, three times in all. Clicks held
478
+ during a failed attempt are dropped. After the third attempt the island is plain
479
+ markup.
480
+ - **The component fails**, while it hydrates or at any time later. Its runtime is
481
+ closed and the island shows the server's markup again, or its fallback content
482
+ under `client:only`. It no longer responds. With a `fallback` in the client runtime
483
+ that view is shown in its place instead. The island gets `data-effect-ui-failed`,
484
+ raises `effect-ui:error`, and the runtime's `onError` runs. A component that fails
485
+ to hydrate is not retried.
486
+ - **Hydration fails under any directive.** The renderer rejects, so Astro reports it
487
+ as it does for every framework: `astro:hydration-error` from Astro 7, a console
488
+ error before that.
489
+ - **A component renders nothing on the server.** With a client directive the browser
490
+ builds it. With none, nothing ever would, so a prerendered page fails the build and
491
+ a page rendered for a request is still answered, with an error logged through
492
+ Effect's logger that starts `[astro-effect-ui]`.
493
+
494
+ ```ts
495
+ document.addEventListener('effect-ui:error', (event) => report(event.detail.error));
496
+ ```
497
+
498
+ ## Kept islands
499
+
500
+ A root's props are fixed once it starts. When an island kept across a navigation with
501
+ `transition:persist` is given different props, the component is rebuilt with them and
502
+ its Model starts over. Add `transition:persist-props` to keep the island as it is.
503
+
504
+ ## Vite
505
+
506
+ The integration prebundles `effect`, `@effect/ui` and `@effect/ui/html`, so the dev
507
+ server does not discover them on the first island and reload the page. It also resolves
508
+ `effect` and `@effect/ui` once, so the renderer and your components share one copy. An
509
+ app needs neither setting in its own config.
510
+
511
+ ## Why it works this way
512
+
513
+ The decisions behind this page are recorded in the repository:
514
+
515
+ - [Hydrate on interaction](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/adr/0129-hydrate-gallery-charts-on-interaction.md)
516
+ - [Fail visibly and load ahead](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/adr/0130-make-astro-effect-ui-islands-fail-visibly-and-load-ahead.md)
517
+ - [The island runtime module](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/adr/0131-give-astro-effect-ui-islands-a-runtime-module.md)
518
+ - [Slots filled from Astro](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/adr/0132-fill-effect-ui-slots-from-astro.md)
519
+
520
+ ## Working on this package
521
+
522
+ ```sh
523
+ bun run --filter @opsydyn/astro-effect-ui build
524
+ bun run --filter @opsydyn/astro-effect-ui test
525
+ bun run --filter @opsydyn/astro-effect-ui size:check
526
+ bun run ci:astro-compat
527
+ ```
528
+
529
+ - **The build stages the npm package in `dist/`**, with this README. The workspace
530
+ manifest is private; the staged one is what gets published.
531
+ - **The size check** holds the renderer's browser code and the inlined directive to
532
+ `etc/bundle-budget.json`.
533
+ - **The compatibility check** packs this package and the forwarding one, then builds
534
+ isolated Astro 5, 6 and 7 projects from [its fixture](https://github.com/opsydyn/fold-kit-experiments/tree/main/packages/astro-effect-ui/test/compat/fixture),
535
+ which covers slots, a runtime module on each side, and the prerender flag.
536
+ - **Publishing** goes through the `effect-ui-next` train, described in the
537
+ [migration record](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/assessments/2026-11-26-effect-ui-1.0-migration.md).
package/client.d.mts CHANGED
@@ -1,11 +1,18 @@
1
1
  import { IslandProps } from "./component.mjs";
2
+ import { AnyClientRuntime } from "./runtime.mjs";
2
3
  import { Component } from "@effect/ui";
3
4
 
4
5
  //#region src/client.d.ts
5
- declare function renderer(island: HTMLElement): (component: Component.Any, props: IslandProps, slots: Record<string, string>, {
6
+ /** The client renderer, with every island run in the app's runtime when it has one. */
7
+ declare function makeClientRenderer(runtime?: AnyClientRuntime): (island: HTMLElement) => (component: Component.Any, props: IslandProps, slots: Record<string, string>, {
8
+ client
9
+ }: {
10
+ client: string;
11
+ }) => Promise<void>;
12
+ declare const _default: (island: HTMLElement) => (component: Component.Any, props: IslandProps, slots: Record<string, string>, {
6
13
  client
7
14
  }: {
8
15
  client: string;
9
16
  }) => Promise<void>;
10
17
  //#endregion
11
- export { renderer as default };
18
+ export { _default as default, makeClientRenderer };