Skip to content

Let the thread card grow, leave and return with its cluster, widen over its marker, and place through Floating UI - #1380

Merged
max-sixty merged 8 commits into
mainfrom
thread-card-geometry-review
Sep 28, 2026
Merged

max-sixty merged 8 commits into
mainfrom
thread-card-geometry-review

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

The margin thread card now follows the comment box's placement rules and places through the same engine. It picks a spot once and holds it relative to its margin cluster, grows its reply until the card fills the room, leaves with its cluster on a scroll and comes back with it instead of closing, and takes the room right of the text rather than only the rail beside its marker.

Motivated by a review of the card against the comment box: the card's reply box scrolled at a third of the card's height, a scroll closed the card mid-draft, and the card was narrower and more cautious than the comment box.

What changes for the user

  • The reply grows. The editor's cap is the card's room less three lines of the turn being answered, in place of a 35% share. A 32-line draft at 1440×900 went from 270px and scrolling to 654px.
  • A scroll carries the card away and back. While any of its cluster shows, the card stays whole inside the window. Past that it leaves by exactly as far as the cluster has gone, clipped under the banner and bottom band, and returns to the same place with focus and draft intact. A key pressed while it is away brings the cluster back. The card only leaves once its cluster has been on screen, and it measures against the layout viewport, so a phone keyboard does not carry it off.
  • The card holds still. It holds its foot while a reply is drafted and, while the thread is read, the edge toward its cluster (its top beside or under it, its foot over it). A turn arriving grows the card away from what it is about rather than lifting the words being read, and scrolling no longer changes the editor's height.
  • The card is wider. Its lane runs from the right edge of the words it is about to the window's edge, up to --thread-card (now 592px, the column's measure at the card's 14px type, was 380px). It stands over its own marker when it needs the room. At 1728px wide the card went from 380px to 488px. Where that lane is under the 320px minimum (windows under about 1390px with a 720px column), it still stands under or over its marker.

Placement through Floating UI

thread-card-geometry.js states the rule as pure arithmetic over client rectangles, tested in Node. The card runs it as its one Floating UI middleware, which carries the answer into the card's positioning space. That covers containing blocks, translated or scaled, frames and WebKit's pinch-zoom offset, none of which the card's own client coordinates handled. autoUpdate replaces the card's own scroll, resize, size and visual-viewport listeners.

The new runtime/floating.js is the one home both surfaces share: the lazily loaded bundle and floatingPlacement, the lifecycle around computePosition and autoUpdate. The comment box's own epoch and watch state moved there.

Placement is now asynchronous and lands before the frame paints. So neither surface waits on a fetch when first opened, the bundle (7 KB gzipped) loads right after the page presents, as a deferred arrival, rather than on the first response. Nothing loaded before presentation changes. If the bundle cannot load, the card closes, as the comment box withdraws, rather than standing open and unseen.

Tests

  • The runtime tests state each geometry rule: the lane, sliding over the marker, the hold and its edges, leaving and returning, the seen and keyboard cases, and a width change dropping the hold.
  • Browser tests cover:
    • editor growth, and the editor keeping its height through a scroll;
    • a read card keeping its top as a turn arrives, and a card over its cluster keeping its foot;
    • the card leaving and returning, and a key bringing it back;
    • a card under a translated, enlarged or shrunk containing block keeping its place and width, which fails on the pre-Floating UI code;
    • a card closing when the bundle cannot load.
  • Tests that asserted a scroll closes the card, the 35% share, or the card staying clear of its controls or of main's box now assert the new behavior. Clearance is now measured against the column's words (WORDS_RIGHT).
  • The startup tests now assert the bundle loads after presentation without holding it.
  • uv run pytest tests passes. The card's browser files fail only on cases that fail on main too.

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

🤖 Generated with Claude Code

max-sixty and others added 6 commits September 27, 2026 12:52
…, and hold its place

The margin thread card now follows the placement rules the comment box already
follows: it chooses a spot once and holds it relative to its cluster, grows from
the edge it holds until the visible boundary stops it, and leaves with its
cluster on a scroll instead of closing.

- The card keeps a hold on every placement, not only while its reply is
  drafted. It holds its foot while drafting and its top while being read, so a
  new turn scrolls in inside a card near the window's foot rather than lifting
  the words being read (the recommended answer to the open "card grows upward"
  gap). Switching edges moves nothing. A top chosen fresh is the spot's own,
  so a card opened low in the window rises back to its cluster once a scroll
  gives it room.
