Skip to content

fix(ui): run a closing palette command's onAction after the close - #446

Merged
JuroOravec merged 2 commits into
mainfrom
fix/ui-palette-action-after-close
Oct 28, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/ui-palette-action-after-close

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Closes #420.

What this fixes

CCommandPalette called onAction before it closed. At that point the modal still made the rest of the page inert, so a focus() call from the owner in onAction did nothing. Now a command that closes the palette closes it first: the palette calls onOpenChange(false), resets the query, and only then calls onAction. A command that keeps the palette open still calls onAction right away.

How the timing works

  • Uncontrolled: the close applies at once, so onAction runs inside the user's event. This holds even when the owner's onOpenChange(false) reopens the palette.
  • Controlled: the palette runs onAction one microtask after onOpenChange returns, outside its own reactive effect. If the owner set open=false synchronously inside onOpenChange, Vue's update has already applied the close by then. An owner that closes later, for example after an await, in nextTick or in a .then(), gets onAction while the palette is still open. api.md says so.
  • Every path runs onAction exactly once and never on a later close. That includes an owner callback that throws during the close, an owner that releases control with open=null, and an owner that unmounts the palette while closing it (onAction then runs in a microtask after the cleanup).
  • Errors: a throw in onAction is reported through reportError, and the palette does not reopen. To keep the palette open after a command, set close_on_action=False.

This is a Breaking entry in the citry_ui CHANGELOG. api.md, api.yml, the example and docs/design/ui_components/command-palette.md are updated to match.

Other popups

I probed whether an owner's focus() in a close callback survives in the other popups. CContextMenu keeps it in all six cases tested. It is lost in controlled CDialog, CAlertDialog and CDrawer, and on a CPopover outside click. Neither is the same small change as this one, so both are filed as #442. Their probe tests are strict xfails (raises=AssertionError) that reference #442, and the passing cases stay as regression tests.

Left out on purpose

onQueryChange, and the onOpenChange call when the palette becomes disabled, still run inside the palette's reactive effect, so anything they read is tracked. That is how main behaves today; this PR only moves onAction out of the effect.

Evidence

  • Chromium: the palette suite plus the owner-focus probes in the five other popup suites give 177 passed and 17 xfailed. Firefox: the palette e2e suite gives 32 passed. WebKit hangs on the local machine, so the weekly cross-browser job is its first run.
  • Each new regression test failed with its fix removed: owner callback throws in both modes, releasing control, reopening, unmounting, and the reactive-tracking case.
  • Firefox enforces user activation for clipboard.writeText, and the deferred write still succeeds there in both modes, for both click and Enter.
  • scripts/validate.py, ruff, and the citry_ui contract tests pass.
  • Three independent review rounds, each with a prose pass, plus a cold read of api.md, api.yml and the CHANGELOG. Every finding is folded in.
  • Cargo and the full gate are left to CI; this lane does not build Rust.

🤖 Generated with Claude Code

@JuroOravec

Copy link
Copy Markdown
Member Author

Added a commit that keeps the palette within a stated asset budget. The deferred onAction pushed the complete Command Palette JavaScript to 21427 bytes gzip and 18256 Brotli, past the 20 KiB and 17 KiB limits; main had 91 and 55 bytes of headroom. Shortening the new JS comments brought it to 21030 and 17945. The rest is logic (about 2.3 KiB raw), so the limits rise to 21.5 KiB gzip and 18.5 KiB Brotli, with the reason in the test and in the design doc's budget table. Locally all non-e2e citry_ui tests pass (3262), and so do the palette e2e tests in Chromium and Firefox. The separate Python 3.15 gzip-level failure in the same test is fixed in #449.

JuroOravec and others added 2 commits October 27, 2026 17:57
CCommandPalette called onAction before it closed, while the modal still
made the rest of the page inert, so an owner's focus() in onAction did
nothing. A command that closes the palette now closes it first (after
onOpenChange(false) and the query reset) and then calls onAction. A
command that keeps the palette open still calls onAction right away.

- An uncontrolled close applies at once, so onAction still runs inside
  the user's event, even if the owner reopened the palette in
  onOpenChange(false).
- In controlled mode the palette runs onAction one microtask after
  onOpenChange, outside the palette's reactive effect. When the owner set
  open=false synchronously inside onOpenChange, Vue's update has applied
  the close by then. Whatever the owner did (accepted, kept open=true,
  accepted only later, or released control), onAction runs there and
  does not wait for a later close; an owner that closes later gets it
  while the palette is still open.
- If an owner callback throws during the close, the error propagates (or
  Vue reports it, for an error thrown during its update) and onAction
  still runs: at once when uncontrolled, one microtask later when
  controlled.
- If the palette is cleaned up first, for example when the owner unmounts
  it while closing it, onAction runs in a microtask after the cleanup.
- An earlier command still waiting runs before the next chosen one.
- A throw in onAction is reported through reportError; the palette does
  not reopen. To keep the palette open, set close_on_action=False.

api.md, api.yml, the example, the design doc and the citry_ui CHANGELOG
(a Breaking entry) describe the new order. E2E tests cover the order in
both modes, the declined close, the owner releasing control or reopening
the palette, owner callback throws in both modes, the unmount, the
reactive tracking, owner focus in both modes, and a clipboard write
after the deferral; they run in Chromium and Firefox. Probe tests for
owner focus in CContextMenu, CDialog, CAlertDialog, CDrawer and CPopover
keep the passing cases as regression tests and mark the controlled-dialog
and popover outside-click losses as strict xfails for #442.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dget

The deferred onAction from the previous commit grew the complete Command
Palette JavaScript past its 20 KiB gzip and 17 KiB Brotli budgets; on
main the family had under 0.1 KiB of headroom. Shortening the new
comments recovered about 0.4 KiB gzip, and the rest is logic: about
2.3 KiB raw (0.6 KiB gzip) for running a closing command's onAction
after the close, with its handling of owner errors, reopening and
unmounting. The gzip and Brotli limits rise by 1.5 KiB, to 21.5 KiB and
18.5 KiB, with the reason recorded beside the test and in the design
doc's budget table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the fix/ui-palette-action-after-close branch from 25889c4 to e58dd10 Compare October 27, 2026 16:58
@JuroOravec
JuroOravec merged commit b3dc3af into main Oct 28, 2026
27 of 35 checks passed
@JuroOravec
JuroOravec deleted the fix/ui-palette-action-after-close branch October 28, 2026 09:47
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.

CCommandPalette: an owner's focus move in onAction is lost when the command closes the palette

1 participant