@opsydyn/astro-foldkit 0.9.2 → 0.10.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 +13 -0
- package/README.md +69 -4
- package/dist/client.d.mts +1 -1
- package/dist/define-app.d.mts +3 -3
- package/dist/define-app.mjs +3 -2
- package/dist/define-page.d.mts +1 -1
- package/dist/server-public.d.mts +1 -1
- package/dist/server-render.d.mts +15 -2
- package/dist/server-render.mjs +18 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +18 -2
- package/dist/{types-DDk3MMb7.d.mts → types-Dws9AyDS.d.mts} +19 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [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
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **astro-foldkit:** let an island pre-render its first paint ([46011d0](https://github.com/opsydyn/fold-kit-experiments/commit/46011d037531541d405a86b1d4079114fe547476))
|
|
8
|
+
- **astro-foldkit:** let an island pre-render its first paint ([ae06ae9](https://github.com/opsydyn/fold-kit-experiments/commit/ae06ae9df22a8cbf094cfe3a9a28ef48da5cf51d))
|
|
9
|
+
|
|
10
|
+
## [0.9.3](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.9.2...astro-foldkit-v0.9.3) (2026-10-29)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- **deps:** move to FoldKit 0.170 and Effect 4.1 with one Effect throughout ([ef2f8c2](https://github.com/opsydyn/fold-kit-experiments/commit/ef2f8c28215cf4d497b6483e3e3acc12f7a33496))
|
|
15
|
+
|
|
3
16
|
## [0.9.2](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.9.1...astro-foldkit-v0.9.2) (2026-10-28)
|
|
4
17
|
|
|
5
18
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -75,36 +75,83 @@ export default lazyApp(() => import('./main'));
|
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
77
|
// src/apps/counter/main.ts
|
|
78
|
+
import { Schema } from 'effect';
|
|
78
79
|
import type { Document, HtmlBuilder } from 'foldkit/html';
|
|
79
80
|
|
|
80
81
|
type Message = 'Inc' | 'Dec';
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
// `Model` is a runtime Schema, not a plain value: FoldKit reads `Model.ast`
|
|
84
|
+
// while the island hydrates. A non-Schema `Model` type-checks, because the
|
|
85
|
+
// contract types it as `unknown`, then fails at hydration.
|
|
86
|
+
export const Model = Schema.Number;
|
|
87
|
+
export type Model = typeof Model.Type;
|
|
88
|
+
|
|
83
89
|
export const init = () => ({ model: 0 });
|
|
84
|
-
export const update = (model:
|
|
90
|
+
export const update = (model: Model, message: Message) => ({
|
|
85
91
|
model: message === 'Inc' ? model + 1 : model - 1,
|
|
86
92
|
});
|
|
87
|
-
export const view = (model:
|
|
93
|
+
export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
|
|
88
94
|
title: `Counter: ${model}`,
|
|
89
95
|
body: h.button([h.OnClick('Inc')], [String(model)]),
|
|
90
96
|
});
|
|
91
97
|
```
|
|
92
98
|
|
|
99
|
+
A string-union `Message` keeps this example small. Applications with more than a
|
|
100
|
+
couple of messages should use `defineMessageUnion` from `foldkit/message`, as
|
|
101
|
+
the [astro-foldkit skill](../../skills/astro-foldkit) and the demo apps do.
|
|
102
|
+
|
|
93
103
|
Use the app in an Astro page:
|
|
94
104
|
|
|
95
105
|
```astro
|
|
96
106
|
---
|
|
97
107
|
import Counter from '../apps/counter/app'
|
|
98
108
|
---
|
|
99
|
-
<Counter client:load />
|
|
109
|
+
<Counter client:load noMeta />
|
|
100
110
|
```
|
|
101
111
|
|
|
112
|
+
`noMeta` keeps the island from writing `document.title` on every render tick,
|
|
113
|
+
which is what you want whenever the Astro page owns its own title — in
|
|
114
|
+
particular on any page carrying more than one island. Drop it only when this
|
|
115
|
+
island is meant to own the page title. See [`noMeta`](#nometa).
|
|
116
|
+
|
|
102
117
|
For `lazyApp` / `defineApp`, the server renderer emits a deterministic
|
|
103
118
|
`<div data-foldkit-island="true"></div>` mount shell. It does not load or
|
|
104
119
|
execute the FoldKit application during SSR; the application is loaded and
|
|
105
120
|
embedded only by the client renderer. Astro still owns the outer island
|
|
106
121
|
serialisation and client directive behavior.
|
|
107
122
|
|
|
123
|
+
### Pre-rendered islands (opt-in)
|
|
124
|
+
|
|
125
|
+
An island can put its first paint in the HTML:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { lazyApp } from '@opsydyn/astro-foldkit/define-app';
|
|
129
|
+
|
|
130
|
+
export default lazyApp<Props>(() => import('./main'), { prerender: true });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The server then loads the module and runs `init` and `view` over the props
|
|
134
|
+
Astro already serialises, filling the same mount shell instead of leaving it
|
|
135
|
+
empty. The markup is static. Nothing hydrates it, and the client replaces it on
|
|
136
|
+
boot exactly as it replaces an empty mount; because both sides run the same
|
|
137
|
+
pure `init` and `view` over the same props, the replacement is the same markup.
|
|
138
|
+
|
|
139
|
+
It carries no hydration stamp and no Flags payload, so any number of
|
|
140
|
+
pre-rendered islands may share one document — unlike a `definePage` owner, of
|
|
141
|
+
which a document may hold one. No build identity is involved, and no Astro
|
|
142
|
+
request context is read.
|
|
143
|
+
|
|
144
|
+
Two consequences are worth knowing:
|
|
145
|
+
|
|
146
|
+
- `init` and `view` run on the server. An island whose `init` touches a
|
|
147
|
+
browser-only resource must leave this off. Opting in and failing fails the
|
|
148
|
+
render rather than quietly falling back to the empty mount, because an author
|
|
149
|
+
who asked for markup should be told they did not get it.
|
|
150
|
+
- `client:visible` only works for an island that opts in. Astro's directive
|
|
151
|
+
observes an island's children, because `astro-island` is `display: contents`;
|
|
152
|
+
an empty mount measures 0x0 and never intersects, so the island silently
|
|
153
|
+
never hydrates. A pre-rendered island has size, and the directive works.
|
|
154
|
+
|
|
108
155
|
FoldKit replaces the inner mount, not the outer `<astro-island>`. The outer
|
|
109
156
|
element remains Astro's lifecycle owner, including for empty `client:only`
|
|
110
157
|
hosts, where the client renderer creates an inner mount. Nested islands keep
|
|
@@ -326,6 +373,24 @@ Both `noMeta` and `noMeta={true}` are accepted. The wrapper pins only the
|
|
|
326
373
|
Document `title`; FoldKit still applies `lang` and `dir` from the app's current
|
|
327
374
|
Document.
|
|
328
375
|
|
|
376
|
+
`noMeta` is declared on the default `EmptyProps`. Supplying your own `Props` to
|
|
377
|
+
`lazyApp<Props>` replaces that type, so re-declare the prop to keep the opt-out
|
|
378
|
+
available:
|
|
379
|
+
|
|
380
|
+
```ts
|
|
381
|
+
// src/apps/chart/app.ts
|
|
382
|
+
import { lazyApp } from '@opsydyn/astro-foldkit/define-app';
|
|
383
|
+
|
|
384
|
+
import type { ChartProps } from './main';
|
|
385
|
+
|
|
386
|
+
type Props = ChartProps & { readonly noMeta?: boolean | '' };
|
|
387
|
+
|
|
388
|
+
export default lazyApp<Props>(() => import('./main'));
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Without it, `<Chart client:load noMeta />` fails to type-check with
|
|
392
|
+
`Property 'noMeta' does not exist`.
|
|
393
|
+
|
|
329
394
|
## Architecture
|
|
330
395
|
|
|
331
396
|
`definePage` owns one server-rendered FoldKit application for a document;
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as NavigationEvent } from "./navigation-Cy2lnE4G.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as AppConfigContract, o as FoldkitApp } from "./types-Dws9AyDS.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/client.d.ts
|
|
5
5
|
interface RuntimeConfigInput {}
|
package/dist/define-app.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as EmptyProps, n as AppConfigContract, o as FoldkitApp, r as DefineAppOptions, t as AppConfig } from "./types-Dws9AyDS.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/define-app.d.ts
|
|
4
|
-
declare function defineApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>>(load: () => Promise<Config
|
|
4
|
+
declare function defineApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>>(load: () => Promise<Config>, options?: DefineAppOptions): FoldkitApp<Props, Config>;
|
|
5
5
|
/** Preferred name for Astro's intentional lazy island entry boundary. */
|
|
6
6
|
declare const lazyApp: typeof defineApp;
|
|
7
7
|
//#endregion
|
|
8
|
-
export { type AppConfig, type FoldkitApp, defineApp, lazyApp };
|
|
8
|
+
export { type AppConfig, type DefineAppOptions, type FoldkitApp, defineApp, lazyApp };
|
package/dist/define-app.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
//#region src/define-app.ts
|
|
2
|
-
function defineApp(load) {
|
|
2
|
+
function defineApp(load, options) {
|
|
3
3
|
return Object.assign((_props) => {}, {
|
|
4
4
|
__foldkit: true,
|
|
5
|
-
load
|
|
5
|
+
load,
|
|
6
|
+
prerender: options?.prerender === true
|
|
6
7
|
});
|
|
7
8
|
}
|
|
8
9
|
/** Preferred name for Astro's intentional lazy island entry boundary. */
|
package/dist/define-page.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { a as EmptyProps, c as PageConfig, d as PageFlagsContext, f as PageFlagsSchema, i as DefinePageOptions, l as PageConfigContract, p as PageParams, s as FoldkitPage, u as PageContext } from "./types-Dws9AyDS.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/define-page.d.ts
|
|
4
4
|
declare function definePage<Props extends object = EmptyProps, Flags extends object = EmptyProps, Config extends PageConfigContract<Flags> = PageConfigContract<Flags>>(load: () => Promise<Config>, options: DefinePageOptions<Props, Flags>): FoldkitPage<Props, Flags, Config>;
|
package/dist/server-public.d.mts
CHANGED
package/dist/server-render.d.mts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as PageConfigContract, n as AppConfigContract } from "./types-Dws9AyDS.mjs";
|
|
2
2
|
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
3
|
|
|
4
4
|
//#region src/server-render.d.ts
|
|
5
5
|
type ServerConfig<Flags extends object> = Pick<PageConfigContract<Flags>, 'Flags' | 'init' | 'view'>;
|
|
6
6
|
declare function renderFoldkitServerApplication<Flags extends object>(config: ServerConfig<Flags>, flags: Flags, buildId?: string): Promise<RenderedApplication>;
|
|
7
|
+
type IslandConfig<Props extends object> = Pick<AppConfigContract<Props>, 'init' | 'view'>;
|
|
8
|
+
/**
|
|
9
|
+
* Renders an island's first paint as static markup.
|
|
10
|
+
*
|
|
11
|
+
* The island declares no Flags, and needs none: `renderToString` accepts a
|
|
12
|
+
* config whose `init` takes no argument, so the props Astro already serialises
|
|
13
|
+
* for the client are closed over here. `isHydratable: false` is what keeps
|
|
14
|
+
* this safe beside other islands — the render carries no root stamp, so it
|
|
15
|
+
* cannot collide with another island's, and `Runtime.hydrate`'s one-root rule
|
|
16
|
+
* never applies because nothing hydrates this markup. The client's existing
|
|
17
|
+
* `embed` replaces it on boot.
|
|
18
|
+
*/
|
|
19
|
+
declare function renderFoldkitIslandMarkup<Props extends object>(config: IslandConfig<Props>, props: Props): Promise<RenderedApplication>;
|
|
7
20
|
//#endregion
|
|
8
|
-
export { renderFoldkitServerApplication };
|
|
21
|
+
export { renderFoldkitIslandMarkup, renderFoldkitServerApplication };
|
package/dist/server-render.mjs
CHANGED
|
@@ -11,5 +11,22 @@ async function renderFoldkitServerApplication(config, flags, buildId) {
|
|
|
11
11
|
buildId
|
|
12
12
|
}));
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Renders an island's first paint as static markup.
|
|
16
|
+
*
|
|
17
|
+
* The island declares no Flags, and needs none: `renderToString` accepts a
|
|
18
|
+
* config whose `init` takes no argument, so the props Astro already serialises
|
|
19
|
+
* for the client are closed over here. `isHydratable: false` is what keeps
|
|
20
|
+
* this safe beside other islands — the render carries no root stamp, so it
|
|
21
|
+
* cannot collide with another island's, and `Runtime.hydrate`'s one-root rule
|
|
22
|
+
* never applies because nothing hydrates this markup. The client's existing
|
|
23
|
+
* `embed` replaces it on boot.
|
|
24
|
+
*/
|
|
25
|
+
async function renderFoldkitIslandMarkup(config, props) {
|
|
26
|
+
return await Effect.runPromise(renderToString({
|
|
27
|
+
init: () => config.init(props),
|
|
28
|
+
view: config.view
|
|
29
|
+
}, { isHydratable: false }));
|
|
30
|
+
}
|
|
14
31
|
//#endregion
|
|
15
|
-
export { renderFoldkitServerApplication };
|
|
32
|
+
export { renderFoldkitIslandMarkup, renderFoldkitServerApplication };
|
package/dist/server.d.mts
CHANGED
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
2
|
-
import { renderFoldkitServerApplication } from "./server-render.mjs";
|
|
2
|
+
import { renderFoldkitIslandMarkup, renderFoldkitServerApplication } from "./server-render.mjs";
|
|
3
3
|
//#region src/server.ts
|
|
4
4
|
const claimedPageResults = /* @__PURE__ */ new WeakSet();
|
|
5
5
|
const isObjectOrFunction = (value) => value != null && (typeof value === "object" || typeof value === "function");
|
|
@@ -30,12 +30,28 @@ const renderPage = async (result, component, props, slots) => {
|
|
|
30
30
|
const flags = component.flags(context);
|
|
31
31
|
return { html: (await renderFoldkitServerApplication(await component.load(), flags, readFoldkitBuildId())).html };
|
|
32
32
|
};
|
|
33
|
+
/** The mount the client's `findIslandMount` resolves, empty or filled. */
|
|
34
|
+
const islandMount = (markup) => `<div data-foldkit-island="true">${markup}</div>`;
|
|
35
|
+
const isPrerenderedApp = (value) => isFoldkitApp(value) && value.prerender === true;
|
|
36
|
+
/**
|
|
37
|
+
* Renders an opted-in island inside the mount the client already resolves.
|
|
38
|
+
*
|
|
39
|
+
* The markup goes inside the mount rather than beside it, because
|
|
40
|
+
* `findIslandMount` resolves that element as the runtime's container and the
|
|
41
|
+
* runtime replaces its contents on boot. Server and client run the same pure
|
|
42
|
+
* `init` and `view` over the same props, so the replacement is the same markup
|
|
43
|
+
* and the swap is invisible.
|
|
44
|
+
*/
|
|
45
|
+
const renderIsland = async (component, props) => {
|
|
46
|
+
return { html: islandMount((await renderFoldkitIslandMarkup(await component.load(), props)).html) };
|
|
47
|
+
};
|
|
33
48
|
async function check(component) {
|
|
34
49
|
return isFoldkitApp(component) || isFoldkitPage(component);
|
|
35
50
|
}
|
|
36
51
|
async function renderToStaticMarkup(component, props, slots) {
|
|
37
52
|
if (isFoldkitPage(component)) return renderPage(this?.result, component, props, slots);
|
|
38
|
-
|
|
53
|
+
if (isPrerenderedApp(component)) return renderIsland(component, props);
|
|
54
|
+
return { html: islandMount("") };
|
|
39
55
|
}
|
|
40
56
|
const renderer = {
|
|
41
57
|
name: "astro-foldkit",
|
|
@@ -29,10 +29,28 @@ type AppConfig<Props extends object = EmptyProps, Model = unknown, Message exten
|
|
|
29
29
|
readonly update: Runtime.ApplicationConfig<Model, Message>['update'];
|
|
30
30
|
readonly view: Runtime.ApplicationConfig<Model, Message>['view'];
|
|
31
31
|
};
|
|
32
|
+
type DefineAppOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* Render this island's markup on the server for first paint.
|
|
35
|
+
*
|
|
36
|
+
* The markup is static: nothing hydrates it, and the client replaces it when
|
|
37
|
+
* the island boots, exactly as it replaces the empty mount today. It carries
|
|
38
|
+
* no hydration stamp and no Flags payload, so any number of pre-rendered
|
|
39
|
+
* islands may share a document — unlike a `definePage` owner, of which a
|
|
40
|
+
* document may hold one.
|
|
41
|
+
*
|
|
42
|
+
* `init` and `view` therefore run on the server. An island whose `init`
|
|
43
|
+
* touches a browser-only resource must leave this off; opting in and failing
|
|
44
|
+
* fails the render rather than quietly serving the empty mount, because an
|
|
45
|
+
* author who asked for markup should be told they did not get it.
|
|
46
|
+
*/
|
|
47
|
+
readonly prerender?: boolean;
|
|
48
|
+
};
|
|
32
49
|
type FoldkitApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>> = {
|
|
33
50
|
(props?: Props): void;
|
|
34
51
|
readonly __foldkit: true;
|
|
35
52
|
readonly load: () => Promise<Config>;
|
|
53
|
+
readonly prerender?: boolean;
|
|
36
54
|
};
|
|
37
55
|
type PageParams = Readonly<Record<string, string | undefined>>;
|
|
38
56
|
type PageFlagsContext<Props extends object = EmptyProps> = {
|
|
@@ -59,4 +77,4 @@ type FoldkitPage<Props extends object = EmptyProps, Flags extends object = Empty
|
|
|
59
77
|
readonly flags: (context: PageFlagsContext<Props>) => Flags;
|
|
60
78
|
};
|
|
61
79
|
//#endregion
|
|
62
|
-
export {
|
|
80
|
+
export { EmptyProps as a, PageConfig as c, PageFlagsContext as d, PageFlagsSchema as f, DefinePageOptions as i, PageConfigContract as l, AppConfigContract as n, FoldkitApp as o, PageParams as p, DefineAppOptions as r, FoldkitPage as s, AppConfig as t, PageContext as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opsydyn/astro-foldkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Astro integration and renderer for FoldKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -72,21 +72,22 @@
|
|
|
72
72
|
"check:fix": "oxfmt . && NODE_OPTIONS=\"--experimental-strip-types\" oxlint --fix ."
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@foldkit/vite-plugin": "^0.
|
|
76
|
-
"effect": "4.0.0"
|
|
75
|
+
"@foldkit/vite-plugin": "^0.29.0"
|
|
77
76
|
},
|
|
78
77
|
"devDependencies": {
|
|
79
78
|
"@types/node": "^22.0.0",
|
|
80
79
|
"astro": "7.4.0",
|
|
81
80
|
"bun-types": "^1.3.14",
|
|
81
|
+
"effect": "4.1.0",
|
|
82
82
|
"fast-check": "^4.8.0",
|
|
83
|
-
"foldkit": "0.
|
|
83
|
+
"foldkit": "0.170.0",
|
|
84
84
|
"tsdown": "^0.21.8",
|
|
85
85
|
"typescript": "^6.0.3"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"astro": ">=5.0.0",
|
|
89
|
-
"
|
|
89
|
+
"effect": "~4.1.0",
|
|
90
|
+
"foldkit": ">=0.170.0 <0.171.0"
|
|
90
91
|
},
|
|
91
92
|
"engines": {
|
|
92
93
|
"node": ">=22.0.0"
|