Commit 8adf441
committed
fix(includes): defensively register scope vars to survive harvest mis-hits
`extractExports` walks a client script's bundled output looking for
top-level const/let/var/function declarations. Its depth tracker
handles strings, template literals, and {} braces — but not regex
literals or other nested constructs. When a `<script client>` pulls
in a heavier third-party (e.g. `ts-medium-editor`) via Bun.build,
the bundled blob contains regex literals like `/\{.../` that flip
the depth counter and let inner-scope vars (e.g. `message`,
`parent`, `frag`) leak into the harvested top-level list.
The downstream effect was fatal: `transformSignalScript` emitted
window.stx._scopes['stx_scope_X'] = { isIE, ..., message, ... };
and at hydration `{ message }` (shorthand for `{ message: message }`)
threw `ReferenceError: message is not defined` — taking the whole
scope registration down with it and leaving the component
unregistered.
Switch the registration to a try/catch per name. Stray harvested
identifiers just resolve to `undefined` (skipped) instead of
crashing, so a single false-positive can no longer brick the rest
of the scope's vars. Cleaner long-term fix is to teach the depth
walker about regex literals — left as a follow-up since this
defensive shape is correct even with a perfect harvester.1 parent bc03a5a commit 8adf441
1 file changed
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
251 | 265 | | |
252 | 266 | | |
253 | 267 | | |
| |||
263 | 277 | | |
264 | 278 | | |
265 | 279 | | |
266 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
267 | 283 | | |
268 | 284 | | |
269 | 285 | | |
| |||
0 commit comments