brustjs 0.1.26-alpha → 0.1.27-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/package.json +7 -7
- package/runtime/cli/jinja-staleness.ts +50 -0
- package/runtime/cli/native-routes-emit.ts +9 -1
- package/runtime/index.js +52 -52
- package/runtime/index.ts +47 -1
- package/runtime/islands/bootstrap.ts +13 -5
- package/runtime/islands/native-render.ts +11 -0
- package/runtime/navigation/index.ts +2 -0
- package/runtime/navigation/navigate.ts +58 -0
- package/runtime/navigation/store.ts +12 -0
- package/runtime/routes.ts +30 -6
- package/runtime/tsconfig.typecheck.json +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brustjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27-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.27-alpha",
|
|
44
|
+
"brustjs-darwin-arm64": "0.1.27-alpha",
|
|
45
|
+
"brustjs-linux-x64-gnu": "0.1.27-alpha",
|
|
46
|
+
"brustjs-linux-arm64-gnu": "0.1.27-alpha",
|
|
47
|
+
"brustjs-linux-x64-musl": "0.1.27-alpha",
|
|
48
|
+
"brustjs-linux-arm64-musl": "0.1.27-alpha"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^19.2.6",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Dirent, existsSync, readdirSync, statSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// Dirs that never hold authored route/component source — skip them so a stray
|
|
5
|
+
// newer .tsx in a build cache or dependency doesn't force a needless recompile.
|
|
6
|
+
const IGNORED_DIRS = new Set(['node_modules', '.brust', 'dist', '.git'])
|
|
7
|
+
|
|
8
|
+
/** Walk `dir` recursively, returning the newest mtime (ms) of any `.tsx` file
|
|
9
|
+
* found, or 0 when there are none. Ignored dirs (build caches, deps) are pruned. */
|
|
10
|
+
function newestTsxMtime(dir: string): number {
|
|
11
|
+
let newest = 0
|
|
12
|
+
let entries: Dirent[]
|
|
13
|
+
try {
|
|
14
|
+
entries = readdirSync(dir, { withFileTypes: true }) as Dirent[]
|
|
15
|
+
} catch {
|
|
16
|
+
return newest
|
|
17
|
+
}
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (entry.isDirectory()) {
|
|
20
|
+
if (IGNORED_DIRS.has(entry.name)) continue
|
|
21
|
+
newest = Math.max(newest, newestTsxMtime(join(dir, entry.name)))
|
|
22
|
+
} else if (entry.isFile() && entry.name.endsWith('.tsx')) {
|
|
23
|
+
try {
|
|
24
|
+
newest = Math.max(newest, statSync(join(dir, entry.name)).mtimeMs)
|
|
25
|
+
} catch {
|
|
26
|
+
// file vanished mid-walk — ignore
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return newest
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** True when the emitted native templates in `jinjaDir` are missing or older
|
|
34
|
+
* than the authored `.tsx` sources under `scanRoot` — i.e. a boot-time
|
|
35
|
+
* recompile is warranted so `bun run <entry>` (source mode) doesn't require a
|
|
36
|
+
* prior `brust build`, and an edited page is picked up without a stale render.
|
|
37
|
+
*
|
|
38
|
+
* Staleness = the build marker (`_manifest.json`, written last by
|
|
39
|
+
* `emitNativeTemplates`) is absent, OR any source `.tsx` is newer than it. */
|
|
40
|
+
export function isJinjaStale(scanRoot: string, jinjaDir: string): boolean {
|
|
41
|
+
const manifestPath = join(jinjaDir, '_manifest.json')
|
|
42
|
+
if (!existsSync(manifestPath)) return true
|
|
43
|
+
let manifestMtime: number
|
|
44
|
+
try {
|
|
45
|
+
manifestMtime = statSync(manifestPath).mtimeMs
|
|
46
|
+
} catch {
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
return newestTsxMtime(scanRoot) > manifestMtime
|
|
50
|
+
}
|
|
@@ -635,6 +635,14 @@ export function reconcileIslandManifest(
|
|
|
635
635
|
|
|
636
636
|
const raw = JSON.parse(readFileSync(islandsJsonPath, 'utf8')) as RawIslandEntry[]
|
|
637
637
|
|
|
638
|
+
// sourcePath is written PROJECT-RELATIVE (relative to the build's cwd), never
|
|
639
|
+
// the build machine's absolute path — the absolute path leaks the developer's
|
|
640
|
+
// username into shipped dist/jinja artifacts, and a relative path survives the
|
|
641
|
+
// dual-emit copy into `.brust/jinja` (both dirs sit directly under cwd, so the
|
|
642
|
+
// same relative string resolves correctly from either). The runtime
|
|
643
|
+
// (`loadIslandManifest`) rehydrates it to an absolute path against cwd before
|
|
644
|
+
// the SSR import. Mirrors the .components.json contract (emitComponentArtifacts).
|
|
645
|
+
const projectRoot = process.cwd()
|
|
638
646
|
const enriched: EnrichedIslandEntry[] = raw.map((entry) => {
|
|
639
647
|
const sourcePath = pageImports.get(entry.component)
|
|
640
648
|
if (!sourcePath) {
|
|
@@ -642,7 +650,7 @@ export function reconcileIslandManifest(
|
|
|
642
650
|
`island component "${entry.component}" in native route "${routeName}" has no matching import in the page source (expected \`import ${entry.component} from "..."\`)`,
|
|
643
651
|
)
|
|
644
652
|
}
|
|
645
|
-
return { ...entry, sourcePath }
|
|
653
|
+
return { ...entry, sourcePath: relative(projectRoot, sourcePath).replaceAll('\\', '/') }
|
|
646
654
|
})
|
|
647
655
|
|
|
648
656
|
writeFileSync(islandsJsonPath, JSON.stringify(enriched))
|
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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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.27-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
|
@@ -459,6 +459,39 @@ export const brust = {
|
|
|
459
459
|
const jinjaDir = prebuilt
|
|
460
460
|
? path.join(distDir!, 'jinja')
|
|
461
461
|
: path.resolve(process.cwd(), '.brust/jinja')
|
|
462
|
+
|
|
463
|
+
// Source mode (`bun run <entry>`, not prebuilt): the emitted native
|
|
464
|
+
// templates in `.brust/jinja` may be missing (never built) or older than
|
|
465
|
+
// the authored `.tsx` (edited since). Recompile them at boot so a native
|
|
466
|
+
// route doesn't 404/stale without a prior `brust build` — the "must build
|
|
467
|
+
// first" papercut. `brust dev` already emits before this boot, so the
|
|
468
|
+
// staleness check is a no-op there; prebuilt ships the templates and skips
|
|
469
|
+
// entirely. A compile failure warns and continues (non-native routes still
|
|
470
|
+
// boot). The heavy emitter is imported lazily so it never enters the hot
|
|
471
|
+
// path (or the prebuilt bundle's live code).
|
|
472
|
+
if (!prebuilt) {
|
|
473
|
+
const routesPath = path.join(scanRoot, 'routes.tsx')
|
|
474
|
+
if (existsSync(routesPath)) {
|
|
475
|
+
const { isJinjaStale } = await import('./cli/jinja-staleness.ts')
|
|
476
|
+
if (isJinjaStale(scanRoot, jinjaDir)) {
|
|
477
|
+
try {
|
|
478
|
+
const { emitNativeTemplates } = await import('./cli/native-routes-emit.ts')
|
|
479
|
+
await emitNativeTemplates({
|
|
480
|
+
entryFile: routesPath,
|
|
481
|
+
flatRoutes: opts.routes as { nativeTemplate?: string }[],
|
|
482
|
+
outDir: jinjaDir,
|
|
483
|
+
repoRoot: process.cwd(),
|
|
484
|
+
})
|
|
485
|
+
console.log(`[brust] main: compiled native templates → ${jinjaDir}`)
|
|
486
|
+
} catch (err) {
|
|
487
|
+
console.warn(
|
|
488
|
+
`[brust] main: native template recompile failed (run \`brust build\`): ${(err as Error).message}`,
|
|
489
|
+
)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
462
495
|
configureJinjaDir(jinjaDir)
|
|
463
496
|
loadJinjaOnce(jinjaDir)
|
|
464
497
|
if (prebuilt && existsSync(jinjaDir)) {
|
|
@@ -708,11 +741,24 @@ export const brust = {
|
|
|
708
741
|
console.log(`[brust] worker: mcp server ready (${mcpManifest.tools.length} tools)`)
|
|
709
742
|
}
|
|
710
743
|
|
|
711
|
-
// Sub-project J note: jinja
|
|
744
|
+
// Sub-project J note: jinja TEMPLATES are loaded ONCE process-wide by the
|
|
712
745
|
// main branch's loadJinjaOnce call. Rust's ENV is a process-global
|
|
713
746
|
// OnceLock; Bun Workers share that process, so calling it from each
|
|
714
747
|
// worker would panic on second set(). The worker reads ENV.get() at
|
|
715
748
|
// napi_render_jinja time — no per-worker load needed.
|
|
749
|
+
//
|
|
750
|
+
// BUT the JS-side island/component sidecar readers (native-render.ts)
|
|
751
|
+
// resolve against a MODULE-LOCAL `_configuredJinjaDir`, and Bun Workers
|
|
752
|
+
// are separate JS isolates — that variable is unset here unless we set it.
|
|
753
|
+
// Without this, the worker falls back to `cwd/.brust/jinja`; a prebuilt
|
|
754
|
+
// run then silently depends on the build's `.brust` dual-emit, and once
|
|
755
|
+
// that cache is removed the island manifest reads null → `data-brust-props`
|
|
756
|
+
// renders empty → the client's JSON.parse throws. Configure it to the SAME
|
|
757
|
+
// dir main loads from so native island/component render works dist-only.
|
|
758
|
+
const workerJinjaDir = prebuilt
|
|
759
|
+
? path.join(distDir!, 'jinja')
|
|
760
|
+
: path.resolve(process.cwd(), '.brust/jinja')
|
|
761
|
+
configureJinjaDir(workerJinjaDir)
|
|
716
762
|
|
|
717
763
|
const { makeRenderer: make } = await import('./routes.ts')
|
|
718
764
|
let wid: number | null = null
|
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
import { createRoot, hydrateRoot, type Root } from 'react-dom/client'
|
|
17
17
|
import { createElement } from 'react'
|
|
18
18
|
import { applyStoreSnapshot } from '../store/client-hydrate.ts'
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
__navStart,
|
|
21
|
+
__navCommit,
|
|
22
|
+
__navError,
|
|
23
|
+
__navInit,
|
|
24
|
+
registerNavigator,
|
|
25
|
+
} from '../navigation/store.ts'
|
|
20
26
|
import { installActiveNav } from '../navigation/active-nav.ts'
|
|
21
27
|
|
|
22
28
|
// Track React roots created by hydrateOne so we can unmount them before
|
|
@@ -207,7 +213,7 @@ export function isInternalLink(a: HTMLAnchorElement, event: MouseEvent): boolean
|
|
|
207
213
|
|
|
208
214
|
let inFlight: AbortController | null = null
|
|
209
215
|
|
|
210
|
-
export async function navigate(url: URL,
|
|
216
|
+
export async function navigate(url: URL, mode: 'push' | 'replace' | 'none'): Promise<void> {
|
|
211
217
|
inFlight?.abort()
|
|
212
218
|
const ac = new AbortController()
|
|
213
219
|
inFlight = ac
|
|
@@ -229,7 +235,8 @@ export async function navigate(url: URL, push: boolean): Promise<void> {
|
|
|
229
235
|
swapMainContent(main as HTMLElement, html)
|
|
230
236
|
if (store) applyStoreSnapshot(store)
|
|
231
237
|
if (title) document.title = title
|
|
232
|
-
if (push) history.pushState({}, '', url.href)
|
|
238
|
+
if (mode === 'push') history.pushState({}, '', url.href)
|
|
239
|
+
else if (mode === 'replace') history.replaceState({}, '', url.href)
|
|
233
240
|
window.scrollTo(0, 0)
|
|
234
241
|
hydrateMarkersIn(main as HTMLElement)
|
|
235
242
|
__navCommit(url.pathname, url.search)
|
|
@@ -255,14 +262,15 @@ function installInterceptor(): void {
|
|
|
255
262
|
e.preventDefault()
|
|
256
263
|
// 'reload' = clicking the page we're already on → no-op (no refetch).
|
|
257
264
|
if (intent === 'reload') return
|
|
258
|
-
void navigate(new URL(a.href, location.href),
|
|
265
|
+
void navigate(new URL(a.href, location.href), 'push')
|
|
259
266
|
})
|
|
260
267
|
window.addEventListener('popstate', () => {
|
|
261
|
-
void navigate(new URL(location.href),
|
|
268
|
+
void navigate(new URL(location.href), 'none')
|
|
262
269
|
})
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
if (typeof document !== 'undefined') {
|
|
273
|
+
registerNavigator((url, replace) => navigate(url, replace ? 'replace' : 'push'))
|
|
266
274
|
if (document.readyState === 'loading') {
|
|
267
275
|
document.addEventListener('DOMContentLoaded', () => {
|
|
268
276
|
__navInit(location.pathname, location.search)
|
|
@@ -128,6 +128,17 @@ export function loadIslandManifest(
|
|
|
128
128
|
manifestCache.set(abs, null)
|
|
129
129
|
return null
|
|
130
130
|
}
|
|
131
|
+
// sourcePath ships PROJECT-RELATIVE (no leaked absolute build path). Rehydrate
|
|
132
|
+
// it to an absolute path against cwd so the SSR `import(entry.sourcePath)` in
|
|
133
|
+
// resolveIslandContext resolves regardless of where the manifest lives. An
|
|
134
|
+
// already-absolute path (old manifests, unit-test stubs) passes through.
|
|
135
|
+
if (parsed) {
|
|
136
|
+
for (const entry of parsed) {
|
|
137
|
+
if (entry.sourcePath && !path.isAbsolute(entry.sourcePath)) {
|
|
138
|
+
entry.sourcePath = path.resolve(process.cwd(), entry.sourcePath)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
131
142
|
manifestCache.set(abs, parsed)
|
|
132
143
|
return parsed
|
|
133
144
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// runtime/navigation/navigate.ts — public imperative SPA navigation for
|
|
2
|
+
// brustjs/navigation. DOM-free at import (touches location/history only at call
|
|
3
|
+
// time, like active-nav.ts); delegates the swap to the navigator bootstrap
|
|
4
|
+
// registers, so this module never imports DOM/island code.
|
|
5
|
+
import { _getNavigator } from './store.ts'
|
|
6
|
+
|
|
7
|
+
export type QueryValue = string | number | boolean
|
|
8
|
+
export type QueryInit = Record<string, QueryValue | null | undefined | ReadonlyArray<QueryValue>>
|
|
9
|
+
export interface NavigateOptions {
|
|
10
|
+
query?: QueryInit
|
|
11
|
+
replace?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function applyQuery(params: URLSearchParams, query: QueryInit): void {
|
|
15
|
+
for (const key of Object.keys(query)) {
|
|
16
|
+
const v = query[key]
|
|
17
|
+
params.delete(key)
|
|
18
|
+
if (v === null || v === undefined) continue
|
|
19
|
+
if (Array.isArray(v)) {
|
|
20
|
+
for (const item of v) params.append(key, String(item))
|
|
21
|
+
} else {
|
|
22
|
+
params.append(key, String(v as QueryValue))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Serialize a query object to a `?...` string (or '' when empty). Pure, DOM-free. */
|
|
28
|
+
export function buildSearch(query: QueryInit): string {
|
|
29
|
+
const params = new URLSearchParams()
|
|
30
|
+
applyQuery(params, query)
|
|
31
|
+
const s = params.toString()
|
|
32
|
+
return s ? `?${s}` : ''
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Programmatic SPA navigation. Resolves `path` against the current location,
|
|
36
|
+
* merges `options.query` over any query already in `path` (each key replaces all
|
|
37
|
+
* base occurrences; null/undefined deletes), then delegates to the registered
|
|
38
|
+
* navigator (full SPA swap + nav-state lifecycle). No navigator registered (no
|
|
39
|
+
* islands bootstrap) → full-document load so the call still navigates. */
|
|
40
|
+
export async function navigate(path: string, options?: NavigateOptions): Promise<void> {
|
|
41
|
+
// navigate() is a client-only action (resolves against location + drives the DOM
|
|
42
|
+
// swap). Guard the bare `location` access so a server-side call surfaces a
|
|
43
|
+
// legible error instead of a raw `ReferenceError` (mirrors active-nav.ts's
|
|
44
|
+
// typeof-guard discipline; see the SSR non-goal in the design).
|
|
45
|
+
if (typeof location === 'undefined') {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'[brust] navigate() is a client-only action — no location/DOM available (called during SSR?)',
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
const url = new URL(path, location.href)
|
|
51
|
+
if (options?.query) applyQuery(url.searchParams, options.query)
|
|
52
|
+
const nav = _getNavigator()
|
|
53
|
+
if (nav) {
|
|
54
|
+
await nav(url, options?.replace ?? false)
|
|
55
|
+
} else {
|
|
56
|
+
location.assign(url.href)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -46,6 +46,7 @@ interface NavInternal extends NavStore {
|
|
|
46
46
|
// would infinite-loop "getSnapshot should be cached"). Mirrors defineStore.
|
|
47
47
|
_version: number
|
|
48
48
|
_snap: { value: NavState; version: number } | null
|
|
49
|
+
_navigator: ((url: URL, replace: boolean) => Promise<void>) | null
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
function createNav(): NavInternal {
|
|
@@ -62,6 +63,7 @@ function createNav(): NavInternal {
|
|
|
62
63
|
_error: new Set(),
|
|
63
64
|
_version: 0,
|
|
64
65
|
_snap: null,
|
|
66
|
+
_navigator: null,
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -202,6 +204,16 @@ export function __navError(toPath: string, error: unknown): void {
|
|
|
202
204
|
emit(s)
|
|
203
205
|
}
|
|
204
206
|
|
|
207
|
+
/** Register the SPA navigator implementation (bootstrap's swap). Last-write-wins;
|
|
208
|
+
* re-registration with the same closure (HMR / multiple chunks) is idempotent. */
|
|
209
|
+
export function registerNavigator(fn: (url: URL, replace: boolean) => Promise<void>): void {
|
|
210
|
+
store()._navigator = fn
|
|
211
|
+
}
|
|
212
|
+
/** @internal — the registered navigator, or null when no islands bootstrap loaded. */
|
|
213
|
+
export function _getNavigator(): ((url: URL, replace: boolean) => Promise<void>) | null {
|
|
214
|
+
return store()._navigator
|
|
215
|
+
}
|
|
216
|
+
|
|
205
217
|
// Test-only: drop the singleton so the next access rebuilds fresh signals.
|
|
206
218
|
export function __resetNavForTest(): void {
|
|
207
219
|
G.__BRUST_NAV__ = undefined
|
package/runtime/routes.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Buffer } from 'node:buffer'
|
|
|
11
11
|
import * as native from './index.js'
|
|
12
12
|
import { renderBranchStreaming } from './render/stream.ts'
|
|
13
13
|
import { runInStoreContext, collectSnapshot } from './store/server-context.ts'
|
|
14
|
+
import { buildStoreScripts } from './render/inject-store.ts'
|
|
14
15
|
import { runInRequestCache } from './loader-cache.ts'
|
|
15
16
|
import { runInRequestScope, __scope } from './request-context.ts'
|
|
16
17
|
import {
|
|
@@ -729,17 +730,22 @@ export function makeRenderer(
|
|
|
729
730
|
let data: Record<string, unknown>
|
|
730
731
|
const ctx = { params: call.params, path: call.path, req: call.req }
|
|
731
732
|
let chainResult: NativeChainResult
|
|
733
|
+
let storeSnapshot: Record<string, Record<string, unknown>> | null = null
|
|
732
734
|
try {
|
|
733
735
|
// Run the WHOLE route chain's loaders top-down (parent → leaf) and
|
|
734
736
|
// merge into ONE flat context (child keys win), mirroring the React
|
|
735
737
|
// chain-loader path. Wrap the entire loop in a SINGLE per-request
|
|
736
738
|
// store scope so a parent loader's defineStore writes are visible to
|
|
737
|
-
// child loaders (one Map per request — NOT one per loader).
|
|
738
|
-
// snapshot
|
|
739
|
-
//
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
)
|
|
739
|
+
// child loaders (one Map per request — NOT one per loader). B7: the
|
|
740
|
+
// store snapshot IS collected here, inside the request-store scope and
|
|
741
|
+
// AFTER the loaders run (the only point native store writes happen —
|
|
742
|
+
// the render is Rust-side and touches no store), feeding the
|
|
743
|
+
// document-shell `{{ __brust_store__ }}` slot below.
|
|
744
|
+
chainResult = await runInRequestContext(call.req?.cookies ?? {}, async () => {
|
|
745
|
+
const r = await runNativeChainLoaders(flat.chain, ctx)
|
|
746
|
+
storeSnapshot = collectSnapshot()
|
|
747
|
+
return r
|
|
748
|
+
})
|
|
743
749
|
} catch (err) {
|
|
744
750
|
console.error(`[brust] loader failed for native route ${flat.fullPath}:`, err)
|
|
745
751
|
// FAST LANE: native routes take dispatch_single_chunk (no chunk
|
|
@@ -769,6 +775,24 @@ export function makeRenderer(
|
|
|
769
775
|
} else {
|
|
770
776
|
data = chainResult.data
|
|
771
777
|
}
|
|
778
|
+
// B7 — native store-snapshot SSR. Fill the framework-owned
|
|
779
|
+
// `{{ __brust_store__ | safe }}` slot (emitted into every native
|
|
780
|
+
// full-document <head>) with the defineStore SSR snapshot collected
|
|
781
|
+
// inside the request-store scope above. buildStoreScripts(null) === '',
|
|
782
|
+
// so the key is always a string and both render sub-paths (the
|
|
783
|
+
// island/component JSON.parse path and the no-island encode path)
|
|
784
|
+
// inherit it for free.
|
|
785
|
+
if (data && typeof data === 'object') {
|
|
786
|
+
// `__brust_store__` is a framework-reserved render-context key. A user
|
|
787
|
+
// loader returning it would be silently overwritten here; dev-warn so
|
|
788
|
+
// the collision isn't invisible (mirrors the Set-Cookie warning below).
|
|
789
|
+
if (process.env.BRUST_DEV === '1' && '__brust_store__' in data) {
|
|
790
|
+
console.warn(
|
|
791
|
+
`[brust] native loader for "${flat.nativeTemplate}" returned a reserved "__brust_store__" key — overwritten by the store snapshot`,
|
|
792
|
+
)
|
|
793
|
+
}
|
|
794
|
+
;(data as Record<string, unknown>).__brust_store__ = buildStoreScripts(storeSnapshot)
|
|
795
|
+
}
|
|
772
796
|
const json = JSON.stringify(data)
|
|
773
797
|
// napiRenderJinja has no headers param — any Set-Cookie staged by a
|
|
774
798
|
// native loader is dropped on this path. Dev-warn so it's not silent.
|