Repository navigation
fix: stop Citry UI menus and pickers from looping while idle - #483
Merged
Merged
Conversation
An open CMenu or CContextMenu with a submenu, a CSplitButton, and a CTimePicker with its CListbox kept an idle page busy. Each runtime wrote an attribute, class, tabIndex or text with the value already in place. That write still queues a MutationObserver record, so the observer that repairs the markup ran again and wrote again. In CMenu the reconcile focused the current item 150 to 180 times a second. Each of those writes, and the shared form-control attr helper, now skips a value that is already in place. The structure observer recognizes a submenu trigger's tabindex change as its own. A controller that takes over an open menu with a focused item no longer makes the surface inert, which blurred the item a second time on a server re-render. A new quality guard opens every browser scenario and fails when focus(), a timer or a DOM change repeats in each of three idle windows. It is marked with the new `weekly` marker and runs in the weekly cross-browser job, because it could add up to about 3 minutes to the pull-request e2e job. The context-menu family's raw JS budget goes from 160 KiB to 161 KiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/cmenu-focus-loop
branch
from
October 27, 2026 23:25
51bd454 to
7571754
Compare
JuroOravec
added a commit
that referenced
this pull request
Oct 28, 2026
… the original re-render test (not for merge)
JuroOravec
added a commit
that referenced
this pull request
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several Citry UI runtimes kept an idle page busy. Each one wrote an attribute, class,
tabIndexor text with the value already in place. That write still queues aMutationObserverrecord, so an observer that repairs the markup ran again, wrote again, and never stopped. Nothing looked wrong on the page, but it burned CPU and battery while nobody touched it.What was looping
Before this change, I measured these while idle in Chromium and Firefox:
CMenu/CContextMenuwith a submenufocus()calls a second.updateCurrentrewrote each item'stabIndex; the structure observer did not recognize a submenu trigger'stabindexchange as its own, so it reconciled, which focused the current item again.CSplitButtonclasswithclassList.addeven when the class was there, re-set the loading indicator'shidden, and wrote the trigger's loading attributes and then removed them, all on every pass.CTimePickerwith itsCListboxA second, smaller bug: when a server re-render updated an open
CMenu, the new controller setinerton the surface during setup, which blurred the focused item a second time.The fix
cmenu.py(tabIndex, classes, the submenu's physical-side dataset),cbutton.py(a guardedsetAttribute, pluswritesLoadingState: falsefor the split button's trigger, so its loading attributes are not written and removed),clistbox.py,ctime_picker.py, and the sharedattrhelper in_form_control_runtime.py. That helper did not loop on its own, but it has the same bug, so it is fixed in the same pass.tabindexrecord as one of its own.Each guarded write compares against the live DOM value, so a value that someone else changed is still written back. Only the record of a write that changes nothing goes away.
Tests
test_cmenu_e2e.py:test_open_menu_with_a_focused_submenu_item_is_idle, andtest_correlated_rerender_does_not_blur_the_focused_item_a_second_time(at most one blur).CSplitButtonandCTimePicker, and assertions in theCButtontests.quality/tests/e2e/test_idle_scenarios_e2e.py. It opens every browser scenario in the quality catalog in its active state, waits for it to settle, then samples three back-to-back 300 ms windows. It fails a scenario when, in every window,focus()ran 5 or more times or one timer or one kind of DOM change repeated 10 or more times. A real loop is busy in every window, while settling work such as a smooth scroll ending is not. With origin/main'scmenu.py,cbutton.py,ctime_picker.pyandclistbox.pyswapped in, it failsmenu.statesandcontext-menu.states(about 50focus()calls a window),split-button.states(about 490 timers a window) andtime.states(about 195).Not covered by a test: the shadow-root focus check, and making the surface inert when anchor setup fails.
Cost of the guard, and why it runs weekly
The guard catches a Citry UI component that falls into an idle loop in a quality-catalog scenario's active state, which no ordinary test notices, because the page looks and works the same.
-n 3, and 3:01 serially.--dist loadfile, which keeps one file on one worker, so the guard could add up to about 3 minutes to the PR e2e job. That is more than the one minute that CLAUDE.md's "Design verification" rules allow without the maintainer's explicit agreement.weeklymarker. The PR e2e job now runs-m "e2e and not weekly", and the weekly cross-browser job (py--tests-cross-browser.yml,-m e2e) runs the guard on Chromium, Firefox and WebKit, about 3 minutes per browser on one worker.docs/codebase.mddescribes the marker.loadfilespreads them over the four workers at about 45 s each, which would keep the guard on PRs. I did not do that here.The guard cannot see mutations inside shadow roots, loops inside iframes, or loops that start only after a popup closes. A component that runs a per-frame loop on purpose, as
CMenuSubmenudoes while a submenu is open, would trip the timer rule. No scenario's active state opens a submenu today.Asset budget
The context-menu family's raw JS budget in
test_asset_report.pygoes from 160 KiB to 161 KiB. Only CMenu's shared menu runtime is in that family's JS, and its new write guards and the focus check add 1,096 bytes: the family is 163,292 bytes raw on main and 164,388 on this branch, after I shortened the new comments. Getting back under 160 KiB would mean deleting every new comment and squeezing the code. Gzip is 35,760 bytes against its 35,840-byte budget (80 bytes to spare), and brotli is 29,992 against 30,720, so neither of those budgets changes. The next change to CMenu's runtime will likely need to raise the gzip budget.Evidence
cmenu,csplitbutton,cbuttonandccontext_menucomponent tests (-n 3 --dist loadfile). An earlier run, before the final comment edits, passed 234 e2e tests across 19 component directories, including the form-control components. The citry_ui non-e2e tests passed (3,299) apart from the asset budget, which this PR updates; the 36 asset report tests now pass.cmenu,csplitbuttonandctime_pickere2e directories and the idle guard pass, except three tests that fail the same way on origin/main:cmenu'stest_a_key_scrolls_the_page_to_an_item_below_the_screen(endandopen-on-last; the open PR test: make four e2e checks pass on Firefox #460 fixes both and renames the test totest_a_key_shows_an_item_that_starts_below_the_screen) andcsplitbutton'stest_layers_example_logs_menu_actions_and_opens_the_dialog_for_provenance, a Firefox failure that already exists on main and has no fix in progress. WebKit was not run locally, because WebKit hangs on this machine.--platform linux) andpnpm run citry-ui:check-assetspass. The cargo phases and the full pytest run are left to PR CI.🤖 Generated with Claude Code