brustjs 0.1.19-alpha → 0.1.21-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/example/pokedex/components/AddToTeamButton.tsx +11 -8
- package/example/pokedex/components/PageLayout.tsx +6 -1
- package/example/pokedex/components/TeamBuilder.tsx +20 -10
- package/example/pokedex/stores/team.ts +14 -0
- package/package.json +9 -8
- package/runtime/cli/templates/minimal/pages/Home.tsx.tmpl +7 -1
- package/runtime/client/index.ts +6 -0
- package/runtime/index.js +52 -52
- package/runtime/index.ts +9 -1
- package/runtime/islands/bootstrap.ts +7 -1
- package/runtime/islands/brust-page.tsx +44 -0
- package/runtime/render/inject-store.ts +63 -0
- package/runtime/render/stream.ts +14 -2
- package/runtime/routes.ts +66 -38
- package/runtime/store/client-hydrate.ts +16 -0
- package/runtime/store/define-store.ts +179 -0
- package/runtime/store/index.ts +8 -0
- package/runtime/store/react.ts +23 -0
- package/runtime/store/serialize.ts +32 -0
- package/runtime/store/server-context.ts +43 -0
- package/runtime/store/signal.ts +152 -0
- package/example/pokedex/components/team-bus.ts +0 -25
|
@@ -4,23 +4,26 @@
|
|
|
4
4
|
// so unlike the native page shells they have NO jinja constraints: hooks, inline
|
|
5
5
|
// `style={{…}}`, event handlers all work normally.
|
|
6
6
|
import { useEffect, useState } from 'react'
|
|
7
|
-
import { client } from 'brustjs/client'
|
|
7
|
+
import { client, useStore } from 'brustjs/client'
|
|
8
8
|
import type { Actions } from '../actions'
|
|
9
|
-
import type { AddToTeamProps
|
|
10
|
-
import {
|
|
9
|
+
import type { AddToTeamProps } from '../lib/types'
|
|
10
|
+
import { teamStore } from '../stores/team'
|
|
11
11
|
|
|
12
12
|
const api = client<Actions>()
|
|
13
13
|
|
|
14
14
|
export default function AddToTeamButton(p: AddToTeamProps) {
|
|
15
|
-
|
|
15
|
+
// Shared store (GAP S4): writing teamStore.members here is observed by the
|
|
16
|
+
// TeamBuilder island — they resolve the same window singleton. This is a
|
|
17
|
+
// client-only island (no `ssr`), so the store read always hits the client branch.
|
|
18
|
+
const { members } = useStore(teamStore)
|
|
19
|
+
const team = members ?? []
|
|
16
20
|
const [busy, setBusy] = useState(false)
|
|
17
21
|
const [toast, setToast] = useState<string | null>(null)
|
|
18
22
|
|
|
19
23
|
useEffect(() => {
|
|
20
24
|
api.team.get().then((r) => {
|
|
21
|
-
if (r.data)
|
|
25
|
+
if (r.data) teamStore.members.set(r.data.team)
|
|
22
26
|
})
|
|
23
|
-
return onTeam(setTeam)
|
|
24
27
|
}, [])
|
|
25
28
|
|
|
26
29
|
const inTeam = team.some((m) => m.id === p.id)
|
|
@@ -33,7 +36,7 @@ export default function AddToTeamButton(p: AddToTeamProps) {
|
|
|
33
36
|
// DELETE from the browser sends no Content-Length, and brust's action
|
|
34
37
|
// dispatch returns 411 on non-GET/HEAD without one. See GAPS S12.
|
|
35
38
|
const { data } = await api.team({ id: p.id }).delete({})
|
|
36
|
-
if (data)
|
|
39
|
+
if (data) teamStore.members.set(data.team)
|
|
37
40
|
} else {
|
|
38
41
|
const { data } = await api.team.post({
|
|
39
42
|
id: p.id,
|
|
@@ -47,7 +50,7 @@ export default function AddToTeamButton(p: AddToTeamProps) {
|
|
|
47
50
|
setToast('ทีมเต็มแล้ว · สูงสุด 6 ตัว')
|
|
48
51
|
setTimeout(() => setToast(null), 2200)
|
|
49
52
|
} else if (data) {
|
|
50
|
-
|
|
53
|
+
teamStore.members.set(data.team)
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
} finally {
|
|
@@ -26,7 +26,12 @@ export default function PageLayout({
|
|
|
26
26
|
children: ReactNode
|
|
27
27
|
}) {
|
|
28
28
|
return (
|
|
29
|
-
<BrustPage
|
|
29
|
+
<BrustPage
|
|
30
|
+
lang="en"
|
|
31
|
+
className="dark"
|
|
32
|
+
title={title}
|
|
33
|
+
head={[{ tag: 'link', rel: 'icon', href: '/favicon.svg' }]}
|
|
34
|
+
>
|
|
30
35
|
<div className="aa-app">
|
|
31
36
|
<aside className="aa-sidebar">
|
|
32
37
|
<div className="aa-sidebar__brand">
|
|
@@ -2,33 +2,43 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Rendered with `ssr` so the initial team (from the loader) ships in the HTML
|
|
4
4
|
// and the dock count is correct on first paint, then hydrates. Stays in sync
|
|
5
|
-
// with AddToTeamButton through the
|
|
5
|
+
// with AddToTeamButton through the shared `teamStore` (one window singleton — see
|
|
6
|
+
// ../stores/team.ts / GAPS S4; replaced the old window-event bus).
|
|
6
7
|
import { useEffect, useState } from 'react'
|
|
7
|
-
import { client } from 'brustjs/client'
|
|
8
|
+
import { client, useStore } from 'brustjs/client'
|
|
8
9
|
import type { Actions } from '../actions'
|
|
9
10
|
import type { TeamMember } from '../lib/types'
|
|
10
|
-
import {
|
|
11
|
+
import { teamStore } from '../stores/team'
|
|
11
12
|
|
|
12
13
|
const api = client<Actions>()
|
|
13
14
|
const MAX = 6
|
|
14
15
|
|
|
15
16
|
export default function TeamBuilder({ teamInitial }: { teamInitial: TeamMember[] }) {
|
|
16
|
-
|
|
17
|
+
// Shared store (GAP S4): in sync with AddToTeamButton via one window singleton.
|
|
18
|
+
const { members } = useStore(teamStore)
|
|
19
|
+
const [mounted, setMounted] = useState(false)
|
|
17
20
|
const [open, setOpen] = useState(false)
|
|
18
21
|
|
|
22
|
+
// This island is `ssr`, but Spec A does not server-seed native client state, so
|
|
23
|
+
// the store is empty during SSR. Drive the first render (server + client) from
|
|
24
|
+
// the `teamInitial` prop so the dock count is correct on first paint AND the
|
|
25
|
+
// hydration markup matches; switch to the live store once mounted. (Full
|
|
26
|
+
// server-seeded native snapshot is Spec B.)
|
|
27
|
+
const team = mounted ? (members ?? []) : (teamInitial ?? [])
|
|
28
|
+
|
|
19
29
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
if (teamInitial?.length) teamStore.members.set(teamInitial)
|
|
31
|
+
setMounted(true)
|
|
32
|
+
// Re-sync from the server on mount (the SSR snapshot may be stale by now).
|
|
22
33
|
api.team.get().then((r) => {
|
|
23
|
-
if (r.data)
|
|
34
|
+
if (r.data) teamStore.members.set(r.data.team)
|
|
24
35
|
})
|
|
25
|
-
|
|
26
|
-
}, [])
|
|
36
|
+
}, [teamInitial])
|
|
27
37
|
|
|
28
38
|
async function remove(id: number) {
|
|
29
39
|
// `.delete({})` — empty body is required (bodyless DELETE → 411). See GAPS S12.
|
|
30
40
|
const { data } = await api.team({ id }).delete({})
|
|
31
|
-
if (data)
|
|
41
|
+
if (data) teamStore.members.set(data.team)
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
const coverage = [...new Set(team.flatMap((m) => m.types))]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Shared team store — GAP S4 dogfood.
|
|
2
|
+
//
|
|
3
|
+
// AddToTeamButton and TeamBuilder are two SEPARATE island bundles. A plain
|
|
4
|
+
// module-scope store imported by both would be duplicated into two instances
|
|
5
|
+
// that never sync. `defineStore` resolves both bundles to ONE instance on
|
|
6
|
+
// `window.__BRUST_STORES__['pokedex.team']`, so a write in one island is seen by
|
|
7
|
+
// the other — no hand-rolled CustomEvent bus. (Replaces the old components/team-bus.ts.)
|
|
8
|
+
import { defineStore, signal } from 'brustjs/store'
|
|
9
|
+
import type { TeamMember } from '../lib/types'
|
|
10
|
+
|
|
11
|
+
export const teamStore = defineStore('pokedex.team', () => {
|
|
12
|
+
const members = signal<TeamMember[]>([])
|
|
13
|
+
return { members }
|
|
14
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brustjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21-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.21-alpha",
|
|
44
|
+
"brustjs-darwin-arm64": "0.1.21-alpha",
|
|
45
|
+
"brustjs-linux-x64-gnu": "0.1.21-alpha",
|
|
46
|
+
"brustjs-linux-arm64-gnu": "0.1.21-alpha",
|
|
47
|
+
"brustjs-linux-x64-musl": "0.1.21-alpha",
|
|
48
|
+
"brustjs-linux-arm64-musl": "0.1.21-alpha"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^19.2.6",
|
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
".": "./runtime/index.ts",
|
|
68
68
|
"./routes": "./runtime/routes.ts",
|
|
69
69
|
"./client": "./runtime/client/index.ts",
|
|
70
|
-
"./create": "./runtime/create.ts"
|
|
70
|
+
"./create": "./runtime/create.ts",
|
|
71
|
+
"./store": "./runtime/store/index.ts"
|
|
71
72
|
},
|
|
72
73
|
"files": [
|
|
73
74
|
"runtime",
|
|
@@ -19,7 +19,13 @@ export default function Home({
|
|
|
19
19
|
cacheTags: string[]
|
|
20
20
|
}) {
|
|
21
21
|
return (
|
|
22
|
-
<BrustPage
|
|
22
|
+
<BrustPage
|
|
23
|
+
lang="en"
|
|
24
|
+
className="dark"
|
|
25
|
+
bodyClassName="brust-body"
|
|
26
|
+
title="__PROJECT_NAME__"
|
|
27
|
+
head={[{ tag: 'link', rel: 'icon', href: '/favicon.svg' }]}
|
|
28
|
+
>
|
|
23
29
|
{/* Background decorative glows */}
|
|
24
30
|
<div className="fixed top-[-20%] left-[-10%] w-[50%] h-[50%] bg-purple-600/10 rounded-full blur-[120px] pointer-events-none"></div>
|
|
25
31
|
<div className="fixed bottom-[-20%] right-[-10%] w-[50%] h-[50%] bg-teal-600/10 rounded-full blur-[120px] pointer-events-none"></div>
|
package/runtime/client/index.ts
CHANGED
|
@@ -20,3 +20,9 @@ export class BrustActionError extends Error {
|
|
|
20
20
|
|
|
21
21
|
export { client } from '../treaty.ts'
|
|
22
22
|
export type { TreatyResponse, ClientOptions } from '../treaty.ts'
|
|
23
|
+
|
|
24
|
+
// Store view-layer adapter for islands. Lives here (the browser/island entry),
|
|
25
|
+
// NOT in the brustjs main entry — that pulls the native addon + server-only
|
|
26
|
+
// surface and cannot be bundled for the browser. react.ts → define-store.ts is
|
|
27
|
+
// browser-safe (no node:async_hooks; the server resolver is injected separately).
|
|
28
|
+
export { useStore } from '../store/react.ts'
|
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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-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.21-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
package/runtime/index.ts
CHANGED
|
@@ -745,7 +745,15 @@ import './islands/isr-jsx.ts'
|
|
|
745
745
|
export type { IsrConfig } from './islands/isr-jsx.ts'
|
|
746
746
|
|
|
747
747
|
export { BrustPage } from './islands/brust-page.tsx'
|
|
748
|
-
export type { BrustPageProps } from './islands/brust-page.tsx'
|
|
748
|
+
export type { BrustPageProps, HeadEntry } from './islands/brust-page.tsx'
|
|
749
|
+
|
|
750
|
+
// Store reactive primitives (isomorphic, server-safe). The React adapter
|
|
751
|
+
// `useStore` is intentionally NOT exported here — it ships from `brustjs/client`
|
|
752
|
+
// because islands (the only React in the browser) bundle for the browser and
|
|
753
|
+
// cannot pull this server entry (native addon + react-dom/server). See
|
|
754
|
+
// runtime/client/index.ts.
|
|
755
|
+
export { defineStore, signal, computed, effect, batch } from './store/index.ts'
|
|
756
|
+
export type { StoreHandle, Snapshot, Signal, Computed } from './store/index.ts'
|
|
749
757
|
|
|
750
758
|
export { buildIslands } from './islands/build.ts'
|
|
751
759
|
export type { IslandsBuildResult, BuildIslandsOptions } from './islands/build.ts'
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { createRoot, hydrateRoot, type Root } from 'react-dom/client'
|
|
17
17
|
import { createElement } from 'react'
|
|
18
|
+
import { applyStoreSnapshot } from '../store/client-hydrate.ts'
|
|
18
19
|
|
|
19
20
|
// Track React roots created by hydrateOne so we can unmount them before
|
|
20
21
|
// removing their DOM in swapMainContent. Without this, removing the DOM
|
|
@@ -214,11 +215,16 @@ async function navigate(url: URL, push: boolean): Promise<void> {
|
|
|
214
215
|
headers: { Accept: 'application/json' },
|
|
215
216
|
})
|
|
216
217
|
if (!resp.ok) throw new Error(`navigation: status ${resp.status}`)
|
|
217
|
-
const { html, title } = (await resp.json()) as {
|
|
218
|
+
const { html, title, store } = (await resp.json()) as {
|
|
219
|
+
html: string
|
|
220
|
+
title: string
|
|
221
|
+
store?: Record<string, Record<string, unknown>>
|
|
222
|
+
}
|
|
218
223
|
const main = document.querySelector('main')
|
|
219
224
|
if (!main) throw new Error('navigation: no <main> element')
|
|
220
225
|
unmountIslandsIn(main as HTMLElement)
|
|
221
226
|
swapMainContent(main as HTMLElement, html)
|
|
227
|
+
if (store) applyStoreSnapshot(store)
|
|
222
228
|
if (title) document.title = title
|
|
223
229
|
if (push) history.pushState({}, '', url.href)
|
|
224
230
|
window.scrollTo(0, 0)
|
|
@@ -14,6 +14,35 @@ import { createElement, type ReactNode } from 'react'
|
|
|
14
14
|
* loader member-path (`title={data.title}`), interpolated into the Rust-rendered
|
|
15
15
|
* shell as `{{ path }}` (S8). Calls/arithmetic are still rejected. This React
|
|
16
16
|
* implementation mirrors the compiled output for the rare non-native use. */
|
|
17
|
+
/** One extra `<head>` element for `<BrustPage head={[…]}>`. Discriminated by
|
|
18
|
+
* `tag`. On the native path, attribute values may be a string literal or a
|
|
19
|
+
* loader member-path (HTML-escaped); `text` (inner content of style/script/
|
|
20
|
+
* noscript) must be a static string literal (raw — never user input). */
|
|
21
|
+
export type HeadEntry =
|
|
22
|
+
| {
|
|
23
|
+
tag: 'link'
|
|
24
|
+
rel: string
|
|
25
|
+
href: string
|
|
26
|
+
type?: string
|
|
27
|
+
sizes?: string
|
|
28
|
+
as?: string
|
|
29
|
+
media?: string
|
|
30
|
+
crossOrigin?: string
|
|
31
|
+
}
|
|
32
|
+
| { tag: 'meta'; name?: string; property?: string; httpEquiv?: string; content: string }
|
|
33
|
+
| { tag: 'base'; href?: string; target?: string }
|
|
34
|
+
| { tag: 'style'; text: string; media?: string }
|
|
35
|
+
| {
|
|
36
|
+
tag: 'script'
|
|
37
|
+
src?: string
|
|
38
|
+
text?: string
|
|
39
|
+
type?: string
|
|
40
|
+
defer?: boolean
|
|
41
|
+
async?: boolean
|
|
42
|
+
crossOrigin?: string
|
|
43
|
+
}
|
|
44
|
+
| { tag: 'noscript'; text: string }
|
|
45
|
+
|
|
17
46
|
export interface BrustPageProps {
|
|
18
47
|
/** `<html lang>` — defaults to `"en"`. */
|
|
19
48
|
lang?: string
|
|
@@ -25,16 +54,30 @@ export interface BrustPageProps {
|
|
|
25
54
|
title?: string
|
|
26
55
|
/** `<meta name="description" content="…">`. Omitted when absent. */
|
|
27
56
|
description?: string
|
|
57
|
+
/** Extra `<head>` elements (link/meta/base/style/script/noscript). */
|
|
58
|
+
head?: HeadEntry[]
|
|
28
59
|
/** Page body — rendered inside `<body>`. */
|
|
29
60
|
children?: ReactNode
|
|
30
61
|
}
|
|
31
62
|
|
|
63
|
+
/** React mirror of one head entry (non-native path). Native routes emit these
|
|
64
|
+
* in Rust; this keeps the rare React render in sync. */
|
|
65
|
+
function headEntryToElement(entry: HeadEntry, key: number): ReactNode {
|
|
66
|
+
const { tag, ...rest } = entry
|
|
67
|
+
if (tag === 'style' || tag === 'script' || tag === 'noscript') {
|
|
68
|
+
const { text, ...attrs } = rest as { text?: string } & Record<string, unknown>
|
|
69
|
+
return createElement(tag, { key, ...attrs }, text ?? undefined)
|
|
70
|
+
}
|
|
71
|
+
return createElement(tag, { key, ...rest })
|
|
72
|
+
}
|
|
73
|
+
|
|
32
74
|
export function BrustPage({
|
|
33
75
|
lang = 'en',
|
|
34
76
|
className,
|
|
35
77
|
bodyClassName,
|
|
36
78
|
title,
|
|
37
79
|
description,
|
|
80
|
+
head,
|
|
38
81
|
children,
|
|
39
82
|
}: BrustPageProps): ReactNode {
|
|
40
83
|
return createElement(
|
|
@@ -50,6 +93,7 @@ export function BrustPage({
|
|
|
50
93
|
? createElement('meta', { name: 'description', content: description })
|
|
51
94
|
: null,
|
|
52
95
|
createElement('link', { rel: 'stylesheet', href: '/_brust/css/app.css' }),
|
|
96
|
+
...(head ?? []).map((entry, i) => headEntryToElement(entry, i)),
|
|
53
97
|
),
|
|
54
98
|
createElement('body', { className: bodyClassName }, children),
|
|
55
99
|
)
|