Skip to content

fix: keep a details toggled twice within a frame where the second toggle left it - #7515

Merged
leaf-agent merged 4 commits into
mainfrom
fix/issue-7509
Nov 28, 2026
Merged

leaf-agent merged 4 commits into
mainfrom
fix/issue-7509

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Effect UI treats a details' open as controlled and writes the Model's value back one animation frame after each toggle. When the user toggled the same details again before that frame, the write-back undid the second toggle, and the browser merged its queued toggle into one reporting no change, so the Model never heard of it. That dropped the second of two quick presses on lf-call-diff's roots and lf-toc's contents disclosure, which both draw through Effect UI and keep open in their Model.

A pnpm patch to Effect UI's host (build/@effect__ui.patch, applied the same way as the existing Plot and Pierre patches) records the state each node's latest toggle reported. Its restore skips a details whose open differs from that state, because a toggle for that node is still queued and its own restore follows once the Model hears it. A Model that refuses the toggle still gets its value written back on that later restore. Dialogs and popovers take their own restore branches and are untouched. The only rebuilt bundle is browser/vendor/effect-ui.js. The patch should go once Effect UI ships the fix upstream. Effect-TS/ui isn't taking issues while it moves into the Effect monorepo, so nothing has been filed there.

test_a_second_toggle_before_the_next_frame_holds presses a call-tree root twice, with the second press in a frame callback that runs just before Effect UI's write-back. It then waits for the second toggle and a frame its listener queues, which runs after the restore Effect UI queued for that toggle, asserts the event reports the press's own change, and reads open once after rendered. It failed 4 of 4 runs on the unpatched bundle, each at the event's state, and passed 5 of 5 with the patch. test_render_toc_disclosure.py on Chromium (14) and pnpm run test:runtime (1237) pass.

This also removes the rendered waits #7510 added to test_evidence_close_folds_room_but_retires_controls_immediately and its comment explaining them, which described the race this patch fixes. That test again presses each toggle right after the last, and it passed 3 of 3 on Chromium and Firefox after the removal.

Closes #7509 — automated triage

…gle left it

Effect UI writes the Model's `open` back onto a controlled `details` one
animation frame after each `toggle`. A second toggle made before that frame
was overwritten, and the browser merged its queued `toggle` into one that
reported no change, so lf-call-diff's roots and lf-toc's contents disclosure
dropped the second press without a sign.

A patch to Effect UI's host records the state each node's latest `toggle`
reported, and its restore skips a `details` whose `open` differs from it,
since that node's `toggle` is still queued and its own restore follows.
test_a_second_toggle_before_the_next_frame_holds fails on the old bundle and
passes with the patch.

Closes #7509
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The rapid-toggle regression reads d.open after two animation frames and setTimeout(..., 50). tests/AGENTS.md excludes a fixed frame count or elapsed time as proof that an independently queued operation finished. If the second toggle task is still pending, the unpatched implementation can transiently show the expected value. Please keep the deliberate frame that injects the second click, then observe its toggle event and the corresponding host restore/render completion before asserting.

This was written by Codex on behalf of max-sixty

…e-toggled fold

The rapid-toggle regression read `open` after two frames and a 50 ms timeout,
which an unfinished second toggle could pass. It now waits for the second
`toggle` event and a frame queued in its listener, which runs after the restore
Effect UI's capture listener queued for it, asserts that event reports the press's
own change, and reads `open` once after `rendered`.

On the unpatched bundle it fails 4 of 4 runs at the event's state; with the patch
it passes 5 of 5.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Done in 32fd818. The frame that injects the second click stays. The test no longer reads d.open after fixed frames and a timeout:

  • It waits for the second click's own toggle event. That listener queues one frame. Effect UI hears toggle in a capture listener on its container and queues that toggle's restore there, so this frame runs after the restore. The test polls for it with wait_for_function and the suite's deadline.
  • It asserts that event's newState is the state the second press asked for. Without the patch, the write-back merges the event into one reporting no change.
  • It waits for rendered so the Model's render of what it heard has run, then reads open once instead of retrying with expect.