- A scroll no longer closes the card. The boundary clamp keeps the whole card
  in view while its cluster is in the window, then gives by exactly as far as
  the cluster has left, so the card leaves with it and returns to the same
  place, with focus and draft intact. It is clipped to the shown window, so it
  passes under the banner and bottom band. The clamp gives only for a cluster
  seen since the card was placed, so a card opened from words deep in a tall
  block stays in view, and a window resize re-arms that. The scrollport is the
  layout viewport (`shownWindow`'s new `viewport: "layout"`), so a phone
  keyboard shrinking the visual viewport keeps the card in what the user sees.
  A key pressed in a card that has left brings its cluster back first.
- The reply editor's cap is the card's room less three lines of the turn being
  answered (or the whole transcript where shorter), replacing the 35% share.
  An eight-line draft at 1440x900 went from scrolling at 165px to showing all
  its lines, and scrolling the page no longer changes the editor's height
  (165 -> 123px over 120px of scroll before, 180px throughout now).
- A newly selected thread in the card chooses its spot afresh.

Tests: the geometry's rules are runtime tests. Browser tests now assert that a
scroll carries the card away and back with focus kept, that a key brings an
away card back, that a drafting card's editor keeps its height through a
scroll, and that a read card keeps its top as a turn arrives; tests that
asserted a scroll hides the card, or the 35% share, now assert the new
behavior. `uv run pytest tests` passes (1450); the card's browser files pass
apart from failures that reproduce on the merge base.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…th needs it

The card's lane now runs from the right edge of the words it is about to the
visible edge, as the comment box's does, rather than from its margin marker.
It is as wide as that lane allows up to `--thread-card`, now 592px (the
column's 720px measure at the card's 14px face, up from 380px), and stands as
far right as that width lets it, so it clears its marker only where the lane
has room for both. A long thread at 1728px wide went from 380px beside the
marker, with the rail to its left unused, to 488px over it; at 1440 the card
stands beside the text at 344px instead of dropping under the marker at 320.
Where the lane is under the 320px minimum (windows under about 1390px with a
720px column) the card stands under or over its marker at the minimum, as
before.

The hold now records the card's width, and a placement at another width
chooses afresh: the card's words reflow, so neither held edge marks what the
user was reading or writing, and a held top would otherwise cap a card that a
narrower window made taller.

Tests: the runtime tests state the lane, the slide over the marker, and the
width change dropping the hold. Browser tests that asserted the card stays
clear of its controls or of `main`'s box now assert it stays clear of the
column's words (`WORDS_RIGHT`), and the ones at windows where the card used to
drop under a crowded or short rail now assert it stands beside the words over
the cluster.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… the comment box

The thread card worked out its spot in client coordinates and wrote them
straight to `left` and `top`, and followed its cluster with listeners of its
own: a document scroll listener, a size observer on the card, and window and
visual-viewport listeners. Client coordinates are the card's positioning space
only when no ancestor is a containing block, nothing is scaled, the page is not
in a frame, and WebKit is not pinch-zoomed, where a fixed box sits off its client
rectangle by the visual viewport's offset. Floating UI already handles each of
those for the comment box.

The card now places through Floating UI as the comment box does.
`thread-card-geometry.js` keeps the rule, unchanged and still pure arithmetic
over client rectangles, and runs as the card's one middleware, which carries
its answer into the card's positioning space by the distance Floating UI
measured between the cluster's client box and its box there. `autoUpdate`,
watching the thread's target, replaces the card's own listeners; the window
resize listener stays only to clear `seen`.

`floating.js` is the one home both surfaces share: the lazy bundle and
`floatingPlacement`, the lifecycle around `computePosition` and `autoUpdate`
(watch the element the box stands against, re-arm when it changes, and drop an
answer computed for an earlier placement). The comment box's epoch, cleanup and
watched-target state moved there.

Placement is now asynchronous, landing in the microtasks after the rendering
pass that asks for it and before the frame paints. So that the first card or
comment box a user opens does not wait on a fetch, the bundle (7 KB gzipped)
loads once the page has presented, as an arrival the page answers for
(`afterPresentation`), rather than on the first response. The requests and
bytes before presentation are unchanged.

Tests: a new browser test puts the card under a transformed ancestor and
checks it keeps its place beside its cluster; it fails on the previous card
code. The startup test that asserted the bundle loads only on a first response
now asserts it loads after presentation without holding presentation, and the
focus-wait test holds the bundle from the start of the page. `uv run pytest
tests --run-nightly` fails only on cases that fail on the merge base
(83a83e9) as well, plus preview-restart tests in test_render_export.py that
fail on both in varying subsets.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/margin-projection.js
#	tests/test_render_margin.py
… and let shortcuts pass an away card

Three findings from review of the move onto Floating UI:

- A failed Floating UI import left the card open with no position, invisible
  and still standing for the keyboard. It now closes, as the comment box
  withdraws, and the error surfaces. A startup test aborts the bundle and
  checks the card closes; it fails without the fix.
- A card placed over its cluster held its top while read, so a turn arriving
  grew it down across the cluster and the words it is about. Read, a card over
  its cluster now holds its foot, the edge toward its cluster.
- Any key in a card a scroll had carried away brought the page back, Escape,
  modifiers and shortcuts included. Those now leave the page where it is.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The coordinate conversion in threadCardMiddleware still assumes that client pixels and the card’s containing-block pixels have the same scale. With a scale(1.2) containing block around .lf-margin-preview, the card moves about 147px above its cluster and its rendered width changes from 584px to 701px; the new browser case covers translation only. The conversion adds a client-space delta directly to rects.reference (margin-projection.js), while --lf-thread-width and the height cap are also written in unscaled pixels. This breaks the PR’s claimed containing-block placement when the block is scaled. The card needs its position and dimensions converted into the containing block’s coordinate space, or a positioning root that cannot be scaled.

… block

The card's rule works in client pixels, and the placement carried its answer
into the card's positioning space by an offset alone. Under a scaled
containing block the card then stood off its cluster (147px above it at
scale(1.2)) and rendered wider than the rule measured it. The cluster's box in
the positioning space and its client box now give the scale as well as the
offset, and the card's position, measured width and height cap, held foot,
and clip insets are all written in that space.

The containing-block test now runs under a translation and a scale; the scale
case fails on the previous code.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The scaled containing-block path still loses the card’s requested width when the ancestor scales down far enough. measureThreadCard converts geometry.width into local pixels, but .lf-margin-preview caps that local width with min(var(--lf-thread-width, var(--thread-card)), calc(100vw - 16px)). At 1920×900 with a scale(0.2) containing block, the new browser case’s placement stays aligned but the card renders 380.8px wide instead of its original 584px. The added scale(1.2) case cannot reach this cap. Keep the viewport limit for the unplaced fallback, or express it in the same positioning space as the measured width, so a placed card can render the geometry’s client-space width.

A placed card's width is written in its own positioning space, and the card's
rule has already kept it inside the visible boundary. Capping it again at
`100vw - 16px`, a length in viewport pixels, cut it short under a containing
block scaled down far enough: at 1920px wide under scale(0.25) the card drew
380px wide instead of 584px. The viewport cap now applies only to the
fallback a card wears before its first placement.

The containing-block test gains a scale(0.25) case, which fails on the
previous stylesheet.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 39fe35c into main Sep 28, 2026
5 checks passed
@max-sixty
max-sixty deleted the thread-card-geometry-review branch September 28, 2026 03:02
max-sixty added a commit that referenced this pull request Oct 5, 2026
A placement design review found that the comment box and the thread card
share one rule for their side and line, but the card decided on its own
which edge to hold as its thread grows. That held-edge policy has been
reversed once and patched five more times (#1147, #1159, #1303, #1380,
#1429, #1453, #1552, #1574). This change gives it one owner.

- `comment-placement.js` now owns the policy (`holding`, `heldAt`,
`heldHeight`) for both surfaces. `margin-projection.js` reports what it
knows of the thread (the transcript's extent, whether the user is
drafting, the latest turn and the draft's words) and no longer keeps
`previewHold`. The logic moved verbatim. The comment box has no turns,
so it never asks.
- The "One writer for each fact" table in `skills/leaf/assets/AGENTS.md`
names the owners of comment placement and of margin-row seating, so a
change that decides either elsewhere shows up in review.
- Margin-entry labels measure their room through `shownWindow` instead
of reading `.lf-banner` and `.lf-shortcut-bar` themselves.
- Two TODO items whose tests already pass are removed: landing a sent
comment's thread where its box stood, and the composer on a page with a
margin on `html`.
`test_an_aimed_comment_keeps_its_place_with_the_asks_drawer_open` now
also runs at 1200px, the width that TODO described.

No user-visible behavior changes. An earlier commit on this branch also
moved the box's scrolled-away trigger into the shared module and applied
it to the card. That part came out when #1705 changed the box to follow
its passage out of view.

New runtime tests cover the held-edge policy. `npm run test:runtime`
passes. The focused browser tests for send placement, the comment box,
the margin card and replies pass, except three cases of
`test_a_thread_resolved_while_its_reply_is_written_keeps_the_user_on_it`,
which fail identically on `main`.

> _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.

2 participants