Skip to content

fix(dashboard): settle useConfirm asks when their dialog disappears - #30251

Open
abirkel wants to merge 1 commit into
kirodotdev:mainfrom
abirkel:fix/native-dialog-d02-confirm-lifecycle
Open

abirkel wants to merge 1 commit into
kirodotdev:mainfrom
abirkel:fix/native-dialog-d02-confirm-lifecycle

Conversation

@abirkel

@abirkel abirkel commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An in-app confirmation always releases the code awaiting it, and only the dialog currently on screen can approve it.

useConfirm() returns a promise and relies on the owner to render confirmDialog. Today the promise can stay pending: Issue Radar's crew page dropped its dialog when it fell back to the loading or error branch, so a retirement ask raised on the crew page vanished and stayed pending until the page content returned, or for good if the error persisted. A Confirm click handler retained from a removed dialog could also approve the pending question while no dialog for it was on screen.

Why it matters

Most native confirm() calls still on main will be replaced by an await useConfirm() call in the follow-up PRs of the series for #15976. A hung await leaves the action suspended, and a late approval runs a destructive action the user is no longer looking at.

Not a goal

  • Migrating any native confirm, alert or prompt call. The allowlist is unchanged.
  • The Radix-nested confirmation variant and interactionDisabled.
  • Settling asks that React itself is holding back behind a transition or a suspended ancestor. These surface when React commits (see below).

What changed (motivation → approach → change)

The hook tracked only "a question is pending", so it could not tell whether anything on screen could answer it. It now tracks the question and the controls that rendered it.

  • ConfirmDialog.tsx: the Cancel and Confirm buttons moved into ConfirmControls, which reports mount and unmount for its question. An ask answers false when its owner unmounts, a newer ask replaces it, or its controls are missing or removed. Only the mounted controls of the current question can answer true, so a stale callback from a destroyed or replaced dialog is ignored. Options are retained as the question object until the exit animation finishes, and a newer question is never cleared by an older dialog's exit.
  • Modal.tsx: an optional onExitComplete passed to AnimatePresence.
  • CrewPageView.tsx: renders confirmDialog on the loading and error branches.
  • The useConfirm doc comment states the contract.

Accepted deferral: an ask made while React holds the owner's update stays open until React commits, then appears normally and still needs a click on the current controls. Cases: (a) a replacement ask in a transition with a suspending body, (b) an ask after a suspending sibling already hid the owner, (c) a transition with a suspending sibling. No production caller was found that asks inside startTransition or passes a suspending body (git grep -nE "startTransition|useTransition" -- website/src ':!website/src/test' finds only comments). Revisit when one does. Tracked in #30960.

Backwards compatibility

Compatible: useConfirm() keeps its signature and confirmOpen still means an unanswered question. Asks that previously never settled now answer false, and approval from controls that are no longer mounted is ignored. Modal gains an optional prop.

Removes nothing: the internal lastOptsRef is replaced by retained question state. No exported name, prop or key is removed.

Tests

ConfirmDialog.test.tsx and IssueRadarCrewPage.test.tsx lock in: replacement answers the old promise false; Cancel, Escape, backdrop and X answer false; owner unmount, an omitted dialog, and a removed dialog answer false; a stale or detached Confirm callback cannot approve after its dialog is removed or remounted; a retained confirm called after owner unmount answers false; a replacement that never commits answers false while a renderer retains the older question; a transition ask stays open and answerable after React commits; a newer question survives the previous exit; an ask from a descendant's first layout effect and from a passive effect works; hidden-owner deletion settles false; a retirement ask on Issue Radar's crew page stays on screen through the loading, error and missing-crew branches and still retires the crew it named. Most cases run in both normal and StrictMode trees. Deferred promises and controlled microtasks are used, with no sleeps.

Proof: not provable -- frontend test (prove.py runs Python only). Disabling the insertion-phase validity, layout-disconnect cancellation, passive lifetime invalidation and committed-pending check in turn each made its matching tests fail.

Manual verification

N/A: lifecycle logic covered by the tests above. The dialog markup and styling are unchanged.

Screenshots / video

Why no screenshot: the confirm dialog's markup and styles are unchanged. The Cancel and Confirm buttons moved into a sibling component with the same props and classes.

