Repository navigation
Use Floating UI for thread previews - #551
Conversation
…-comments # Conflicts: # skills/leaf/assets/runtime/chrome-layout.js # skills/leaf/assets/runtime/composing/selection.js # skills/leaf/assets/runtime/composing/surface.js
…-preview # Conflicts: # scripts/vendor.py # skills/leaf/assets/vendor/floating-ui.esm.js # tests/test_render_aim.py
leaf-agent
left a comment
There was a problem hiding this comment.
Two findings, both reproduced against this head and against the merge base (2a67f0d6).
The overlay placement collapses the card to zero width when the source control has no box. tests/test_render_navigation.py::test_the_thread_walk_stays_inline_until_threads_is_opened passes at the merge base and fails here — it is a test_render_* nightly file, so the PR gate never selects it and ci is green. At 600×844, after the walk moves to the second thread, the margin control's getBoundingClientRect() is 0×0 at the origin. bottom-end against that live element puts the card at x = -460, 468px outside boundary.left; size runs before shift, so it takes the noShift branch, subtracts that overflow and reports availableWidth: -8, and the apply clamps --lf-thread-width to 0px. shift then returns the card to left: 8px, but the width is already gone: the card paints as a 26px sliver of padding in the top-left corner and .lf-conversation-msg measures 0 wide, which is the assertion that fails. The side-lane branch is immune because it hands Floating UI a virtual reference, so the engine cannot contradict the lane; the overlay branch hands over the live element and loses that protection. The old code never read the element — it clamped left from target.right - width into [firstLeft, lastRight - width], so a degenerate target still produced a full-width card at a sane position.
A failed lazy module now leaves the card open, invisible, inert, and holding focus. With **/vendor/floating-ui.esm.js aborted and t pressed, this head reports {open: true, opacity: '0', pointerEvents: 'none', left: '', placement: null, focusInsideCard: true} and a repeating TypeError: Failed to fetch dynamically imported module; the merge base reports {open: true, opacity: '1', pointerEvents: 'auto'} with no page errors. resetThreadPreviewPosition sets the opacity and pointer-events gate, and only the resolved .then clears it, so any rejection strands the reader with focus inside a card they cannot see. composing/surface.js already answers this for the response surface with a .catch that withdraws the surface and returns focus, and tests/test_render_startup.py::test_an_unavailable_floating_ui_module_withdraws_the_response states the contract as "A failed lazy module cannot leave a hidden live composer holding focus."
One smaller seam behind both: preview.style.opacity now has two owners. scheduleThreadTransition sets it to "0" and clears it unconditionally on the next frame, while resetThreadPreviewPosition sets the same property and only a resolved placement clears it. On a transition-opened card the frame callback removes the opacity before computePosition resolves, so the card can paint at whatever style.left/style.top the previous card left behind — nothing at all on the first open of a session.
…ntracts (#582) The scheduled complete suite came back **38 failed, 2393 passed, 6 skipped** on [run 34562158190](https://github.com/max-sixty/leaf/actions/runs/34562158190). Ten of those are already repaired by #576, #579 and #580, which merged after that run started. This realigns eight more, all of them tests stating a contract a recent change deliberately replaced without running the nightly file that names it. ## The preview places itself before it hands over focus #551 replaced the thread preview's placement engine with Floating UI and made the lifecycle asynchronous: `deferThreadPreviewFocus` waits on the placement promise and focuses the card from it. Three tests read `document.activeElement` in the same turn as the press that opens it, so they see the page rather than the conversation. Bisecting `test_a_tap_on_a_quote_opens_its_thread` across `013f3c44..692032a` names 24f4efc as the first bad commit, and a probe on `main` shows the conversation arriving on the poll after the press. `conversation_a_press_opened` states that ordering once for the three of them. It keeps each test's own failure message — the wait answers None rather than raising, so a press that opens the wrong conversation still reports which one it opened, which is the whole point of the seam fixture. ## The compact card reveals its reply box on request #574 made the popover compact: Reply appears when asked for or when a draft exists, and the card's accessible name became "Conversation for …". So `test_pressing_the_current_element_mark_keeps_its_contour` waited 30s for a `textarea` the card no longer shows — the paint it asserts is the same either way — and `test_a_drawing_can_be_sent_without_words` looked for a dialog named "Thread for …". That test held the only remaining reading of the old wording. ## Settlement reads `responds` #561 made an agent reply settle a reader's word only by naming it in `responds`, and made `leaf reply` require exactly one of `--for` and `--initiates`. Three fixtures pre-date both: one invokes the CLI with neither flag, and two append a reply event that the projection then reads as unanswered, so the receipt and the neighbouring-page row stay where the test expects them to move on. Other hand-written reply fixtures do not assert settlement and are left alone. ## Verification - Complete `tests/test_render_anchors.py`: **3 failed, 92 passed**. The three are the response-bar and widget-text cases #547 already tracks. - Complete `tests/test_render_drawing.py` and `tests/test_render_controls.py`: **3 failed, 114 passed**. All three fail on `main` without this branch — two are in #547's scope, and `test_each_control_archetype_holds_its_neighbours_still[diff-review]` is a thirty-ninth failure that arrived on `main` after the run above. - `pre-commit run --files` over the three changed files: passed. The rest of the run's failures stand. #547 carries them, and I have refreshed it with what this run and `main` now show. Co-authored-by: leaf-agent <[email protected]>
The thread-preview card had accumulated a separate placement engine for measuring height, choosing page lanes, avoiding its source cluster and bottom chrome, and detecting detachment. Now that Floating UI is already vendored for comment placement, this reuses it for the preview card too.
Leaf still chooses the right page lane before the left and retains its source-cluster, bottom-chrome, focus-scrolling, scheduler, and seen-then-detached behavior. A virtual reference expresses the selected lane or overlay geometry; Floating UI handles flipping, sizing, shifting, clipping, and reference visibility. A failed lazy import withdraws the hidden preview and restores focus. The existing vendor build now exports
hide.Placement completion is also part of the preview lifecycle: compact overlay references shift below the banner, focus remains on the prior visible surface until the current geometry lands, workspace restoration uses the same handoff, and the new-comment transition reads its destination only after that placement. Same-thread rerenders can supersede an in-flight computation without resolving focus against stale geometry.
This removes the custom height cache and above/below candidate arithmetic.
living-margin.jsremains approximately line-neutral because the lazy asynchronous lifecycle and virtual lane representation replace that code, so the gain is one geometry implementation rather than fewer source lines.Validation:
uv run pytest tests— 1,008 passed on the final tree merged with currentmainmainunder the same two-worker setup