Repository navigation
fix: reuse Cancel confirmation for browser-back guard (OPS-1081) - #6565
rajohnson90 wants to merge 4 commits into
Conversation
|
Reviewer: @Santi-3rd (picked by rotation) Not the right person? The PR author can comment |
Preview environment
Log in: choose Sign in with FakeAuth and pick a role: System Owner, Budget Team Member, Procurement Team Member, Division Director, User Demo, Administrative Power User or Read Only User. Data: the first deploy seeds test data. Later pushes only run migrations, so data you enter survives fix commits. To reset it, open Actions > Preview Create > Run workflow and enter Lifetime: removed when the PR closes, the Limits: FakeAuth only; no Storybook, |
josbell
left a comment
There was a problem hiding this comment.
Shared AI Review — PR #6565
Head SHA reviewed: 5db3ec0d1 · Scope: Fix PR (S0/S1 block) · Tier: 3 (routes browser-Back into a deleteAgreement data-write path) · Mode: Full review, reviewer mode · N: 3 skeptic turns
Four specialist reviewers (pragmatic, frontend, accessibility, software-architect) reviewed this PR independently, and three independently found the same bug below. Three independent skeptics re-derived severity from the code; 2 of 3 (including the accessibility domain specialist) land on S1, which is why this is REQUEST_CHANGES. See the inline comment for the blocking finding.
Non-blocking
[S3] frontend/src/pages/agreements/StepSelectProject.jsx:49-76
What breaks: Nothing currently — the isBypassingRef/blockerRef/bypass-effect machinery this PR adds duplicates frontend/src/hooks/useUnsavedChangesBlocker.hooks.js:38-48 almost line-for-line instead of sharing it.
Scenario: A future fix to this ref/effect pattern in one copy could be forgotten in the other.
Fix: Extract a shared useBlockerWithBypassRef(...) hook for both call sites. Discretionary.
Pre-existing
[Pre-existing S2] frontend/src/components/UI/Modals/ConfirmationModal.jsx (~lines 85, 101-119)
aria-describedby="ops-modal-description" points at a <p> that only renders when a description prop is passed; StepSelectProject never passes one, in base or head. Unrelated to this PR.
No author shared-review comment (<!-- shared-review sha=... -->) exists on this PR to compare against — the PR body describes an internal AI-assisted pass that fixed three other issues in the second commit, but that's not a tracked, comparable result. The finding below is new to this run.
Verdict: BLOCKING (1)
| // Closes the Cancel confirmation (whichever trigger opened it — the Cancel button or | ||
| // the browser-Back guard below) and discards any pending blocked back-navigation so the | ||
| // user stays on the page instead of leaving a blocked transition dangling. | ||
| const handleCloseModal = (value) => { |
There was a problem hiding this comment.
[S1] frontend/src/pages/agreements/StepSelectProject.jsx:81-86
What breaks: handleCloseModal is passed as ConfirmationModal's setShowModal prop on every render (replacing the previously-stable useState setter), without useCallback. ConfirmationModal's handleKeyDown (useCallback, deps include setShowModal) and its focus-trap useEffect (deps include handleKeyDown) therefore tear down and rebuild on every re-render of StepSelectProject while the dialog is open. Teardown unconditionally refocuses whatever was focused when that effect instance mounted — the page's background trigger button, which isn't inert/aria-hidden while the dialog is open — and setup unconditionally refocuses the dialog's first button, with no check for where focus currently is.
Scenario: User opens the Cancel-confirmation dialog (via Cancel, or a blocked browser Back), tabs to "Continue Editing" to read it, then presses browser Back again before clicking anything — the exact sequence this PR's own new test ("still blocks further navigation while the Cancel confirmation dialog is already open") and manual-test step 8 both exercise. The resulting re-render recreates handleCloseModal, rebuilding the focus-trap effect and snapping focus away from "Continue Editing" — briefly through the background trigger button — back to "Cancel Agreement," with no visual cue, while the user is still deciding. ConfirmationModal is fully mocked in StepSelectProject.test.jsx, so no test (old or new) exercises the real focus-trap behavior this PR's change affects.
Fix: Wrap handleCloseModal in React.useCallback with an empty dependency array (setShowModal and blockerRef are both already stable): const handleCloseModal = React.useCallback((value) => { setShowModal(value); if (!value && blockerRef.current.state === "blocked") blockerRef.current.reset(); }, []). Add a test that exercises the real ConfirmationModal (not the current stub) across a repeated blocked-navigation attempt.
weimiao67
left a comment
There was a problem hiding this comment.
looks good to me as long as findings from Josbell are resolved.
What changed
This PR changes how the browser's Back button is guarded on step 1 (project selection) of the Create Agreement wizard. A prior merged PR (#6545) added a distinct "Leave without finishing?" modal for this case. This PR replaces that with reuse of the page's existing Cancel confirmation — same heading/buttons/handler — so confirming cancels the agreement (deletes a new draft, redirects to
/agreements) exactly like the page's own Cancel button does, instead of resuming navigation to wherever Back was headed.It also fixes three issues an internal AI-assisted review caught in that change before asking for human review.
frontend/src/pages/agreements/StepSelectProject.jsx
useUnsavedChangesBlocker/SaveChangesAndExitModalpairing (still used elsewhere — unaffected) in favor of callinguseBlockerdirectly.ConfirmationModalthe Cancel button uses, with the samehandleCancelhandler.handleCloseModalto reset a pending blocked navigation when the modal closes (either button), and keptisBypassingRefso the Cancel confirm's own redirect isn't re-blocked.!showModalguard (meant only to avoid stacking a second modal) was letting any navigation attempt slip through unguarded once the modal was open, abandoning the pending delete/redirect. Removed that guard — the shared modal/state no longer needs it.frontend/src/pages/agreements/StepSelectProject.test.jsx
react-router-domuseBlockermock that captures the real predicate, so tests exercise actual behavior instead of asserting on mock call arguments.deleteAgreementactually fires via the new browser-Back trigger (and is skipped in edit mode) — a gap the review flagged, since this PR is what first routes Back into a data-write path.isBypassingRefbut didn't —hasProjectChangedwas pinnedfalsefrom before mount in its setup, so the assertion passed independent of the ref. Now the project is selected after mount so the assertion is meaningful.Decisions reviewers may ask about
/agreementsinstead of resuming navigation to wherever Back was headed? That's the deliberate point of this PR — reusing the exact same Cancel flow means the same outcome (delete the draft, redirect to/agreements), not a different "continue navigating" behavior.!showModalremoved from the blocker predicate entirely, rather than gating the duplicate-modal concern a different way? With the Cancel-button and Back-triggered opens now sharing one modal/state, re-running the open-modal effect while already open is just a harmless no-op (same props, no remount) — so there's no longer a reason to suppress the guard itself while the modal is open./ops-pr-reviewrun before asking for human review.Issue
OPS-1081
How to test
Automated:
Manual (must navigate in-SPA — a hard page load to
/agreements/createwon't let the browser-Back guard fire, since that's a cross-document history entry, not a same-documentpopstate):docker compose up --build(or against the already-running dev stack), log in./agreements, draft agreement deleted, success alert shown.A11y impact
A11Y-SUPPRESSIONmetadata (owner, expires, rationale)Storybook
src/components/UI/Screenshots
Step 1 with a project selected, after pressing browser Back — the Cancel-confirmation modal appears in place of the old distinct "Leave without finishing?" wording:
Close-up of the modal itself — same heading/buttons as the page's own Cancel button:
Definition of Done Checklist
Links
N/A