Skip to content

fix(ui): stop re-renders from scrolling the page back to CSelect, CTabs and others - #406

Merged
JuroOravec merged 1 commit into
mainfrom
fix/popups-keep-page-scroll
Oct 25, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/popups-keep-page-scroll

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Follow-up to #383 and #395. That fix found that CMenu scrolled the page back to itself whenever it refocused an item. This PR checks the other components that call scrollIntoView or focus() on a path that runs without a key press. Each one has a browser test that scrolls the page away and then triggers that path. Only the cases a test confirmed on main are fixed.

Confirmed on main, and fixed

Component Path scrollY on main (from 3000) Fix
CSelect a server re-render while the popup is open reopens it and shows the highlighted option 79 scrolls only the popup's list
CMultiSelect same 74 scrolls only the popup's list
CCombobox new items drop the highlighted option, and the first new one is highlighted 89 scrolls only the list, through the shared active-option code
CTabs a re-render removes the selected tab, so a fallback is selected and shown 8 scrolls only the tab list
CTagGroup a re-render removes the focused tag, so focus moves to a neighbor 0 focus({ preventScroll: true })
CToolbar a re-render removes the focused control, so focus moves to another 0 focus({ preventScroll: true }), then scrolls only the toolbar

The shared runtime is new, in components/_reveal.py. It's stored on globalThis under Symbol.for('citry-ui:reveal') and loaded through Dependencies, like _scroll_geometry.py, and it's written short by hand, like that one, because every page with one of these components downloads it. reveal(element, container) scrolls only the scrollable elements from the element up to and including container, by the least distance that shows it. It does nothing when the element isn't inside the container, or is the container itself.

  • CSelect runs it before its open animation. The animation scales the popup, which would make the measured distances too short. CSelect's runtime.min.js is rebuilt.
  • Arrow-key and typeahead moves in CSelect and CMultiSelect keep scrollIntoView, because a key press means the reader is at the component. CTabs keyboard moves still scroll through focus().
  • CCommandPalette is modal and locks the page's scrolling. A page with only the palette doesn't load the new runtime, and the shared active-option code keeps scrollIntoView there. This also keeps the command-palette family under its byte budgets.

Cleared

Every other popup that leaves the page free to scroll passes the new parametrized re-render test on main: cmenu, cpopover, chover_card, ccombobox (its re-render path; the new-items path is fixed above), ccascader, ccolor_picker, the date and time pickers and ctour. The test is test_server_rerender_of_an_open_overlay_leaves_the_page_where_the_reader_scrolled. While it ran, I logged every scrollIntoView and focus() call: these components either make none on that path or pass preventScroll. Modal dialogs lock the page's scrolling, so they don't take part.

Not checked (out of scope)

  • CTransferList: in controlled mode, the owner's value can arrive after a server round trip (runtime.source.js:451), and focusMoved then calls scrollIntoView. I found this by reading the code and didn't test it.
  • CCascader: a controlled open calls item.focus() without preventScroll. That's probably intended when the owner opens the popup.

Tests

  • Each confirmed case's test fails on main and passes here:
    • CSelect and CMultiSelect: citry_ui/tests/e2e/test_open_state_across_server_rerender_e2e.py.
    • The others: their own e2e files.
    • CTagGroup and CToolbar each get a small v-if on their test page, so a Vue re-render can remove the focused item.
  • New: cselect/.../test_opening_shows_the_highlighted_option_inside_the_list checks that the list still scrolls to show a selected option far down, fully inside the popup. It fails on an earlier draft of this change that ran reveal after the animation started.

Evidence (local, with citry_core built from main 5a4e517)

  • Suites for the touched components, the re-render tests and the asset tests: 529 passed.

  • The one failure is test_context_menu_assets_stay_within_the_family_budgets, which fails on main too and is fixed by fix(ui): bring the context-menu family back under its byte budgets #401.

  • Byte budgets (family JS, gzip and brotli), main → this PR:

    Family gzip brotli
    select 10,479 → 10,844 9,334 → 9,654
    multi-select 17,125 → 17,451 14,966 → 15,277
    combobox 6,917 → 7,317 6,202 → 6,574
    tabs 3,528 → 3,994 3,063 → 3,484
    toolbar 2,838 → 3,338 2,469 → 2,915
    command-palette 20,308 → 20,389 (budget 20,480) 17,263 → 17,353 (budget 17,408)

    All are within budget. The command-palette brotli figure is the tightest spot, with about 55 bytes of room, so the next edit to _active_descendant.py will likely need to shorten something there.

  • All the local check phases pass, including citry-ui assets, docs-playground and vscode-extension.

PR CI runs the cargo phases and the full matrix.

🤖 Generated with Claude Code

…bs and others

The #383 fix found that CMenu scrolled the page back to itself whenever
it refocused an item. A browser test for each other component that calls
scrollIntoView or focus() without a key press confirmed the same on main
for six of them. The reader scrolls the page away, then:

- CSelect and CMultiSelect: a re-render while the popup is open reopens
  it and shows the highlighted option with scrollIntoView;
- CCombobox: new items move the active option, which the shared
  active-option code shows with scrollIntoView;
- CTabs: a re-render that removes the selected tab shows the fallback tab
  with scrollIntoView;
- CTagGroup and CToolbar: a re-render that removes the focused item moves
  focus with focus().

CSelect, CMultiSelect, CCombobox and CTabs now scroll only their own list,
through a shared runtime (components/_reveal.py) that scrolls the
scrollable elements from an element up to its container by the least
distance. CSelect runs it before its open animation scales the popup.
CTagGroup moves focus with preventScroll, and CToolbar also scrolls only
itself to show the replacement. Arrow-key and typeahead moves in CSelect
and CMultiSelect keep scrollIntoView; CTabs keyboard moves still scroll
through focus(). CCommandPalette is modal, so a page with only the
palette keeps scrollIntoView and does not load the new runtime.

Every other popup that leaves the page free to scroll passed the same
re-render test on main, so it is unchanged.

Co-Authored-By: Claude Opus 5.5 <[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.

1 participant