Related Issues

Part of #15976

Sibling sweep

Swept: git grep -n "useConfirm()\|useDialogConfirm()" origin/main -- website/src
Sibling: website/src/components/crew/useDialogConfirm.tsx -- tracked in #15976 -- keeps its own state machine with no rendered-surface check, handled in the Radix confirmation PR of this series.
Sibling: website/src/apps/issue-radar/views/CrewPageView.tsx -- changed here -- the owner found whose early returns dropped the dialog. The other owners render it under their own alias and were not audited branch by branch. ArtifactDetailPage drops it on its loading, error and not-found returns; #30515 fixes that.

Pattern harvest

Rule candidate: review-prompt
Pattern: an awaited UI prompt whose owner can return JSX without rendering the prompt's dialog.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@abirkel
abirkel requested review from a team and KiroCrewCaptain as code owners November 5, 2026 09:04
@abirkel
abirkel requested a review from iamwhatever November 5, 2026 09:04
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 3b822c4afb8caff94178e2768eb18add11c0aa6c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: an ask that can't be answered now resolves false instead of hanging, which is safe and easy to revert.

Notes

  • Owners that drop confirmDialog for a moment change behaviour. Today an ask hidden by a refetch's loading branch comes back when the content returns. After this PR it is cancelled at once and never comes back. ArtifactDetailPage is one such owner (fix(pages): ask in-app before artifact, channel and Knowledge actions #30515), along with any other owner nobody has checked branch by branch. Land fix(pages): ask in-app before artifact, channel and Knowledge actions #30515 first or alongside, or a destructive action there will silently cancel during a refetch.
  • The lifecycle check depends on the order React runs its effects: the insertion, layout and passive effects plus queued microtasks. A React upgrade could change that order. The suite catches it only if those tests keep running on the upgrade PR. Note the React-version dependency in the useConfirm doc comment.

[DESIGN-REVIEWED] 3b822c4

Description read

[DESCRIPTION-READ] 87de3ec781daf6c67a9b22e20b0777e91b4db471c3612a6afd0c8611b674fb1e

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 3b822c4afb8caff94178e2768eb18add11c0aa6c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The confirm dialog looks the same as before. It now stays open through Issue Radar's crew-page loading and error states instead of vanishing, and its title still names the crew it will retire.

Notes

  • Neither the description nor temp-screenshots/ includes a screenshot, and the PR marks itself no-visual-delta. The one new visible state is the retire dialog over the loading or error page (CrewPageView.tsx). The diff only moves confirmDialog into those branches and leaves its markup unchanged, so this lane doesn't count it as a gap.

[UX-REVIEWED] 3b822c4

Description read

[DESCRIPTION-READ] 4b6d8fcd76751b74724c6dc16c893841dfbf679ab92a9ad7d664e2d4abb1c572

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 3b822c4afb8caff94178e2768eb18add11c0aa6c via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The hook-level change fixes the cause: any ask whose dialog cannot answer now settles false, whichever owner drops it. The fix is pinned by tests that drive the Issue Radar crew page through each branch.

Notes

  • Item 6 — duplicate of website/src/test/ConnectionsPage.coverageTestUtils.tsx:54: the test helpers already export deferred<T>() there, and the diff adds export function deferred<T>() to helpers.tsx. Subtraction: import the existing helper, or move that one into helpers.tsx, rather than keeping two shared exports.

What this change ships

Inventory (6 items) — 5 justified

Intent: an awaited in-app confirmation always releases its caller, and only the dialog on screen can approve it. This is a FIX.

  1. A pending confirmation now answers "no" when its dialog is not rendered, stops rendering, or its owner unmounts. — justified
  2. A Confirm click from a removed or replaced dialog no longer approves the pending question. — justified
  3. A newer question's dialog is no longer cleared by an older dialog's exit animation. — justified
  4. Issue Radar's crew page keeps the retirement dialog on screen through its loading, error and missing-crew branches. — justified
  5. Modal gains an optional onExitComplete prop, with one consumer (ConfirmDialog). — justified
  6. A shared deferred() test helper is added to helpers.tsx. — duplicate of ConnectionsPage.coverageTestUtils.tsx deferred

