Repository navigation
Keep HTML module roots independent and classify their type correctly - #1768
Conversation
Lorenzobattistela
left a comment
There was a problem hiding this comment.
Thanks for this. The type-classification fix and the deadlock repro are both solid, and the gates are green merged onto main d169272 (repo 54/54, test 1680/1680, perf 124/124, ping 63/63, safe 0 false rejects). But turning external module scripts into wrapper entries changes behavior beyond #1767/#1774, and three of those changes break pages that build on main:
-
Root-relative srcs no longer build.
<script type="module" src="/src/main.js">(the usual Vite-style index.html) goes throughpath.resolve(dirname(file), source), which resolves to the filesystem root. Run from the page's directory, main builds this page; the PR fails withCould not resolve: "/src/main.js" at a.html:1:8. -
"sideEffects": falsesilently empties the script. The wrapperimport "/abs/m.js";is a bare side-effect import, and Bun drops it under"sideEffects": false. With a package.json holding{"sideEffects":false}and<script type="module" src="./m.js">(m.js =console.log("side")), main's output contains the log; the PR's bend-entry-0-.js and chunk-.js are both empty, and the build reports no error. -
A module root inside
<template>swallows the classic batch.earlyis inserted before the first rewritten module root even when that root is inside an inert<template>, and the real batch tag is then removed. With<template><script type="module">…</script></template><script src="./c.js"></script><script type="module">…</script>, c.js never runs. On main it does.
The simplest fix for all three may be to keep external src modules as Bun handles them today, and only split inline modules into separate entries. That's enough for #1774.
Smaller things:
- An unresolvable external src now reports the wrapper's location:
m.html:1:8with a code frame showing the generatedimport "/abs/..."line, instead of the user's./missing.tson its real line. - tests/io/html_script_types.js runs main.ts without the HOME / BEND_ORIGIN / BEND_NO_TELEMETRY overrides and without a spawn timeout (the other two tests set them), so a gate run touches the real ~/.bend cache, calls bend-lang.com/check, and a stuck child can hang the shard.
emittedtakes any entry-point output whose basename matchesbend-entry-N-, including the HTML page itself when the page is named bend-entry-0.html. It only works because the JS output happens to come last; filtering on.jswould make it deterministic.- When Bun's batch tag sits in
<head>and the module roots are in<body>, the head tag is never removed, so the batch is emitted twice. - Nit: the page's dest uses
path.join(dir, …)while every other output usespath.resolve, so the size listing mixes relative and absolute paths.fileis also bound three ways inside cli_bundle (page realpath, href's parameter, output path); renaming the inner two would make it easier to read.
|
Thanks, I'll keep external src scripts on Bun's normal path and split only inline modules. I'll fix the template/head batch placement and the test isolation too, then check the remaining diagnostics/output cases before pushing. |
|
Pushed 903dffe. Cut out the external wrappers: only inline modules become separate entries now. Added real CLI regressions for root-relative srcs and a console-only module under The batch stays outside templates, and an existing head batch is reused rather than copied. Entry mapping ignores HTML outputs; output paths are absolute and the shadowed bindings are gone. All three consumers now isolate HOME/origin/telemetry and give child processes a 6-second timeout. The missing-src error now names All three IO consumers print 0, the Chromium cases pass (classic once, template inert, no duplicate batch, await reaches 42), and repo is 54/54. |
HTMLRewriter keeps character references in attributes, so an encoded "mod&bendlang#117;le" was skipped, and trim() strips NBSP, so a non-module type ran. Decode the ASCII references that can spell "module" and trim only HTML whitespace. Closes bendlang#1767 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ac0c907 to
c124b05
Compare
|
Thanks for both fixes and the careful repros. We've cut this PR down to the #1767 fix and force-pushed it as one commit (authored by you): the HTML-rules decoding of We're not taking the #1774 part. After two review rounds we did have a version that kept every module root independent (per-script entries mapped through Bun's metafile, CSS links, template and batch handling; still reachable at ac0c907). But it cost about +1,600 ttok on main.ts and depends on Bun internals for a rare pattern. The underlying behavior is Bun's: its HTML bundler merges a page's module scripts into one sequential chunk, even separate src files. Details on #1774. Removing our earlier changes-requested review once this lands. |
|
Thanks for landing the type-decoding fix. I'll keep the Bun workaround out and won't push the old branch over your rewrite. |
Fixes HTML script classification and independent inline modules that deadlocked when Bun combined them into one sequential chunk.
Only inline modules become separate entries in the shared build graph. External src scripts stay on Bun's normal HTML path, including root-relative URLs and packages with
sideEffects: false. Shared dependencies still execute once. The HTML batch stays outside inert templates and isn't duplicated when Bun already put it in the head.Checked the real CLI and Chromium: the waiting page reaches 42; root-relative, side-effects, template/head placement and output-name cases pass. All three executable IO consumers print 0, including the new root-relative and console-only regressions. Child spawns use isolated HOME/origin/telemetry and 6-second timeouts. Repo gate: 54/54.
Missing external srcs use Bun's native diagnostic against the page and original relative specifier. No kernel, GUIDE, changelog, gate or cap changes.
Closes #1767