foldkit-ssr 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +51 -1
  2. package/package.json +11 -11
package/README.md CHANGED
@@ -129,7 +129,7 @@ SSR.hydrate(config, Post, { buildId })
129
129
  Foldkit's root stamp (`FOLDKIT_APP_ATTRIBUTE`) among them. It imports nothing
130
130
  of `foldkit/experimental/server`, whose renderer and HTML parser `foldkit-ssr`
131
131
  brings along: about 200 kB minified (60 kB gzipped) off a page's script in the
132
- [SSR example](../../examples/foldkit-ssr). `foldkit-ssr` has all of it and the
132
+ [SSR example](../../examples/foldkit/ssr). `foldkit-ssr` has all of it and the
133
133
  server's calls, the same functions, so a plan made from either works with
134
134
  both. Import `foldkit-ssr/client` in every module the page loads, the plan and
135
135
  the view included, and `foldkit-ssr` only where the server alone runs.
@@ -287,6 +287,12 @@ release tag, public and unique per deployment. The plugin compiles it into
287
287
  both bundles; a script outside Vite, such as a prerender, reads
288
288
  `process.env.FOLDKIT_BUILD_ID`, the same value the build saw.
289
289
 
290
+ Set it even though `@foldkit/vite-plugin` can now generate an id on its own.
291
+ The generated one is compiled into Foldkit alone, where `foldkit-ssr` cannot
292
+ read it, and the client must compare builds before it reads a page's payload,
293
+ so a Model serialized by another deployment is never decoded. Asking Foldkit
294
+ to expose that id is [proposal 4](../../docs/upstream-foldkit-ssr.md#proposal-4-expose-the-compiled-build-id).
295
+
290
296
  `GET` and `HEAD` render the page for the request's URL; an application with
291
297
  Flags passes `flags: request => ...`. `POST` is handled only for a plan with a
292
298
  [server fallback](#forms-that-work-without-scripts). `OPTIONS` is answered
@@ -366,6 +372,50 @@ twice, one not starting with `/`, or a date `Date` cannot read is refused
366
372
  rather than written into a sitemap a search engine would reject. `robots`
367
373
  takes `disallow` paths and a `sitemap` path other than `/sitemap.xml`.
368
374
 
375
+ ### As a Vite plugin: `foldkit-ssr/vite`
376
+
377
+ `foldkit-ssr/vite` runs the same static build as a `closeBundle` step on the
378
+ application's own `vite build`, so a site is generated without a second script.
379
+ The application describes its site in a module (`src/site.ts`) and the plugin
380
+ evaluates it through a server, so `vite.config.ts` names a file, never
381
+ application code:
382
+
383
+ ```ts
384
+ // vite.config.ts
385
+ import { staticSite } from 'foldkit-ssr/vite'
386
+ export default defineConfig({
387
+ plugins: [foldkit(), staticSite({ site: { module: '/src/site.ts' } })],
388
+ })
389
+ ```
390
+
391
+ `src/site.ts` exports a `SiteModule`: what `SSR.generate` takes, plus where the
392
+ pages land. `config` may be one config or a function of the path (a site whose
393
+ Model is prepared per page returns its own); `paths` may be a thunk that seeds
394
+ and lists; `head` is the same `head`; and `sitemap`/`robots` write their files
395
+ from the generated pages. `files` is the host's layout — `'directory'`
396
+ (`/about` as `about/index.html`, the default) or `'flat'` (`about.html`, for a
397
+ host with clean addresses and no directory indexes):
398
+
399
+ ```ts
400
+ // src/site.ts
401
+ import type { SiteModule } from 'foldkit-ssr/vite'
402
+ export const site = {
403
+ origin: 'https://example.com',
404
+ paths: ['/', '/about'],
405
+ config: { Model, init, update, view, container: null, routing },
406
+ plan,
407
+ head: rendered => `<style>${Style.usedIn(rendered.html)}</style>`,
408
+ files: 'directory',
409
+ sitemap: true,
410
+ robots: true,
411
+ } satisfies SiteModule
412
+ ```
413
+
414
+ `generateStaticSite(site)` is the same build without Vite: it renders every
415
+ path and returns `{ pages, sitemap?, robots? }`. `fileFor(path, layout)` maps
416
+ one path to the file a host serves it from, so a caller writes the files
417
+ itself; `generateStaticSite` refuses two paths that would claim one file.
418
+
369
419
  ## Checking what the browser will read
370
420
 
371
421
  The view check sees what the first render shows. A Surface can read a field the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit-ssr",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Server rendering for Foldkit Plus: render once on the server, hand the Model over, and hydrate without rerunning init.",
5
5
  "keywords": [
6
6
  "foldkit",
@@ -47,27 +47,27 @@
47
47
  "LICENSE"
48
48
  ],
49
49
  "peerDependencies": {
50
- "effect": ">=4.0.0-rc.116 <4.0.0-rc.118",
51
- "foldkit": "^0.163.0"
50
+ "effect": "^4.0.0",
51
+ "foldkit": "^0.165.0"
52
52
  },
53
53
  "dependencies": {
54
- "foldkit-surface": "0.5.1"
54
+ "foldkit-surface": "0.6.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@effect/platform-browser": "4.0.0-rc.116",
57
+ "@effect/platform-browser": "4.0.0",
58
58
  "@types/jsdom": "21.1.7",
59
- "effect": "4.0.0-rc.116",
59
+ "effect": "4.0.0",
60
60
  "esbuild": "0.28.2",
61
- "foldkit": "0.163.0",
61
+ "foldkit": "0.165.0",
62
62
  "jsdom": "26.1.0",
63
63
  "playwright-core": "1.63.0",
64
64
  "tsdown": "^0.23.0",
65
65
  "typescript": "5.9.3",
66
66
  "vite": "5.4.21",
67
- "foldkit-bundle": "0.4.0",
68
- "foldkit-entity": "0.5.0",
69
- "foldkit-remote": "0.9.0",
70
- "foldkit-mirror": "0.4.0"
67
+ "foldkit-entity": "0.6.0",
68
+ "foldkit-bundle": "0.5.0",
69
+ "foldkit-mirror": "0.5.0",
70
+ "foldkit-remote": "0.10.0"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",