Skip to content

Add design doc for the browser JS module refactor - #503

Merged
stevedekorte merged 1 commit into
masterfrom
docs/js-module-refactor-plan
Aug 29, 2026
Merged

Add design doc for the browser JS module refactor#503
stevedekorte merged 1 commit into
masterfrom
docs/js-module-refactor-plan

Conversation

@stevedekorte

Copy link
Copy Markdown
Member

Design doc only — no code changes.

browser/io.js is 1071 lines: 1-889 are library, 891-1071 are the REPL app. The layering is already sound, and there is exactly one edge from the core into the DOM, at line 774. The doc describes cutting that seam so the VM can be embedded, and eventually published to npm.

Covers the five things that block library use (no exports, module-level singletons, parse-time config, the DOM edge, browser-only loading), the proposed file layout and Io class API, the three changes that do the work, and the hazards found while reading the current code.

One of those is a real bug rather than a smell: flushCallbackOutput returns early when there is no #output element, so output printed from inside Io callbacks is silently discarded for any embedder. Inverting the line 774 edge fixes it.

Also worth flagging: the core becomes instantiable from bytes with no DOM, so most of test.html could become a plain Node test and make check-browser would stop needing Playwright/Chromium for anything but genuine in-page behavior.

All line references in the doc were verified against the current file.

🤖 Generated with Claude Code

browser/io.js is a REPL page script with no exports, so the VM cannot be
embedded in another page without copying files by hand. The doc describes
turning it into an importable module: the file layout, the proposed Io
class API, the three changes that cut the seam, and the hazards found
while reading the current code.

Notes one real bug: output printed from inside Io callbacks is silently
dropped when there is no REPL #output element, because ioSend reaches
into the DOM through flushCallbackOutput.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@stevedekorte
stevedekorte merged commit e1371f0 into master Aug 29, 2026
1 check passed
@stevedekorte
stevedekorte deleted the docs/js-module-refactor-plan branch August 29, 2026 05:03
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.

1 participant