[FIRST-PRINCIPLES-REVIEWED] 3b822c4

Description read

[DESCRIPTION-READ] 3b51b1624f8e7e382413c34bb84bfca5a0960175f5793e893aa07fb60cf245b1

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 3b822c4afb8caff94178e2768eb18add11c0aa6c via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3b822c4

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 3b822c4afb8caff94178e2768eb18add11c0aa6c via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3b822c4

@iamwhatever iamwhatever 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.

Request changes at 129c28d. Only issue links are needed. The code looks sound.

The new lifecycle holds up in the cases I traced. Only the committed controls of the current question can answer true (settle). A missing dialog answers false. A same-commit remount keeps the ask, because the cancel check waits for a microtask and OverlayPortal mounts synchronously (code).

Two follow-ups are stated but not tracked. #15976 does not cover either one:

  1. The description says the other useConfirm owners were not audited branch by branch, and Design Review found one: ArtifactDetailPage's loading, error and not-found returns drop confirmDialog (L326, L330, L359). With this PR such an ask answers false, which is safe, but the dialog still vanishes.
  2. The "Accepted deferral" for asks held behind a transition or a suspended owner ("Revisit when one does").

Please fix them here or open one issue per item and link them in the description.

AI findings judged non-blocking

  • Design (note): a root-level confirm host would make the missing-dialog case impossible. Does not block: this is advice for later PRs, and nothing in this diff is harmed.
  • UX (note): CrewPageView remounts the dialog on a branch switch and replays its entry animation. Does not block: the effect is cosmetic, and the ask survives the remount (code).
  • First Principles (note): deferred<T>() in test/helpers.tsx duplicates an existing export. Does not block: the duplicate is test-only (code).

— crew-pr-reviewer (r146)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 5, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 9, 2026
useConfirm() hands the caller a promise and leaves the dialog to the
owner's JSX. When that dialog was never rendered, stopped being rendered (Issue
Radar's loading and error branches dropped it), or its owner went away,
the awaiting caller was never released, or a retained affirmative click
handler could still approve the pending question with no dialog on
screen.
Most native dialogs this series replaces will await useConfirm(), so the
hook has to settle first.

An ask now answers false when its owner unmounts (including an owner
deleted while hidden by Suspense), a newer ask replaces it, or its controls are not
rendered or are removed. Only the controls mounted for the current
question can answer true, and a newer question survives the previous
dialog's exit callback. Modal gains onExitComplete so the hook drops the
answered question once its exit animation ends without clearing a newer
one, and Issue Radar's crew page renders its dialog on the loading and
error branches.

An ask made while React holds the owner's update (a pending transition
or a suspended ancestor) stays open until React commits it, then appears
normally. The useConfirm doc comment states this contract.

Part of kirodotdev#15976
@abirkel
abirkel force-pushed the fix/native-dialog-d02-confirm-lifecycle branch from 129c28d to 3b822c4 Compare November 10, 2026 00:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 10, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 10, 2026

@bolichen97 bolichen97 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.

LGTM. I read the whole diff, tests included.

  • useConfirm now answers false when the owner unmounts, a newer ask replaces the old one, or the dialog is never rendered or stops being rendered. Callers no longer hang.
  • Only the mounted ConfirmControls for the current question can answer true, so a stale Confirm handler cannot approve an ask whose dialog is gone.
  • onExitComplete keeps the answered question's title and buttons through the exit animation, and it does not clear a newer question.
  • CrewPageView now renders confirmDialog in the loading and error branches too, and the new it.each test covers all three branches.
  • The new tests cover StrictMode, Suspense, transitions and same-commit remounts. The change is frontend only, with no regex and no new refusal. All 94 checks are green.

The open change request from another reviewer asks only for issue links for the follow-ups, not for code changes.

@abirkel

abirkel commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@iamwhatever, would you re-review this when you have a moment? Your request was for issue links on the two follow-ups, and both are now in the description:

The PR has an approval on the current head since your review, and the code has not changed in response to it. D03, D04 and the leave-guard PRs are stacked on this one, so they are waiting on it.

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

fork Pull request from a fork (external contributor) readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants