Repository navigation
Serve the browser framework as written, in JavaScript with JSDoc types - #4184
Merged
Merged
Conversation
An edit to the framework's TypeScript reached no page until someone ran the build, and nothing said so: the kernel's freshness check (`runtime_selection.read_runtime`) hashes the `.js` modules a page runs, and the framework's source was `.ts`. The framework is now JavaScript under `browser/runtime/` (`framework.js`, the facade, and `framework/`), so a page serves its source as it does every other runtime module, and an edit makes the kernel stale and the source modules run, with no build. The type check keeps the framework's guarantees. Each module opts into the strict program with `// @ts-check`, as the strict runtime modules already did, so `strict`, `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes` still hold for it. `domain.ts`, which held only types, is `domain.d.ts`. The bundles the framework imports by served path, `/vendor/lit.js` and `/vendor/signals-core.js`, read as declarations of the packages they bundle (`lit.d.ts`, `signals-core.d.ts`); that also gives packages that import `/vendor/lit.js` Lit's own types, which found one expando property in `lf-timeline`, now declared. This deletes the compiled copy in `browser/vendor/browser-runtime/` (2,670 lines), the compile step and its import rewriting in `build/browser/build.mjs`, the line-preservation test, the `Generated from` trailer lookup in `tests/js_facts.mjs`, and the `amaro` dependency. The kernel still compiles the framework and its signals in; its requests and bytes before a page presents are unchanged. The framework's tests move to `tests/runtime/framework-*.test.mjs`, which `test:runtime` runs. Runtime modules import the facade as `/runtime/framework.js`. `focus.js`, a primitive that may import only vendor bundles and other primitives, takes `signal` from `/vendor/signals-core.js`, since the facade now reads as the runtime owner it is. dependency-cruiser excludes the facade by name, as it did when it sat under `/vendor/`. Closes #4112 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # dist/kernel/kernel.json # dist/kernel/leaf.js # dist/kernel/runtime/bundle-answer.js # dist/kernel/runtime/bundle-surfaces.js
The framework's strictness hung on a `// @ts-check` line nothing enforced: a new framework module without it passed the type check unchecked. The strict program now checks every runtime module (`checkJs`) and reports the framework's by path and the others that opt in (`strictlyChecked` in `build/browser/build.mjs`), so the framework's modules drop the pragma. A pragma-less module under `runtime/framework/` with an unchecked index, a null dereference and an implicit-any parameter now fails all three. `lit.d.ts` hand-listed eleven Lit modules, so `when`, `unsafeSVG` or `staticHtml` imported from `/vendor/lit.js` failed to type. The build now writes it from the namespace `build/lit.mjs` bundles, and the check holds it to that. The type check's home is `browser/types/`, since `browser/framework/` no longer holds the framework. The framework's third-party notices are named after the bundles served, `lit.LICENSES.txt` and `signals-core.LICENSES.txt`, and stale mentions of the compiled framework are gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Checking every runtime module in the strict program and filtering about 2 MB of its diagnostics down to the strict set hid tsc's output behind the build's own filter. The framework's modules carry `// @ts-check` again, which puts them in the strict program the way every other strict runtime module gets there, and `build/browser/build.mjs` refuses a module under `runtime/framework.js` or `runtime/framework/` that doesn't start with it, naming the file. The strict program's output is unfiltered again, and the raised `maxBuffer` is gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
marked this pull request as ready for review
October 26, 2026 05:53
# Conflicts: # dist/kernel/kernel.json # dist/kernel/leaf.js # dist/kernel/runtime/bundle-content-layout.js # dist/kernel/runtime/bundle-page-inspection.js # dist/kernel/runtime/bundle-surfaces.js
leaf-agent
approved these changes
Oct 26, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 30, 2026
…pages and tests without a build (#4780) #4725 to #4757 wrote seven runtime modules in TypeScript (`semantic-state`, `rendering`, `queued-work`, `exception` and the framework's `application`, `presentation` and `snapshot`) and committed a generated `.js` beside each. Pages and runtime tests read only the generated file. The kernel's freshness check hashes `.js` files, and `tests/runtime/dom.mjs` resolves the committed `.js`. So an edit to a `.ts` changed nothing until `pnpm run build:browser` ran, and every probe and test passed on the old code. That is the failure #4112 described and #4184 fixed. The conversion bought no stricter checking, since the same strict program checks JSDoc under `// @ts-check`, and the files came out about the same length. The seven modules are authored JavaScript again. Each starts with `// @ts-check` in the strict program and keeps every flag the campaign added (`strictFunctionTypes`, `noImplicitThis`, `useUnknownInCatchVariables`). The executable code is unchanged: run through esbuild and compared as ASTs, each new module matches the generated file it replaces, and the kernel diff is only variable renames and input hashes. | After appending an export to `semantic-state` | What a page server serves | Has the edit | |---|---|---| | main, editing `semantic-state.ts` | the same kernel, still taken as fresh | no | | this branch, editing `semantic-state.js` | the source modules | yes | With the framework's `application` module made to throw as it loads, `framework-application.test.mjs` passes on main (55 of 55, since it imports the generated file) and fails on this branch. ## What it deletes - `build/runtime-sources.mjs`, the compile and orphan-cleanup logic in `build/browser/build.mjs`, and its tests. - The generated-output handling in `.github/scripts/dependency-bundles.mjs`, `.dependency-cruiser.mjs`, `tests/js_facts.mjs` and `tests/journeys/test_unused_exports.py`. - The checker-derived options #4739 gave `build/esbuild.mjs`, which only the TypeScript emission needed. It returns to `tsconfigRaw: "{}"`. The build now refuses any `.ts` other than `.d.ts` under `browser/runtime/`, naming the file and #4112. The pragma guard is back to #4184's form, covering framework modules only. `browser/AGENTS.md` again describes the runtime as JavaScript a page runs as written. ## Other changes - **Export audit.** The converted modules take their types through JSDoc `@import` tags. `tests/js_facts.mjs` now reads those as it reads `import("…").Name`; without that, the audit reported `LocalMessage` and `PendingProjection` in `domain.d.ts` as unread. `dev/tests/test_js_facts.py` replaces its tests of the output mapping with tests of the tag. - **Dev probes.** This removes #4743's type-checking of the four dev probes (`main_thread.js`, `startup.js`, `bench_latency.js`, `verify_site_browser.js`) and `dev/browser-globals.d.ts`. It found nothing, and a mistake there fails as soon as the probe runs. #4743's five ESLint rules stay. - **Spawn forwarder.** The forwarder in `dev/leaf_dev/pi_watch_observer.mjs` returns to its three-argument form. #4737's tools program rejects that form's arity against `spawn`'s overloads, so one `@type` cast wraps it in place of `Reflect.apply` and two casts. ## Tests - `pnpm run check:hooks`, `check:tools`, `check:framework` (29 build tests) and `check:browser` after merging main. - `pnpm run check`, run before these last edits: 708 runtime and 88 Worker tests. - `uv run pytest tests/model -k "kernel or runtime_selection or distribution or js_facts"` (19 passed) and `dev/tests/test_js_facts.py` (6 passed). - Pre-commit on every changed file. Build tests that changed: the test that a renamed TypeScript owner's output is refused is gone with the mechanism. New tests cover the `.ts` refusal and the framework pragma guard. `tests/journeys/test_unused_exports.py` still fails on six exports, each in a file this change doesn't touch and no removed `.ts` file read: `check-api.js` `runtimeRootState`, `content-layout.js` `readDocumentHeaders`, `framework.js` `Directive`, `widget-elements.js` `selectableOfferElement`, `toc-view.js` `outlineDocument`, and `layout.js` `containedSpace`. This PR's edit to the test makes CI run it. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An edit to the browser framework now reaches pages with no build. The framework is JavaScript with JSDoc types under
browser/runtime/(framework.js, the facade, andframework/application.js,presentation.js,snapshot.js), so a page serves its source as it does every other runtime module. The kernel's freshness check (leaf.runtime_selection.read_runtime) hashes those.jsfiles, so an edit makes the kernel stale and the source modules run.Closes #4112
Repro, before and after
The issue's repro: append an export to the framework's
presentationmodule, then read the serving runtime with no build.browser/framework/presentation.ts)442564cd0d3662b1442564cd0d3662b1(unchanged)950be482f, before edit (browser/runtime/framework/presentation.js)081b6d3fe2e736f768ee527de447ba80What the type check keeps
The framework was strict TypeScript, and it stays strict. The type check's home is now
browser/types/, sincebrowser/framework/no longer holds the framework. Each framework module opts into the strict program,tsconfig.json, with a leading// @ts-check, as the strict runtime modules already did, sostrict,noUncheckedIndexedAccess,exactOptionalPropertyTypesandnoUnusedLocalsstill apply. Nothing used to enforce that pragma, sobuild/browser/build.mjsnow refuses any module underruntime/framework.jsorruntime/framework/that doesn't start with it, and names the file. Each program's tsc output stays unfiltered beyond the runtime program's existing filter.Proofs, each reverted after:
pnpm run check:browserrefuses a pragma-lessbrowser/runtime/framework/extra.jsand names it.pnpm run check:browserfails on a deliberate type error inpresentation.js(TS2345).tscfailed on an unchecked index insnapshot.js(TS2532,noUncheckedIndexedAccess).domain.test.tsis nowbrowser/types/domain.test.js. Its@ts-expect-errorandIsAnychecks fail whenEventis typedany.Declarations with no JavaScript home stay
.d.ts:domain.tsheld only types, so it is nowbrowser/types/domain.d.ts./vendor/lit.js,/vendor/signals-core.js), and those minified bundles carry no types. The generatedtsconfig.paths.jsonmaps the served paths to declarations of the packages they bundle. The build writeslit.d.tsfrom the namespacebuild/lit.mjsbundles (litNamespace), every public Lit module and static-html's renamed tags, andcheck:browserholds it to that, sowhen,unsafeSVGandstaticHtmltype as main typed them.signals-core.d.tsis four hand-written lines naming the two packages the signals bundle holds./vendor/lit.jsnow get Lit's own types too. That flagged an undeclared expando (event.step) inlf-timeline, which is now declared in the object literal.Compared as ASTs, the converted modules parse to the same program as the old compiled output, apart from import paths and two edits made for types.
currentWidgetRelationsreadsmemberships.get(x)![attr]!through a smallmembershelper that throws in the same cases, andselectWidgetnamesinputsbefore the callback in place ofinputs!.What it deletes
browser/vendor/browser-runtime.jsandbrowser/vendor/browser-runtime/{application,presentation,snapshot}.js: 2,670 lines.build/browser/build.mjs(−96 net), with theamarodependency (package.json,pnpm-lock.yaml).// Generated fromtrailer lookup intests/js_facts.mjsthat mapped a compiled module back to its source.The kernel keeps its copy. It still compiles the framework and its signals in, as it compiles every runtime module, and
dist/kernel/is about 420 bytes smaller. Rolldown chunks it differently:bundle-browser-runtime.jsis gone, the framework now sits inbundle-context.js, and the signals share a new chunk,bundle-signals-core.js, withqueued-work.js. The framework source grows from 2,666 to about 2,930 lines, because JSDoc puts types on lines of their own.Other changes
/runtime/framework.js. Thevendor/browser-runtimecontent-module rules ineslint.config.mjsare gone, since the/runtime/rules already cover the facade.semanticStoreOwnershipRulestill refuses deep imports intoframework/. It no longer requires the served path, which existed only because a relative path reached the compiled facade's blanked types.focus.jsis a primitive that may import only vendor bundles and other primitives. It now takessignalfrom/vendor/signals-core.js, because the facade no longer sits undervendor/and reads as the runtime owner it is..dependency-cruiser.mjsexcludes/runtime/framework.jsby name, as it excluded the facade under/vendor/. The framework's own modules are checked as owners.tests/runtime/framework-*.test.mjs, whichtest:runtimeruns, because the served modules import site-absolute/vendor/paths thattests/runtime/dom.mjsresolves. The publisher tests inbuild/browser/build.test.mjsjoinframework-snapshot.test.mjs.browser-runtime.LICENSES.txtbecomelit.LICENSES.txtandsignals-core.LICENSES.txt, one per served bundle.Packages that replaced the framework
packages.mddocuments packages replacing a kernel vendor module. The framework was one: a package'svendor/browser-runtime.jsreplaced the facade, and the kernel then stood aside. That no longer works. The framework is a runtime module now, andkernel_runtime_paths()refuses a package that replaces one. A packagevendor/file at/vendor/browser-runtime.jsis now an unrelated module nothing imports. The signals bundle a package could replace moved fromvendor/browser-runtime/signals-core.jstovendor/signals-core.js. A custom package that imported/vendor/browser-runtime.jsalso breaks. No bundled package did either, ESLint refused the import, andwidget-api.jsis the public API, so this PR makes no protocol bump.Browser startup
Requests and bytes loaded before the page first shows the server's state (
data-lf-presented), fromleaf-dev probe <page> --baseat32643b1a8. The later commits change no module's code, only comments and types. Each arm ran the kernel its own build commits:Requests are the same, and each page loads 301 fewer JS bytes. Apart from those, the files that load differ only by the chunking above.
A plain
--baserun misreports this change.leaf-dev probe --basecompiles the base arm's kernel with this checkout'sbuild/runtime-bundle.mjs(distribution.prepare). That compiler no longer knowsvendor/browser-runtime*as framework, so it loaded the base's framework natively, at 71 requests against 52. The base row above comes from a run withLEAF_PREVIEW_COMPILER_ROOTpointing at an extracted base checkout. That checkout's compiler reproduces the base's committeddist/kernel/byte for byte.Tests run
pnpm run checkat950be482f: build check, 28test:browser, 669test:runtime(including 105 framework tests), and 85 Worker tests.tests/model/test_distribution.py, andtests/model -k "kernel or runtime_selection or distribution or vendor or layer"(299 passed).-n 4, at32643b1a8:tests/smoke, plus-kselections fromtest_render_application_boundary.py(presentation, preparation, readiness),test_render_outbox.py(undo, refusal, fail-soft presentation) andwidgets/test_timeline.py(36 passed).tests/smokepassed apart fromtest_ship_review_obligations_are_directly_answerable. That test asserts the kernel is served.tests/journeys/test_unused_exports.pyfails on five exports:hasUnread,tickLabel,tickStep,layoutLabelsandreadTimeline. It fails on the same five at the merge base (e55c9589a), so the failure is inherited. This PR adds no unread export: the bundle declarations joincontract.d.tsin its unchecked list.