Skip to content

Draw a data-reading element only once the page's data has been read - #3843

Closed
max-sixty wants to merge 2 commits into
mainfrom
grind/s-text-document
Closed

max-sixty wants to merge 2 commits into
mainfrom
grind/s-text-document

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

this.data(input) returned null both before the first state answer and for a source with nothing in it, so every data-reading widget had to guess. lf-text-document guessed "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 LeafElement already has for a widget's declared verbs. A LeafElement whose tag declares x-data now draws nothing until the page's data has been read (dataDelivered() in data.js: the data version has arrived, or the page has settled offline). null therefore always means a source with nothing to read. lf-text-document needs no change, and module-state.md states 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 turns ready at 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):

viewport base layout shift this change
1440x900 0.108 0
390x800 0.196 0

Tests run: pnpm run test:runtime (545 pass); new test_a_text_document_is_never_drawn_before_its_text_arrives (fails on base, passes) and test_a_text_document_whose_page_never_reaches_its_server_reads_no_data in test_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.py and test_workspaces_and_bounds.py pass, except test_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.

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

max-sixty and others added 2 commits October 24, 2026 20:21
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]>
@max-sixty max-sixty changed the title Hold a text document's listing until the first state answer Draw a data-reading element only once the page's data has been read Oct 25, 2026
@max-sixty

Copy link
Copy Markdown
Owner Author

Superseded by #3929, which makes the same core change for source-bound widgets only and includes this PR's offline handling.

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

@max-sixty max-sixty closed this Oct 25, 2026
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]>
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