On the unpatched bundle it failed 4 of 4 runs, each at the event's state ('closed' == 'open'). With the patch it passed 5 of 5. I also removed the stray second import pytest above the test and updated the description's test paragraph.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This PR fixes the race that the comment above test_evidence_close_folds_room_but_retires_controls_immediately's waits describes ("Effect UI writes the Model's open back in the frame after a toggle event, which undoes a toggle made before that frame"). Once it lands, that comment is false about the bundle Leaf ships. The description calls the waits harmless, but AGENTS.md, "Where instructions live", asks the tree to say what holds now. A reader would also take those four rendered(page) waits as still necessary and copy them into new tests. The description reports 4 of 4 passes without them, so I'm removing #7510's comment and waits in this PR. Each toggle in that test then follows the previous one immediately, the way a user's presses can.

…necessary

test_evidence_close_folds_room_but_retires_controls_immediately again presses
each toggle right after the last, as a user can. The comment that explained the
waits described the write-back race this branch fixes, so it no longer held.
@leaf-agent
leaf-agent merged commit afb9b9d into main Nov 28, 2026
9 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-7509 branch November 28, 2026 08:48
leaf-agent added a commit that referenced this pull request Nov 28, 2026
…raws before its toggle (#7522)

Effect UI writes a `details`' controlled `open` from two paths: the
restore one frame after a `toggle`, and the render each message brings.
#7515's patch (`build/@effect__ui.patch`) taught only the restore to
wait while a press's `toggle` is still queued. A render in that gap
still writes the Model's older `open` back. That undoes the press, and
the browser merges the queued event into one reporting no change, so the
Model never hears of the press. In
`test_call_diff_projects_stable_commentable_rows`, the test folds the
call tree's root and presses Enter on the root's location. When the
Enter lands before the fold's `toggle`, the location's message redraws
the tree and reopens the root. That is #7521's failure.

The patch now sends both paths through one guard, `writeOpen`. It skips
a `details` whose `open` differs from the state the host last knew for
it. It also records each value the host writes or finds, so a node's
first press is covered too. A Model that refuses a press still gets its
value written back by the restore that the press's `toggle` brings.
Dialogs and popovers take their own branches and are untouched. The only
rebuilt bundle is `browser/vendor/effect-ui.js`.

**Verification.** The new test
`test_a_fold_redrawn_before_its_toggle_holds` folds a root and presses
its location in one task, which forces the redraw ahead of the `toggle`.
It failed 2 of 2 on main's bundle, where the `toggle` reported `open`,
and it passes with the patch. The bundle from before #7515 fails the
same forced ordering, so the race predates #7515, and #7515 left the
render path unguarded.

<details><summary>Other checks run</summary>

- `test_call_diff_projects_stable_commentable_rows`: 24 of 24 under
`leaf-dev suite flake --workers 4 --load 2`. Before the fix it failed
about 1 in 25 locally, on Chromium, and the failure matched CI's
capture: the patch line was focused and the root was open.
- `test_render_toc_disclosure.py` together with the call-diff, toc,
toggle and fold tests in `test_render_diff_controls.py`: 24 passed.
- `pnpm run test:runtime`: 1237 passed.
- `pnpm run check:browser` reproduces the committed bundle from the
updated lock.

</details>

Closes #7521 — automated triage

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 28, 2026
…7545)

Leaf stops patching Effect UI. `build/@effect__ui.patch` (#7515, #7522)
held one guard: the host skipped writing a `details`' controlled `open`
while the user's `toggle` for it was still queued. Since #7542 no view
controls `open`. `lf-call-diff` and `lf-toc` seed it with an attribute
the view never changes, and `lf-worktree` writes an attribute only when
its host's authored `open` changes. Effect UI writes an attribute only
when the drawn value changes and never restores one, so the guard ran
for no node. The rebuilt `browser/vendor/effect-ui.js` is byte-identical
to the bundle before #7515.

The race lives in the controlled idiom itself. The browser reports a
fold with `toggle` a task after making it, and a draw or restore in that
gap undoes the fold, even where the Model follows `toggle`. So a widget
leaves a fold to the browser, and `effect-widget.ts`'s list of Effect
UI's limits now says why.

Max asked to avoid the patch ("it's much more likely we misunderstood
something rather than the upstream needs patching"). The two race tests
from #7515 and #7522 keep their assertions and pass on the unpatched
bundle, 12 of 12 copies each under load; with the views from before
#7542 put back, they fail. The `lf-call-diff`, `lf-toc` and
`lf-worktree` browser tests, `pnpm run test:runtime` (1240) and `pnpm
run check:browser` pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Effect UI undoes a second details toggle made within a frame of the first (lf-call-diff, lf-toc)

2 participants