Skip to content

Serve the browser framework as written, in JavaScript with JSDoc types - #4184

Merged
max-sixty merged 5 commits into
mainfrom
framework-as-js
Oct 26, 2026
Merged

max-sixty merged 5 commits into
mainfrom
framework-as-js

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

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, and framework/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 .js files, 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 presentation module, then read the serving runtime with no build.

identity serves kernel served module carries the edit
base, before edit (browser/framework/presentation.ts) 442564cd0d3662b1 yes no
base, after edit 442564cd0d3662b1 (unchanged) yes no
this branch at 950be482f, before edit (browser/runtime/framework/presentation.js) 081b6d3fe2e736f7 yes no
this branch, after edit 68ee527de447ba80 no, source modules yes

What the type check keeps

The framework was strict TypeScript, and it stays strict. The type check's home is now browser/types/, since browser/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, so strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes and noUnusedLocals still apply. Nothing used to enforce that pragma, so build/browser/build.mjs now refuses any module under runtime/framework.js or runtime/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:browser refuses a pragma-less browser/runtime/framework/extra.js and names it.
  • pnpm run check:browser fails on a deliberate type error in presentation.js (TS2345).
  • tsc failed on an unchecked index in snapshot.js (TS2532, noUncheckedIndexedAccess).
  • The compile-only regression domain.test.ts is now browser/types/domain.test.js. Its @ts-expect-error and IsAny checks fail when Event is typed any.

Declarations with no JavaScript home stay .d.ts:

  • domain.ts held only types, so it is now browser/types/domain.d.ts.
  • The framework imports Lit and signals by served path (/vendor/lit.js, /vendor/signals-core.js), and those minified bundles carry no types. The generated tsconfig.paths.json maps the served paths to declarations of the packages they bundle. The build writes lit.d.ts from the namespace build/lit.mjs bundles (litNamespace), every public Lit module and static-html's renamed tags, and check:browser holds it to that, so when, unsafeSVG and staticHtml type as main typed them. signals-core.d.ts is four hand-written lines naming the two packages the signals bundle holds.
  • Packages that import /vendor/lit.js now get Lit's own types too. That flagged an undeclared expando (event.step) in lf-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. currentWidgetRelations reads memberships.get(x)![attr]! through a small members helper that throws in the same cases, and selectWidget names inputs before the callback in place of inputs!.

What it deletes

  • The compiled copy, browser/vendor/browser-runtime.js and browser/vendor/browser-runtime/{application,presentation,snapshot}.js: 2,670 lines.
  • The compile step and its import rewriting in build/browser/build.mjs (−96 net), with the amaro dependency (package.json, pnpm-lock.yaml).
  • The test that the compiled output kept source lines, and the // Generated from trailer lookup in tests/js_facts.mjs that 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.js is gone, the framework now sits in bundle-context.js, and the signals share a new chunk, bundle-signals-core.js, with queued-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 modules import the facade as /runtime/framework.js. The vendor/browser-runtime content-module rules in eslint.config.mjs are gone, since the /runtime/ rules already cover the facade. semanticStoreOwnershipRule still refuses deep imports into framework/. It no longer requires the served path, which existed only because a relative path reached the compiled facade's blanked types.
  • focus.js is a primitive that may import only vendor bundles and other primitives. It now takes signal from /vendor/signals-core.js, because the facade no longer sits under vendor/ and reads as the runtime owner it is.
  • .dependency-cruiser.mjs excludes /runtime/framework.js by name, as it excluded the facade under /vendor/. The framework's own modules are checked as owners.
  • The framework's Node tests move to tests/runtime/framework-*.test.mjs, which test:runtime runs, because the served modules import site-absolute /vendor/ paths that tests/runtime/dom.mjs resolves. The publisher tests in build/browser/build.test.mjs join framework-snapshot.test.mjs.
  • The third-party notices browser-runtime.LICENSES.txt become lit.LICENSES.txt and signals-core.LICENSES.txt, one per served bundle.

Packages that replaced the framework

packages.md documents packages replacing a kernel vendor module. The framework was one: a package's vendor/browser-runtime.js replaced the facade, and the kernel then stood aside. That no longer works. The framework is a runtime module now, and kernel_runtime_paths() refuses a package that replaces one. A package vendor/ file at /vendor/browser-runtime.js is now an unrelated module nothing imports. The signals bundle a package could replace moved from vendor/browser-runtime/signals-core.js to vendor/signals-core.js. A custom package that imported /vendor/browser-runtime.js also breaks. No bundled package did either, ESLint refused the import, and widget-api.js is 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), from leaf-dev probe <page> --base at 32643b1a8. The later commits change no module's code, only comments and types. Each arm ran the kernel its own build commits:

page arm requests bytes JS requests JS bytes
release-notes base 52 3,234,121 45 2,509,343
release-notes this branch 52 3,234,007 45 2,509,042
triage-board base 43 2,954,080 38 2,375,389
triage-board this branch 43 2,953,966 38 2,375,088

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 --base run misreports this change. leaf-dev probe --base compiles the base arm's kernel with this checkout's build/runtime-bundle.mjs (distribution.prepare). That compiler no longer knows vendor/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 with LEAF_PREVIEW_COMPILER_ROOT pointing at an extracted base checkout. That checkout's compiler reproduces the base's committed dist/kernel/ byte for byte.

Tests run

  • pnpm run check at 950be482f: build check, 28 test:browser, 669 test:runtime (including 105 framework tests), and 85 Worker tests.
  • tests/model/test_distribution.py, and tests/model -k "kernel or runtime_selection or distribution or vendor or layer" (299 passed).
  • Browser, -n 4, at 32643b1a8: tests/smoke, plus -k selections from test_render_application_boundary.py (presentation, preparation, readiness), test_render_outbox.py (undo, refusal, fail-soft presentation) and widgets/test_timeline.py (36 passed).
  • With the kernel made stale, so pages ran the framework from source, tests/smoke passed apart from test_ship_review_obligations_are_directly_answerable. That test asserts the kernel is served.
  • tests/journeys/test_unused_exports.py fails on five exports: hasUnread, tickLabel, tickStep, layoutLabels and readTimeline. 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 join contract.d.ts in its unchecked list.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 4 commits October 25, 2026 21:59
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
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
@max-sixty
max-sixty merged commit 191465f into main Oct 26, 2026
5 checks passed
@max-sixty
max-sixty deleted the framework-as-js branch October 26, 2026 06:10
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_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A framework TypeScript edit reaches pages without a build

2 participants