Repository navigation
Conversation
A document's source reads null both before the first state answer and for a source with nothing to read, so lf-text-document drew a one-row "no data" frame at upgrade; the gutter widened and the code column moved when the text arrived. The widget now draws only once the text is read or the reading phase has left "waiting", so the theme's stand-in frame stays until then. The phase is the signal the widget API already offers (readObligations().phase, as lf-tally uses it); no new primitive, since data readers and the phase share one root and module-state.md now says so. Probe on a 20-line, 3-line and markdown-preview page: layout shift 0.108 -> 0 at 1440px and 0.196 -> 0 at 390px. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Rework: the gap is in core, not in one widget. this.data() returned null both before the first state answer and for a source with nothing in it, so every data-reading widget (lf-text-document, lf-diff, lf-trace, ...) had to guess. A LeafElement whose tag declares x-data now draws nothing until the data version has arrived or the page has settled offline (dataDelivered in data.js), beside the existing gate that waits for every declared verb. null therefore always means a source with nothing to read; lf-text-document needs no special case, and module-state.md states the rule once. The gate is keyed on the data version itself, so it no longer matters that the state phase turns ready before the data readers are notified. A page that never reaches its server settles offline and reads no data rather than waiting. Layout shift on a 20-line, 3-line and preview page: 0.108 -> 0 at 1440px and 0.196 -> 0 at 390px. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Owner
Author
|
Superseded by #3929, which makes the same core change for source-bound widgets only and includes this PR's offline handling.
|
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
…t arrives The runtime test drives a synthetic element and calls acceptData itself; this one reads the real page startup, where the state feed brings the text, and fails without the shouldUpdate gate. Ported from the closed #3843. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
An `lf-text-document` drew its listing as soon as its module upgraded, before the first state answer brought its text: one empty row under a caption ending "· no data". When the text arrived, the gutter widened for two-digit line numbers and the code column moved right inside the box, and a long label that "· no data" had wrapped onto a second line shortened the box. The cause sits in `LeafElement`, not the module. Widgets upgrade before the state feed's first answer is applied (`browser/AGENTS.md`, "Startup and presentation"), and until then `this.data(input)` returns `null`, the same value it returns for a source that holds nothing. Every widget bound to a source therefore drew its empty reading first: the text document's "no data" listing, `lf-call-diff`'s "Waiting for call-diff data.", an empty file tree. A `LeafElement` bound to a page data source now draws nothing until the page has accepted its first data reading (`awaitsData` in `data.js`, gated in `shouldUpdate` beside the missing-verb gate, whose claim settles the same way with nothing drawn). The theme's first-paint box stands until then, and the acceptance draws the element with the accepted reading, as any element's first read takes it. An input bound to another widget's output, or a declared source the element doesn't name (an `lf-diff` with inline text), waits for nothing. `module-state.md` says so for package authors. A page whose first read brings no state settles offline (`phase` "offline"), and its elements draw then, so a text document says "· no data" rather than keeping the stand-in box. Evidence: `leaf-dev probe` on a page holding a 20-line, a 3-line and a Markdown preview document scores the arrival 0.13 of layout shift at 1440×900 and 0.21 at 390×844 on main, and 0 at both with this change; in Firefox all three documents draw their lines and captions. `tests/runtime/data-unread.test.mjs` fails on main (the bound element draws `no data` before any data is read) and passes with this change; it also fails without the offline settle. Supersedes #3843 (closed), which gated every `x-data` element the same way; this one gates only elements bound to a page source (an input bound to another widget's output, or an `lf-diff` with inline text, draws at once). From #3843 it takes `test_a_text_document_is_never_drawn_before_its_text_arrives` in `tests/browser/startup/test_projected_data.py`, which watches a real page's startup and asserts no caption or listing appears before the state feed brings the text. The runtime test drives a synthetic element and calls `acceptData` itself, so only the browser test covers the real `lf-text-document` declaration and the state feed's order; it fails with the `shouldUpdate` gate removed and costs one page opening. #3843's offline browser test is left out: the runtime test covers the offline settle, and that test failed in #3843's CI on an `/api/state` console error. Ran: `pnpm run test:runtime`, the widget quality checks (`test_a_widget_first_paints_the_box_it_presents`, `test_an_export_first_paints_its_widgets_at_their_presented_boxes`, `test_bundled_widgets_meet_the_widget_quality_checks` for every package), and focused data and widget tests in `test_projected_data.py`, `test_code_and_documents.py`, `test_render_export.py`, `test_render_playwright_trace.py`, `test_visual_review.py` and `test_render_diff_controls.py`; `pnpm run build:browser` for the kernel. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
this.data(input)returnednullboth before the first state answer and for a source with nothing in it, so every data-reading widget had to guess.lf-text-documentguessed "no data": it drew a one-row listing at upgrade, then widened the gutter and moved the code column when the text arrived.The fix is in core, beside the gate
LeafElementalready has for a widget's declared verbs. ALeafElementwhose tag declaresx-datanow draws nothing until the page's data has been read (dataDelivered()indata.js: the data version has arrived, or the page has settled offline).nulltherefore always means a source with nothing to read.lf-text-documentneeds no change, andmodule-state.mdstates the rule once. The theme's stand-in frame and caption stay until the data arrives.The gate is keyed on the data version itself, so the order in
state-application.js(state phase turnsreadyat adopt, data readers are notified afterwards) no longer matters. A page that never reaches its server settles offline (statePhase"offline") and draws "no data" rather than waiting; an interactive export carries its data in the first state it applies.Evidence (
uv run leaf-dev probe <fixture> --base --viewport WxH; fixture: 20-line, 3-line and markdown-preview documents):Tests run:
pnpm run test:runtime(545 pass); newtest_a_text_document_is_never_drawn_before_its_text_arrives(fails on base, passes) andtest_a_text_document_whose_page_never_reaches_its_server_reads_no_dataintest_projected_data.py; that file,test_code_and_documents.py,test_render_export.py,widgets/test_diffs.py,test_render_playwright_trace.py,test_render_visual_review_journey.pyandtest_workspaces_and_bounds.pypass, excepttest_workspace_root_scrollbar_appears_only_when_page_overflows, which fails identically on the base. The kernel is rebuilt (pnpm run build:browser). Not verified: Firefox,pnpm run check, long-label wrap, file-tree tests.Removes the item from
TODO.md.