Skip to content

Misc Message Draft Fixes#58

Merged
AmethystLiang merged 3 commits intostablyai:mainfrom
TheOutdoorProgrammer:main
Mar 8, 2026
Merged

Misc Message Draft Fixes#58
AmethystLiang merged 3 commits intostablyai:mainfrom
TheOutdoorProgrammer:main

Conversation

@TheOutdoorProgrammer
Copy link
Contributor

@TheOutdoorProgrammer TheOutdoorProgrammer commented Mar 8, 2026

The message draft command had a few issues with it. I've fixed them all. This should permanently close #49.

Issue 1

Every \ in draft-editor.html's <script> block is/was escaped for some reason at some point using a double backslash(\\). In a JS regex literal, \\/ is parsed as \\ (literal backslash) followed by / (closes the regex) — the parser then tries to read the remaining code as regex flags and throws:

SyntaxError: Invalid regular expression flags

This kills all JavaScript on the page.

Issue 2

The send button in a draft message was always disabled. When initial text is provided editor.innerHTML = ... doesn't fire the input event, so updateSendBtn() was never called.

Issue 3

getEditorHtml() loads the HTML at runtime via readFileSync relative to import.meta.url. This works from source but fails after bundling (dist/index.js) or compiling (bun build --compile) because the HTML file doesn't exist at the resolved path:

ENOENT: no such file or directory, open '/$bunfs/root/draft-editor.html'

Fixed by replacing the runtime readFileSync with a static import ... with { type: "text" }, which Bun inlines into the bundle at build time. A sibling .d.ts file types the import as string since bun-types declares *.html as HTMLBundle (meant for Bun.serve HTML routes, not text imports).
Works for source, bun build --outdir, and bun build --compile.

Note: The import has a @ts-ignore because module: "ES2022" in tsconfig doesn't support import attributes syntax. Changing to module: "ESNext" would remove the need for it.. no behavioral difference since noEmit: true and Bun handles bundling regardless.

Style changes

It looks like draft-editor.html was added before oxfmt commit hooks. So I separated the style commit out so its an easier to read diff.

Commits

Commit What
fix: repair double-escaped regex patterns in draft editor \\\ in the <script> block + updateSendBtn() fix
style: format draft-editor.html (oxfmt) oxfmt reformatting (single→double quotes, etc.)
fix: inline draft-editor.html into bundle via static text import Replace readFileSync with static text import

Copy link
Contributor

@AmethystLiang AmethystLiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review (Claude)

Overall: Approve. Well-structured PR with clear commit separation and a thorough write-up. The three bugs are real and the fixes are correct.

Fix 1: Double-escaped regex (\\u2318\u2318)

Correct fix. The double backslashes were causing SyntaxError: Invalid regular expression flags which killed all JS on the page.

Fix 2: Send button always disabled

Correct. Setting innerHTML doesn't fire the input event, so updateSendBtn() was never called when initial text was present. Using requestAnimationFrame is the right approach to ensure the DOM has settled before checking content.

Fix 3: Static text import for bundling

Replacing runtime readFileSync with a static import ... with { type: "text" } is the right call — lets Bun inline the HTML at build time and fixes the ENOENT after bundling/compiling.

Minor observations:

  • getEditorHtml() is now a trivial wrapper (return _editorHtmlContent) — could be inlined into buildEditorHtml() in a follow-up.
  • The @ts-ignore is well-documented. Worth considering module: "ESNext" in tsconfig later to remove it.

Ship it.

@AmethystLiang AmethystLiang merged commit 2a6a9e5 into stablyai:main Mar 8, 2026
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.

v0.5.0 binary crashes on startup: missing draft-editor.html in Bun bundle

2 participants