Skip to content

Every content edit to an lf-diagram or lf-diff needs a hand-copied data-height and another check run #3174

Closed as not planned

Description

@max-sixty

Use. An agent building a page unattended, with an lf-diagram and several lf-diffs, edits their content as the page develops.

What happened. These widgets reserve no height before they draw (page-layout.md). After each content change, page check --render reported unreserved-height advice naming the drawn height, and the agent copied each number into data-height and ran the check again. One page took three of these edit-and-check rounds, and any later content edit starts another.

Cost. The check already has the right number, so the agent's step is a transcription plus a second render. An agent that skips the advice ships a page whose content jumps as each widget draws.

Proposed shape. Have Leaf set the reservation instead of the author. Either page check --render (or page stamp) writes the measured data-height into the source, or Leaf records the measurement with the revision so the widget reserves it without an authored attribute. An authored data-height still wins.

Seen on leaf 28c8d33, installed 2026-10-19T07:54:45-07:00.

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

Activity

  1. added
    enhancement
    on Oct 19, 2026
  2. leaf-agent commented on Oct 19, 2026

    @leaf-agent
    Collaborator

    The render check already measures the settled widget box and reports its difference from first paint; delivery reserves height from the widget declaration or an authored data-height. The repeat-edit case needs Leaf to distinguish a measured reservation from an authored one. If a check simply inserts data-height, the next content edit leaves no way to tell whether that value should be refreshed or preserved as the author’s override.

    The clean direction is a measured value tied to the candidate revision and applied by delivery only when the author has not set data-height. That keeps the author’s override and lets a new measurement replace an old one after an edit. It also means deciding when a browser measurement becomes part of a revision, since page stamp currently validates source without rendering. I did not open a PR: a source-only rewrite would recreate the reported loop after the next edit, while revision-scoped measurement crosses the render check, revision capture, and delivery contracts.

  3. max-sixty commented on Oct 25, 2026

    @max-sixty
    OwnerAuthor

    Reopening for lf-diagram, which #3984's Closes swept up but didn't fix. #3984 settled lf-diff: an inline-patch diff now first-paints at its drawn height through a 1.4 KB counting script, and authors no longer write data-height for it.

    lf-diagram still needs a hand-copied data-height, and quick pages, which skip --render, still shift when one draws. A count can't help there, because the height comes from Pele's layout. The direction from triage: a diagram's drawn height is a pure function of its source text, since it renders with responsive: false and isn't width-dependent. So the render check can record each diagram's measured height keyed by a digest of its source, and delivery can apply it wherever no data-height is authored. An edit changes the digest, so an old height stops applying.

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

  4. leaf-agent commented on Oct 25, 2026

    @leaf-agent
    Collaborator

    The source-only cache key needs one correction: responsive: false removes width dependence, but the height also depends on font metrics. Leaf passes the page’s --sans and --mono into Pele. In Chrome, the identical source below rendered at 301px with sans-serif and 245px with monospace, with responsive: false in both calls. A circular node makes text width affect height.

    A reusable measured reservation therefore needs to be scoped to its renderer and font environment as well as its source; an authored data-height can still take precedence. There is also a cold-cache limit: recording heights only during --render removes the transcription step after that check, but cannot reserve a new or edited diagram on a quick page that has never measured that source. That case remains part of this issue rather than being closed by the cache alone.

    Reproduce the font-dependent height

    Run this expression with leaf-dev probe security-boundary --js in this checkout. It calls the page’s vendored Pele renderer with the widget’s sizing options:

    async () => {
      const { parse, render } = await import('/vendor/pele.esm.js');
      const source = 'flowchart TD\nA((WWWWWWWWWWWW)) --> B[end]';
      return ['sans-serif', 'monospace', 'serif'].map(fontFamily => {
        const { height } = render(parse(source), {
          fontFamily, fontFamilyMono: fontFamily, fontSize: 14,
          padding: 16, responsive: false, links: false, images: false,
        });
        return { fontFamily, height };
      });
    }

    Observed heights: 301, 245, 301. No code change or PR from this run; this establishes a missing cache dependency before implementing the proposed reservation.

  5. leaf-agent commented on Oct 28, 2026

    @leaf-agent
    Collaborator

    The remaining product choice is what a quick page should do when a diagram has no measurement yet. The existing first-paint route has a concrete cost here: x-initial producers run synchronously and are inlined in the document head, whereas the diagram renderer waits for fonts. Moving the existing drawing into that route would put Pele ahead of the body and would also need an answer for fonts that are still loading. The current committed Pele file is 689,892 bytes, or 256,293 bytes when gzipped; those are bundle sizes, not a measured startup regression.

    A font-scoped measurement cache can remove the transcription after --render, as already proposed, but settling the quick-page case additionally requires choosing where the first measurement is paid: automatically render during authoring even when --render was omitted, or wait for layout and fonts before exposing the affected reading content in the viewer. Those change the quick-authoring or first-paint behavior respectively. I’m leaving this open for @max-sixty’s direction on that cache-miss behavior; no PR from this run, and the cache proposal remains a partial repair rather than a resolution of the whole issue.

  6. max-sixty commented on Nov 5, 2026

    @max-sixty
    OwnerAuthor

    Closing as obsolete. The loop this reports (the render check names a drawn height, the agent copies it into data-height, reruns) can no longer happen: #4724 removed the unreserved-height finding with the initial-render producers and deliberately accepted one content-derived resize when a widget upgrades. lf-diff was settled by #3984; lf-diagram's first-draw shift now sits under #4724's call, and the open cache-miss question in the last comment presumes a mechanism nothing on main builds.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions