Skip to content

Config store: one operation at a time; cancel Load on dismiss - #129

Open
YektaY wants to merge 8 commits into
mainfrom
yektay/config-store-modal-concurrency
Open

YektaY wants to merge 8 commits into
mainfrom
yektay/config-store-modal-concurrency

Conversation

@YektaY

@YektaY YektaY commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #92.

Description

ConfigStoreModal now runs one operation at a time, and lets the dialog close only when that's safe.

  • One busy slot. Save and every row's Load, Rename and Delete share one slot: state for the render, a ref for the handlers. Every one of those buttons is disabled while it's held, and a status line next to Refresh names the running row operation. Of two Load clicks, the first now applies. On main, the second aborts the first and wins.
  • Mutations block dismissal; a Load doesn't.
    • While a Save, Rename or Delete has its server call in flight, X, Escape and the backdrop are refused. The guard reads refs, so it also holds for Escape, whose Carbon listener keeps the onClose from the render where the modal opened.
    • The slot is freed as soon as the server call settles, before the list refresh, so a hung list request can't trap the dialog.
    • Closing during a Load aborts it, and a response that beat the abort is dropped.
  • The delete confirmation holds the store. While it's open, only its own Delete can start.

Motivation

#92: one busySlug let operations on different rows interleave and re-enable each other's buttons, and a dismissal during a Save, Rename or Delete either got through on Escape or hid the outcome.

Review follow-up

  • 27ef386 fixes the review finding. begin() refuses everything except the confirmation's own Delete while it's open. Rename checks this before its prompt, and a row's Delete can't switch the confirmation to another config. A Load's success closes through requestClose.
  • cf81edb merges main. It keeps Keep keyboard focus in the config store's delete confirmation #177's delete-focus handling and ports its three focus tests into this file. It drops main's "aborts superseded loads and only applies the latest response" test, because this PR replaces that behaviour.

Testing

  • ConfigStoreModal.test.tsx mocks every magpie call and settles each one by hand, so a case controls when a response lands relative to clicks and dismissals. The four cases for the review fix fail without it.
  • With main's dependencies: pnpm lint, format:check and typecheck are clean, and the full suite passes. This file also passes with ci: bump the npm-minor-and-patch group across 1 directory with 18 updates #196's dependencies (Carbon 1.120).
  • Not checked in a browser.

Out of scope: PostToElogModal uses the same posting ? undefined : onClose guard on main. It needs the same fix in its own PR.

The modal tracked a single busySlug and disabled only that row's buttons,
so Load A followed by Load B overwrote the marker: both requests ran, both
called onLoaded, and the later response won. Each `finally` also cleared
the marker unconditionally, re-enabling a row whose operation was still in
flight.

Save and every row's Load/Rename/Delete now share one slot (state for the
render, a ref for handlers), and every action is disabled while it is held.
A successful Load closes the modal, so nothing useful can run beside it. An
operation releases the slot only if it still holds it. A status line names
the running row operation, which also explains why the buttons are disabled.

Save, Rename and Delete now block X, Escape and the backdrop until they
settle. The old `onClose={saving ? undefined : onClose}` did not block: on
X or backdrop Carbon hid the dialog while the parent's `open` stayed true,
so the toolbar could not reopen it. Escape still closed it, because Carbon
registers its Escape listener once per open and keeps that render's
onClose. The guard returns false from a stable handler that reads the
slot's ref, which holds on all three paths. A Load stays dismissible; it is
cancelled on close in the next commit.

Refs #92
A Load stayed live after X, Escape or the backdrop dismissed the modal.
Nothing cancelled getConfig, and the modal is always mounted, so the
response still called onLoaded and replaced the workspace after the dialog
was gone. A reopen also kept the dismissed row's Load disabled until the old
request settled, and then that stale response closed the new dialog.

Each open is now a session. Closing ends it in requestClose and again in
the `open` -> false effect (unmounting ends it too), and ending a session
aborts the pending Load through the signal getConfig already accepts. Every
operation applies its result, including errors, only while its session is
current, which also covers a response that beat the abort.

A reopen releases a slot still held by a dismissed Load. It leaves a Save,
Rename or Delete in place: those block dismissal, so one can only reach a
reopen through a close the parent made itself, and it is still running. The
slot is released by identity rather than by session, so such an operation
frees it when it settles, and a stale Load can't free a newer operation's
slot.

Refs #92
Save, Rename and Delete held the busy slot through the list refresh that
follows them, so a hung listConfigs left the dialog impossible to close.
Before this branch Rename and Delete never blocked closing, so that would
have been a regression. The refresh is only a read, so the slot is now
released as soon as the server call settles, and only the mutation itself
blocks dismissal.

Also from review:
- A successful Load ends its session before calling onClose, as
  requestClose does, so every close path ends the session first.
- Test two Load clicks that land before React re-renders. Only the slot's
  ref can turn the second one away, because its button is still enabled.
- Rename a test whose name overstated what it checks.
- Share one label helper between the status line and the delete prompt.

Refs #92
Save kept the busy slot until the clipboard write settled, so a pending
clipboard permission prompt left every action disabled and X, Escape and
the backdrop blocked after the workspace was already saved. Free the slot,
clear the form and start the refresh as soon as saveConfig resolves; the
copy and the toast follow, and the toast still goes out if the dialog has
closed in the meantime.

Refs #92
Main reworked the config store in #79: a Carbon dialog confirms deletes,
toasts carry a timeout, a Load aborts on unmount and when a newer Load
supersedes it, and TraceApp mounts the modal only while it's open.

The resolution keeps this PR's one-operation-at-a-time slot and its
cancel-on-dismiss sessions, with main's changes on top:

- Delete goes through main's confirmation dialog. Confirming claims the
  slot. While the delete's server call runs, the dialog's X, Escape and
  Cancel are refused, read from the slot's ref: Carbon keeps the onClose
  from the render that opened the dialog, so a guard on render state let
  Escape close it mid-delete. The store refuses to close under the
  dialog, and a failure shows in the dialog, which stays open for a retry.
- A second Load stays blocked rather than superseding the first, so
  main's supersede path is gone. Ending the session already aborts a
  pending Load on unmount.
- Main's toast timeouts and Load warnings are kept.
- Each open is a fresh mount now, so this PR's reset-on-reopen code is
  dropped.

The tests are one file on this PR's deferred-promise harness, which now
mounts the modal the way TraceApp does. Main's dialog and share-link
timeout tests are ported. Its superseded-Load test gives way to the
first-click-wins tests; its Save-dismissal and unmount-abort tests
duplicated existing ones. New tests cover dismissing the confirmation
before and during a delete, a delete failure and retry, and the Load
toast's warnings.
Cancelling the delete confirmation (X, Escape or Cancel) after a failed
Delete left the error set, so the store's banner showed it for a Delete
that had been cancelled. requestCancelDelete now clears it.

Name both dialogs with aria-label. Carbon names a ComposedModal from its
aria-label or ModalHeader's label, not the title, so both were unnamed.
The tests now find the dialogs, rows and the confirmation's Delete by
role and name, and tell open from closed by aria-hidden, instead of
reading Carbon's class names. Escape-driven steps keep the onClose
guards covered: Carbon only sends Escape to a modal it still shows.
@YektaY
YektaY requested a review from a team as a code owner November 12, 2026 06:27

@zdomke zdomke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Compared against the archived PR's review (slaclab/react-trace-archive#129): Copilot's one finding (clipboard write holding the Save slot) and my two findings (stale delete error leaking after cancel; tests coupled to Carbon's internal CSS classes) are all fixed and verified present here.

A fresh pass over the current diff found a real, confirmed concurrency bug not caught by the archived review — see inline comment. Not approving yet.

Comment thread src/components/ConfigStoreModal.tsx Resolved
begin() checked only the busy slot, which a Delete takes only once it's
confirmed. While the confirmation was open, a Load, Rename or Save from
the store behind it could claim the slot. The confirmation's Delete
then did nothing, a failed Rename showed under "Could not delete
config", and a Load that succeeded closed the store, confirmation and
all.

begin() now turns away everything but the confirmation's own Delete
while it is open. Rename checks this before its prompt, and a row's
Delete can't switch the confirmation to another config. A Load's
success closes through requestClose, like X, Escape and the backdrop.

This branch has not been deployed

No deployments
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.

Config-store modal: concurrent row operations and loads surviving modal close

2 participants