brustjs 0.1.6-alpha → 0.1.8-alpha
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 +3 -1
- package/package.json +7 -7
- package/runtime/cache.ts +18 -0
- package/runtime/cli/native-routes-emit.ts +6 -0
- package/runtime/cli/templates/minimal/pages/Home.tsx.tmpl +20 -5
- package/runtime/cli/templates/minimal/routes.tsx +7 -0
- package/runtime/dev/coordinator.ts +8 -0
- package/runtime/index.d.ts +13 -0
- package/runtime/index.js +56 -52
- package/runtime/index.ts +8 -0
- package/runtime/islands/__fixtures__/CountingIsland.tsx +10 -0
- package/runtime/islands/__fixtures__/render-counter.ts +5 -0
- package/runtime/islands/island.tsx +22 -0
- package/runtime/islands/native-render.ts +68 -7
- package/runtime/routes.ts +19 -1
package/README.md
CHANGED
|
@@ -80,13 +80,15 @@ brustjs new <name> # scaffold a project (partial — see Status)
|
|
|
80
80
|
|
|
81
81
|
- **React 19 SSR** via `renderToPipeableStream` (auto-Suspense → chunked streaming).
|
|
82
82
|
- **Islands** — opt-in client hydration with `<Island>`; the rest ships zero JS.
|
|
83
|
+
SSR islands can opt into **ISR caching** (`isr={{ key, tags, revalidate }}`) so
|
|
84
|
+
`renderToString` runs once per key, then serves a frozen pair from Rust.
|
|
83
85
|
- **`native: true` routes** — JSX compiled to a jinja template at build time and
|
|
84
86
|
rendered Rust-side (`minijinja`), skipping React on the server entirely.
|
|
85
87
|
- **Server actions** (`"use server"`) → per-action endpoints; client helper rewrites
|
|
86
88
|
form/`fetch` targets.
|
|
87
89
|
- **SSE & WebSockets** as first-class route shapes.
|
|
88
90
|
- Nested routes + dynamic params, per-route typed loaders, request-scoped middleware,
|
|
89
|
-
forms/multipart, SPA-style navigation, in-process LRU cache, Tailwind v4 + CSS Modules.
|
|
91
|
+
forms/multipart, SPA-style navigation, in-process LRU response cache + island ISR cache, Tailwind v4 + CSS Modules.
|
|
90
92
|
- **Agent-first** — server fns and routes expose MCP tool/resource schemas at
|
|
91
93
|
`/_brust/mcp` so agents drive the app without scraping.
|
|
92
94
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brustjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8-alpha",
|
|
4
4
|
"description": "Bun + Rust SSR framework — React on the server, Rust everywhere else (napi cdylib + per-worker SharedArrayBuffer).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"optionalDependencies": {
|
|
43
|
-
"brustjs-darwin-x64": "0.1.
|
|
44
|
-
"brustjs-darwin-arm64": "0.1.
|
|
45
|
-
"brustjs-linux-x64-gnu": "0.1.
|
|
46
|
-
"brustjs-linux-arm64-gnu": "0.1.
|
|
47
|
-
"brustjs-linux-x64-musl": "0.1.
|
|
48
|
-
"brustjs-linux-arm64-musl": "0.1.
|
|
43
|
+
"brustjs-darwin-x64": "0.1.8-alpha",
|
|
44
|
+
"brustjs-darwin-arm64": "0.1.8-alpha",
|
|
45
|
+
"brustjs-linux-x64-gnu": "0.1.8-alpha",
|
|
46
|
+
"brustjs-linux-arm64-gnu": "0.1.8-alpha",
|
|
47
|
+
"brustjs-linux-x64-musl": "0.1.8-alpha",
|
|
48
|
+
"brustjs-linux-arm64-musl": "0.1.8-alpha"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^19.2.6",
|
package/runtime/cache.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Dev-facing island ISR cache control. Invalidation crosses to the Rust-side
|
|
2
|
+
// store (shared across the worker pool) via NAPI. Call from action/api/loader.
|
|
3
|
+
import * as native from './index.js'
|
|
4
|
+
|
|
5
|
+
export interface InvalidateArgs {
|
|
6
|
+
key?: string
|
|
7
|
+
tags?: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const cache = {
|
|
11
|
+
/** Evict by exact key and/or by tag group. Both optional; both may be given.
|
|
12
|
+
* `invalidate({})` forwards `(undefined, undefined)` — a deliberate no-op on
|
|
13
|
+
* the Rust side (neither the key nor the tags branch fires). The `?.` guards
|
|
14
|
+
* against a stale addon built before this export existed (degrades to no-op). */
|
|
15
|
+
invalidate(args: InvalidateArgs): void {
|
|
16
|
+
;(native as any).islandCacheInvalidate?.(args.key, args.tags)
|
|
17
|
+
},
|
|
18
|
+
}
|
|
@@ -56,6 +56,12 @@ interface RawIslandEntry {
|
|
|
56
56
|
propsPath: string
|
|
57
57
|
ssr: boolean
|
|
58
58
|
hydrate: string
|
|
59
|
+
/** ISR cache fields (present only on islands with an `isr` attr). Declared so
|
|
60
|
+
* reconcile's `{ ...entry }` spread is type-complete — they MUST survive into
|
|
61
|
+
* the enriched manifest, or runtime ISR caching silently never activates. */
|
|
62
|
+
keyPath?: string
|
|
63
|
+
tagsPath?: string
|
|
64
|
+
revalidate?: number
|
|
59
65
|
}
|
|
60
66
|
interface EnrichedIslandEntry extends RawIslandEntry {
|
|
61
67
|
/** Absolute path to the island's client source, resolved from the page's
|
|
@@ -10,9 +10,13 @@ import Counter from '../components/Counter'
|
|
|
10
10
|
export default function Home({
|
|
11
11
|
clientProps,
|
|
12
12
|
serverProps,
|
|
13
|
+
cacheKey,
|
|
14
|
+
cacheTags,
|
|
13
15
|
}: {
|
|
14
16
|
clientProps: { start: number; label: string }
|
|
15
17
|
serverProps: { start: number; label: string }
|
|
18
|
+
cacheKey: string
|
|
19
|
+
cacheTags: string[]
|
|
16
20
|
}) {
|
|
17
21
|
return (
|
|
18
22
|
<BrustPage lang="en" className="dark" bodyClassName="brust-body" title="__PROJECT_NAME__">
|
|
@@ -49,18 +53,29 @@ export default function Home({
|
|
|
49
53
|
</div>
|
|
50
54
|
</section>
|
|
51
55
|
|
|
52
|
-
{/* Server island —
|
|
56
|
+
{/* Server island — ISR-cached: renderToString runs ONCE per `key`,
|
|
57
|
+
then every request serves the frozen markup from the Rust-side
|
|
58
|
+
cache (no re-render). `key`/`tags` come from the loader; invalidate
|
|
59
|
+
from server code with `import { cache } from 'brustjs'` →
|
|
60
|
+
`cache.invalidate({ tags: ['home'] })`. Drop the `isr` prop to
|
|
61
|
+
render on every request instead. */}
|
|
53
62
|
<section className="island-card island-card-server">
|
|
54
63
|
<div className="island-header">
|
|
55
|
-
<span className="island-badge island-badge-server">SSR +
|
|
64
|
+
<span className="island-badge island-badge-server">SSR + ISR</span>
|
|
56
65
|
<h2 className="island-title">Server Island</h2>
|
|
57
66
|
</div>
|
|
58
67
|
<p className="island-desc">
|
|
59
|
-
Rendered to string in the Bun worker
|
|
60
|
-
layout shift.
|
|
68
|
+
Rendered to string in the Bun worker, then cached (ISR) and hydrated — rendered once
|
|
69
|
+
per key, no layout shift.
|
|
61
70
|
</p>
|
|
62
71
|
<div className="island-mount-point">
|
|
63
|
-
<Island
|
|
72
|
+
<Island
|
|
73
|
+
component={Counter}
|
|
74
|
+
props={serverProps}
|
|
75
|
+
ssr
|
|
76
|
+
hydrate="load"
|
|
77
|
+
isr={{ key: cacheKey, tags: cacheTags }}
|
|
78
|
+
/>
|
|
64
79
|
</div>
|
|
65
80
|
</section>
|
|
66
81
|
</div>
|
|
@@ -5,6 +5,11 @@ export const routes = defineRoutes([
|
|
|
5
5
|
// `native: true` — Home is compiled to a jinja template and rendered in Rust
|
|
6
6
|
// (no React on the server). The loader's return value is the template
|
|
7
7
|
// context; each island's `props` is a path into it.
|
|
8
|
+
//
|
|
9
|
+
// `cacheKey`/`cacheTags` feed the server island's `isr` cache: with a stable
|
|
10
|
+
// key its renderToString runs once and later requests serve the frozen markup
|
|
11
|
+
// from Rust. In a real app derive the key from the data the island depends on
|
|
12
|
+
// (e.g. `product:${id}`) and invalidate by tag when that data changes.
|
|
8
13
|
{
|
|
9
14
|
path: '/',
|
|
10
15
|
Component: Home,
|
|
@@ -12,6 +17,8 @@ export const routes = defineRoutes([
|
|
|
12
17
|
loader: async () => ({
|
|
13
18
|
clientProps: { start: 0, label: 'client clicks' },
|
|
14
19
|
serverProps: { start: 100, label: 'server clicks' },
|
|
20
|
+
cacheKey: 'home:server-island',
|
|
21
|
+
cacheTags: ['home'],
|
|
15
22
|
}),
|
|
16
23
|
},
|
|
17
24
|
] as const)
|
|
@@ -11,6 +11,11 @@ export interface CoordinatorDeps {
|
|
|
11
11
|
/** Recompile native-route `.jinja` templates from source and reload them into
|
|
12
12
|
* the minijinja env, so `native: true` routes pick up .tsx edits on reload. */
|
|
13
13
|
reEmitJinja: () => Promise<void>
|
|
14
|
+
/** Clear the Rust-side island ISR cache. Called on every render-affecting
|
|
15
|
+
* reload (`ts`/`html`/`islands`) so a `.tsx` edit is reflected immediately —
|
|
16
|
+
* a frozen island render from before the edit must never survive a hot reload.
|
|
17
|
+
* Optional: a build without the island-cache addon export omits it. */
|
|
18
|
+
clearIslandCache?: () => void
|
|
14
19
|
buildComponentCss?: () => Promise<void>
|
|
15
20
|
snapshotComponentCss?: () => Promise<import('../css/manifest.ts').ComponentCssManifest | null>
|
|
16
21
|
broadcast: (msg: DevMessage) => Promise<void> | void
|
|
@@ -34,6 +39,8 @@ export class Coordinator {
|
|
|
34
39
|
switch (ev.kind) {
|
|
35
40
|
case 'ts':
|
|
36
41
|
case 'html':
|
|
42
|
+
// Stale frozen island renders must not survive a source edit.
|
|
43
|
+
this.deps.clearIslandCache?.()
|
|
37
44
|
await this.deps.workers.terminateAll()
|
|
38
45
|
await this.deps.workers.spawnAll()
|
|
39
46
|
// Reload native-route templates (process-global minijinja env — does
|
|
@@ -42,6 +49,7 @@ export class Coordinator {
|
|
|
42
49
|
await this.deps.broadcast({ type: 'reload' })
|
|
43
50
|
break
|
|
44
51
|
case 'islands':
|
|
52
|
+
this.deps.clearIslandCache?.()
|
|
45
53
|
await this.deps.buildIslands()
|
|
46
54
|
await this.deps.workers.terminateAll()
|
|
47
55
|
await this.deps.workers.spawnAll()
|
package/runtime/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export declare function beginServe(opts: ServeOptions): NapiResult<undefined>
|
|
4
4
|
|
|
5
|
+
export interface CachedIslandJs {
|
|
6
|
+
html: string
|
|
7
|
+
props: string
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Compile a single native-route source to its jinja template + island
|
|
7
12
|
* manifest. `path` is used only in error messages. Mirrors `jsx-rustc`'s
|
|
@@ -16,6 +21,14 @@ export declare function configureCssDir(path: string): NapiResult<undefined>
|
|
|
16
21
|
|
|
17
22
|
export declare function configureIslandsDir(path: string): NapiResult<undefined>
|
|
18
23
|
|
|
24
|
+
export declare function islandCacheClear(): void
|
|
25
|
+
|
|
26
|
+
export declare function islandCacheGet(key: string): CachedIslandJs | null
|
|
27
|
+
|
|
28
|
+
export declare function islandCacheInvalidate(key?: string | undefined | null, tags?: Array<string> | undefined | null): void
|
|
29
|
+
|
|
30
|
+
export declare function islandCacheSet(key: string, tags: Array<string>, ttlMs: number | undefined | null, html: string, props: string): void
|
|
31
|
+
|
|
19
32
|
export declare function isWorker(): boolean
|
|
20
33
|
|
|
21
34
|
/** Result of compiling one `pages/<Name>.tsx` source. */
|
package/runtime/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('brustjs-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('brustjs-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.1.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
80
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('brustjs-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('brustjs-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.1.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
96
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('brustjs-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('brustjs-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.1.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
117
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('brustjs-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('brustjs-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.1.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
133
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('brustjs-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('brustjs-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.1.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
150
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('brustjs-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('brustjs-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.1.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
166
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('brustjs-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('brustjs-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.1.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
185
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('brustjs-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('brustjs-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.1.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
201
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('brustjs-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('brustjs-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.1.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
217
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('brustjs-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('brustjs-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.1.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
237
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('brustjs-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('brustjs-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.1.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
253
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('brustjs-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('brustjs-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.1.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
274
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('brustjs-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('brustjs-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.1.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
290
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('brustjs-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('brustjs-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.1.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
308
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('brustjs-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('brustjs-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.1.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
324
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('brustjs-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('brustjs-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.1.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
342
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('brustjs-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('brustjs-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.1.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
358
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('brustjs-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('brustjs-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.1.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
376
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('brustjs-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('brustjs-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.1.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
392
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('brustjs-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('brustjs-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.1.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
410
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('brustjs-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('brustjs-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.1.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
426
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('brustjs-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('brustjs-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.1.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
443
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('brustjs-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('brustjs-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.1.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
459
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('brustjs-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('brustjs-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.1.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
479
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('brustjs-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('brustjs-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.1.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
495
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('brustjs-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('brustjs-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.1.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
511
|
+
if (bindingPackageVersion !== '0.1.8-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -581,6 +581,10 @@ module.exports.compileJsx = nativeBinding.compileJsx
|
|
|
581
581
|
module.exports.configureCache = nativeBinding.configureCache
|
|
582
582
|
module.exports.configureCssDir = nativeBinding.configureCssDir
|
|
583
583
|
module.exports.configureIslandsDir = nativeBinding.configureIslandsDir
|
|
584
|
+
module.exports.islandCacheClear = nativeBinding.islandCacheClear
|
|
585
|
+
module.exports.islandCacheGet = nativeBinding.islandCacheGet
|
|
586
|
+
module.exports.islandCacheInvalidate = nativeBinding.islandCacheInvalidate
|
|
587
|
+
module.exports.islandCacheSet = nativeBinding.islandCacheSet
|
|
584
588
|
module.exports.isWorker = nativeBinding.isWorker
|
|
585
589
|
module.exports.napiDevBroadcast = nativeBinding.napiDevBroadcast
|
|
586
590
|
module.exports.napiListNativeTemplates = nativeBinding.napiListNativeTemplates
|
package/runtime/index.ts
CHANGED
|
@@ -488,6 +488,11 @@ export const brust = {
|
|
|
488
488
|
},
|
|
489
489
|
},
|
|
490
490
|
reEmitJinja,
|
|
491
|
+
// Wipe the Rust-side island ISR cache on every render-affecting reload
|
|
492
|
+
// so a frozen island render never survives a `.tsx` edit in dev.
|
|
493
|
+
clearIslandCache: () => {
|
|
494
|
+
;(native as any).islandCacheClear?.()
|
|
495
|
+
},
|
|
491
496
|
buildCss: async () => {
|
|
492
497
|
const appCss = pathModule.join(scanRoot, 'app.css')
|
|
493
498
|
if (fsModule.existsSync(appCss)) {
|
|
@@ -679,3 +684,6 @@ export type { BrustPageProps } from './islands/brust-page.tsx'
|
|
|
679
684
|
|
|
680
685
|
export { buildIslands } from './islands/build.ts'
|
|
681
686
|
export type { IslandsBuildResult, BuildIslandsOptions } from './islands/build.ts'
|
|
687
|
+
|
|
688
|
+
export { cache } from './cache.ts'
|
|
689
|
+
export type { InvalidateArgs } from './cache.ts'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Test fixture: an SSR island that bumps a shared counter on every render, so
|
|
2
|
+
// the ISR integration test can prove a cache HIT skipped renderToString. Markup
|
|
3
|
+
// embeds `n` (same shape as StubIsland) so the served html is assertable.
|
|
4
|
+
import { createElement } from 'react'
|
|
5
|
+
import { renderCounter } from './render-counter.ts'
|
|
6
|
+
|
|
7
|
+
export default ({ n }: { n: number }) => {
|
|
8
|
+
renderCounter.count++
|
|
9
|
+
return createElement('span', null, String(n))
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Shared render counter for the ISR integration test. The CountingIsland
|
|
2
|
+
// fixture increments `count` each time it server-renders; the test imports this
|
|
3
|
+
// SAME module (Bun module cache makes it a singleton) to assert how many times
|
|
4
|
+
// renderToString actually ran — i.e. whether the ISR cache served a hit.
|
|
5
|
+
export const renderCounter = { count: 0 }
|
|
@@ -20,6 +20,28 @@ export interface IslandProps<P> {
|
|
|
20
20
|
* the loader crossing) so its markup ships in the HTML, then hydrate. Ignored
|
|
21
21
|
* on the React path (the whole tree already SSRs there). Default false. */
|
|
22
22
|
ssr?: boolean
|
|
23
|
+
/**
|
|
24
|
+
* Optional ISR (incremental static regeneration) cache for an `ssr` island on
|
|
25
|
+
* a native-jinja route. When present, the island's `renderToString` runs ONCE
|
|
26
|
+
* per `key`; later requests serve the frozen markup from the Rust-side cache.
|
|
27
|
+
* Ignored unless `ssr` is set (caching a client-only island is meaningless).
|
|
28
|
+
*
|
|
29
|
+
* - `key` (required): unique string identifying this cache entry. A different
|
|
30
|
+
* key is a different cached render. Compute it in the loader and pass it
|
|
31
|
+
* through, e.g. `isr={{ key: data.cacheKey }}`.
|
|
32
|
+
* - `tags` (optional): groups for bulk invalidation —
|
|
33
|
+
* `import { cache } from 'brustjs'; cache.invalidate({ tags: ['blog'] })`
|
|
34
|
+
* evicts every entry carrying that tag. `cache.invalidate({ key })` evicts one.
|
|
35
|
+
* - `revalidate` (optional): TTL in **seconds** (integer). Omit to cache until
|
|
36
|
+
* explicitly invalidated.
|
|
37
|
+
*
|
|
38
|
+
* Example: `isr={{ key: data.cacheKey, tags: ['blog'], revalidate: 60 }}`
|
|
39
|
+
*/
|
|
40
|
+
isr?: {
|
|
41
|
+
key: string
|
|
42
|
+
tags?: string[]
|
|
43
|
+
revalidate?: number
|
|
44
|
+
}
|
|
23
45
|
}
|
|
24
46
|
|
|
25
47
|
/** Module-scope flag flipped by every `<Island>` render. `makeRenderer`
|
|
@@ -28,6 +28,21 @@ export interface NativeIslandEntry {
|
|
|
28
28
|
ssr: boolean
|
|
29
29
|
hydrate: string
|
|
30
30
|
sourcePath: string
|
|
31
|
+
/** Dotted path into loader data yielding the ISR cache key (string). */
|
|
32
|
+
keyPath?: string
|
|
33
|
+
/** Dotted path into loader data yielding the ISR cache tags (string[]). */
|
|
34
|
+
tagsPath?: string
|
|
35
|
+
/** Revalidate window in SECONDS; converted to ttlMs on cache.set. */
|
|
36
|
+
revalidate?: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Rust-side ISR cache, injected as a port for testability. A `get` hit
|
|
40
|
+
* returns a FROZEN {html,props} pair (the props are the entity-encoded attr
|
|
41
|
+
* string, identical to what was stored) so the served markup and the hydrated
|
|
42
|
+
* props stay byte-identical regardless of live loader-data mutation. */
|
|
43
|
+
export interface IslandCache {
|
|
44
|
+
get(key: string): { html: string; props: string } | null
|
|
45
|
+
set(key: string, tags: string[], ttlMs: number | undefined, html: string, props: string): void
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
/** Walk a dotted path into `data`. Each segment must be an OWN enumerable
|
|
@@ -109,17 +124,42 @@ const componentCache = new Map<string, unknown>()
|
|
|
109
124
|
export async function resolveIslandContext(
|
|
110
125
|
manifest: NativeIslandEntry[],
|
|
111
126
|
data: unknown,
|
|
127
|
+
cache?: IslandCache,
|
|
112
128
|
): Promise<Record<string, string>> {
|
|
113
129
|
const out: Record<string, string> = {}
|
|
114
130
|
for (const entry of manifest) {
|
|
115
131
|
const props = pathInto(data, entry.propsPath)
|
|
116
132
|
// `?? null` handles undefined props; the `?? 'null'` belt-and-braces covers
|
|
117
133
|
// the case where JSON.stringify itself returns undefined (e.g. a function
|
|
118
|
-
// value), so entityEncode never receives undefined.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
134
|
+
// value), so entityEncode never receives undefined. Hoisted ABOVE the ssr
|
|
135
|
+
// branch so the SAME attr string is stored in (and served from) the cache
|
|
136
|
+
// AND hydrated against — byte-identity is the ISR hydration-safety invariant.
|
|
137
|
+
const propsAttr = entityEncode(JSON.stringify(props ?? null) ?? 'null')
|
|
138
|
+
out['island_' + entry.instance + '_props'] = propsAttr
|
|
122
139
|
if (!entry.ssr) continue
|
|
140
|
+
|
|
141
|
+
// ISR fast-path: resolve a string cache key out of loader data. A hit
|
|
142
|
+
// serves the FROZEN {html,props} pair (overwriting the live _props with the
|
|
143
|
+
// stored one) and skips render. A non-string-but-defined key is a manifest
|
|
144
|
+
// bug — warn and fall through to an uncached render.
|
|
145
|
+
let key: string | undefined
|
|
146
|
+
if (cache && entry.keyPath) {
|
|
147
|
+
const k = pathInto(data, entry.keyPath)
|
|
148
|
+
if (typeof k === 'string') {
|
|
149
|
+
key = k
|
|
150
|
+
const hit = cache.get(key)
|
|
151
|
+
if (hit) {
|
|
152
|
+
out['island_' + entry.instance + '_html'] = hit.html
|
|
153
|
+
out['island_' + entry.instance + '_props'] = hit.props
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
} else if (k !== undefined) {
|
|
157
|
+
console.warn(
|
|
158
|
+
`[brust] ssr island "${entry.component}" ISR keyPath "${entry.keyPath}" resolved to a non-string value; rendering uncached`,
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
123
163
|
try {
|
|
124
164
|
let Component = componentCache.get(entry.sourcePath)
|
|
125
165
|
if (Component === undefined) {
|
|
@@ -134,9 +174,30 @@ export async function resolveIslandContext(
|
|
|
134
174
|
// JSON.parse(data-brust-props) — byte-identity guarantees no hydration
|
|
135
175
|
// mismatch. props ?? undefined: pass the actual value (or undefined) to
|
|
136
176
|
// the component, NOT the `null` sentinel used for the props string.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
177
|
+
const html = renderToString(createElement(Component as any, (props ?? undefined) as any))
|
|
178
|
+
out['island_' + entry.instance + '_html'] = html
|
|
179
|
+
// Write-through: only on the SUCCESS path (a throwing render must not
|
|
180
|
+
// poison the cache). Store the SAME entity-encoded propsAttr so a later
|
|
181
|
+
// hit hydrates byte-identically.
|
|
182
|
+
if (cache && key) {
|
|
183
|
+
// Resolve tags only when tagsPath is set (avoids pathInto('') returning
|
|
184
|
+
// the whole loader object). Must be a string[] — the value crosses to
|
|
185
|
+
// Rust as Vec<String>, so a non-array OR an array with a non-string
|
|
186
|
+
// element degrades to no tags + a warning, never a bad NAPI payload.
|
|
187
|
+
let tags: string[] = []
|
|
188
|
+
if (entry.tagsPath !== undefined) {
|
|
189
|
+
const tagsValue = pathInto(data, entry.tagsPath)
|
|
190
|
+
if (Array.isArray(tagsValue) && tagsValue.every((t) => typeof t === 'string')) {
|
|
191
|
+
tags = tagsValue
|
|
192
|
+
} else if (tagsValue !== undefined) {
|
|
193
|
+
console.warn(
|
|
194
|
+
`[brust] ssr island "${entry.component}" ISR tagsPath "${entry.tagsPath}" must resolve to a string[]; using no tags`,
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const ttlMs = entry.revalidate !== undefined ? entry.revalidate * 1000 : undefined
|
|
199
|
+
cache.set(key, tags, ttlMs, html, propsAttr)
|
|
200
|
+
}
|
|
140
201
|
} catch (e) {
|
|
141
202
|
// CONTAINED FAILURE (spec invariant): a throwing ssr island degrades to
|
|
142
203
|
// an empty mount (no _html) + logged warning, rather than 500-ing the
|
package/runtime/routes.ts
CHANGED
|
@@ -12,8 +12,26 @@ import { Buffer } from 'node:buffer'
|
|
|
12
12
|
import * as native from './index.js'
|
|
13
13
|
import { renderBranchStreaming } from './render/stream.ts'
|
|
14
14
|
import { loadIslandManifest, resolveIslandContext } from './islands/native-render.ts'
|
|
15
|
+
import type { IslandCache } from './islands/native-render.ts'
|
|
15
16
|
import type { ActionDef } from './actions.ts'
|
|
16
17
|
|
|
18
|
+
// Sub-project J — island ISR cache, backed by the Rust-side store (shared across
|
|
19
|
+
// the worker pool) via NAPI. napi-rs maps snake→camel: island_cache_get →
|
|
20
|
+
// islandCacheGet, island_cache_set → islandCacheSet. `as any` avoids depending on
|
|
21
|
+
// the regenerated .d.ts — the addon isn't rebuilt locally; index.js/*.node are
|
|
22
|
+
// gitignored and CI rebuilds. Optional-chaining (`?.`) means a STALE addon (built
|
|
23
|
+
// before these exports existed) degrades gracefully: get → undefined → null (a
|
|
24
|
+
// cache miss → normal render), set → no-op. Caching is an enhancement, never a
|
|
25
|
+
// hard dependency — unlike napiRenderJinja which has no fallback.
|
|
26
|
+
const islandCache: IslandCache = {
|
|
27
|
+
get(key) {
|
|
28
|
+
return (native as any).islandCacheGet?.(key) ?? null
|
|
29
|
+
},
|
|
30
|
+
set(key, tags, ttlMs, html, props) {
|
|
31
|
+
;(native as any).islandCacheSet?.(key, tags, ttlMs, html, props)
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
// Permanently-unaborted AbortSignal sentinel for non-SSE routes.
|
|
18
36
|
// The controller is held in module scope and never .abort()-ed, keeping
|
|
19
37
|
// the signal alive in the unaborted state. Do NOT use AbortSignal.abort()
|
|
@@ -595,7 +613,7 @@ export function makeRenderer(
|
|
|
595
613
|
const manifest = loadIslandManifest(flat.nativeTemplate)
|
|
596
614
|
if (manifest && manifest.length > 0) {
|
|
597
615
|
const rt = JSON.parse(json) // roundtrip ONCE; props read from rt
|
|
598
|
-
const extra = await resolveIslandContext(manifest, rt)
|
|
616
|
+
const extra = await resolveIslandContext(manifest, rt, islandCache)
|
|
599
617
|
const ctx = { ...rt, ...extra }
|
|
600
618
|
const finalBytes = encoder.encode(JSON.stringify(ctx))
|
|
601
619
|
// The original size check guarded the pre-island bytes; the merged
|