fix: app.doc is dead; app.document is never assigned#115
Merged
Conversation
createApp built the app object with a `doc` field, but every other module (explain-graph.js, results.js, schema-detail.js, file-menu.js, shortcuts.js, app.js itself) read app.document instead — never assigned, so `app.document || document` silently always fell through to the global document. Rename app.doc -> app.document and drop the fallbacks that were provably unreachable; leave the ones intentionally tolerant of a null/minimal app (detached-view.js, explain-graph.js, schema-detail.js, and shortcuts.js — which has its own delete-app.document test) untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01784dKCpk5W7rdpUAwcQnix
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.
What & why
Closes #106.
createAppbuilt theappobject with adoc:field, but every other module in the codebase (explain-graph.js,results.js,schema-detail.js,file-menu.js,shortcuts.js, andapp.jsitself) readapp.documentinstead — which was never assigned.app.document || documenttherefore always silently fell through to the globaldocument. Harmless today only becauseenv.documentis unset in production and every test helper coincidentally passes the same globaldocument— but a footgun the injected-seam pattern (CLAUDE.md rule 2) exists to prevent.Fix:
src/ui/app.js:doc:→document: docin theappobject literal;renderApp'sconst { state, doc } = app→const { state, document: doc } = app; two internalapp.document || documentsites become bareapp.document(only ever called against the live, fully-built app).src/ui/file-menu.js(openFileMenu,openConfirm) andsrc/ui/results.js(openRowsViewer,expandDataPane,openCellDetail) — dropped the now-dead|| documentfallback, verified per call site against every caller insrc/andtests/(all go throughmakeApp(), which always setsdocument).app-tolerant, confirmed by dedicated tests):src/ui/detached-view.js,src/ui/explain-graph.js,src/ui/schema-detail.js, andsrc/ui/shortcuts.js(which has its owndelete app.documentregression test predating this issue).tests/unit/app.test.jsassertingapp.documentresolves to an injected custom document, not the global one.Test plan
npm test— 50/50 files, 1283/1283 tests pass, coverage gate holds.npm run build—dist/sql.htmlbuilds clean; verified the minified output correctly compilede.document.addEventListener(...)./code-review(3 parallel finder angles + verify) — zero findings.antalya.demo.altinity.cloud, vianpm run local+ Playwright/Chromium): ran a query, opened the File menu, opened a cell-detail drawer, and expanded a result into a real detached tab (a genuine seconddocument— the exact seam this fix targets). All three worked correctly with no regressions.Checklist
npm testpasses (the per-file coverage gate is non-negotiable)npm run buildsucceeds (single-filedist/sql.html)src/core/, network insrc/net/(injected fetch), DOM insrc/ui/CHANGELOG.md([Unreleased]) updatedinboxissue, not part of roadmap Roadmap to 1.0.0 #68's phased build order, so no Roadmap to 1.0.0 #68/ADR changes needed🤖 Generated with Claude Code
https://claude.ai/code/session_01784dKCpk5W7rdpUAwcQnix