Skip to content

Commit ae68419

Browse files
mchwangclaude
andcommitted
Check Cancel's focus against the control focused before the update, and test the disabled fallback (#194 review round 22)
Also word the fallback as "not disabled (aria-disabled qualifies)" in the rule and the comment, drop the second write of Merge status's visibility, and document every focus move in merge-handoff.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 188b68d commit ae68419

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For features with background jobs, polling, retries, cancellation, or shutdown:
3232
- Preserve completed historical results, but visibly mark them stale when their snapshot, plan revision, assignment, or referenced code no longer matches.
3333
- When polling updates one part of the screen, update only that state. Preserve scroll position unless the user was already following the bottom.
3434
- While a request is in flight, do not disable the control that has keyboard focus; disabling it drops focus to the page. Mark it `aria-disabled`, ignore repeat activation with an in-flight guard, and test that focus stays on the control after the response.
35-
- When a background update (a poll, a reload, an answer) hides or removes the control that has keyboard focus, move focus to a named fallback that is still shown and enabled once the update has set every control's final state, and test that focus lands there for each way the control can be hidden. Decide a focusable control's visibility once per update: hiding it and showing it again blurs it.
35+
- When a background update (a poll, a reload, an answer) hides or removes the control that has keyboard focus, move focus to a named fallback that is still shown and not `disabled` (an `aria-disabled` control qualifies) once the update has set every control's final state, and test that focus lands there for each way the control can be hidden. Decide a focusable control's visibility once per update: hiding it and showing it again blurs it.
3636
- When a row or control's visual selection determines the current content or input, expose the same state with the appropriate accessibility attribute, such as `aria-current` or `aria-selected`, and test it across navigation.
3737

3838
## Required race regressions

‎docs/implementation/merge-handoff.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The job saves each change to the list in its `merge_jobs` record, so the list su
7878
- The step that was running is **Failed** even when its own work succeeded and a check during it stopped the job. For example, **Fetch** fails when the fetch shows the pull request head moved, **Push** fails when the pull request moves after the push, and **Already-fixed check** fails for any refusal in the guarded merge's validation, such as a pull request that changed.
7979
- When no step was running, the list stays as it was. For example: preparation stops for review after the rebase (a stale approval); its final inspection or authorization, after **Re-run checks**, refuses; it refuses before **Fetch** starts (an earlier push was settled, or cleanup is unresolved); the review changed between the click and the job's first review load; or the merge was cancelled during that load. Then every step may still read **Waiting**.
8080

81-
The list stays on screen after the job ends until the review reloads (**Refresh**, or any review action, plan import or **Apply**), also while the page follows the merge queue a job ended `queued` in. **Cancel merge** shows only while the job runs, not "always" as the design says: an ended job has nothing to cancel. When Cancel hides (the job ends, or the bar hides), keyboard focus on it moves to the merge control, or to **Refresh** when that is hidden too. A job saved before the list existed has no `steps`; the page then shows its step as before, without the list or Cancel.
81+
The list stays on screen after the job ends until the review reloads (**Refresh**, or any review action, plan import or **Apply**), also while the page follows the merge queue a job ended `queued` in. **Cancel merge** shows only while the job runs, not "always" as the design says: an ended job has nothing to cancel. When Cancel, **Merge PR** or the **Merge status** button hides (the job ends, the bar hides, a reload clears the blockers or makes merging unavailable, or a load fails), keyboard focus on it moves to **Merge PR**, or to **Refresh** when Merge PR is hidden or `disabled`. The page reads the focused control before it changes any control and moves focus once every control's final state is set. A job saved before the list existed has no `steps`; the page then shows its step as before, without the list or Cancel.
8282

8383
**Cancel merge** stops the job without cancelling the task. The page sends `{action: "cancel-merge", jobId}` to `POST /api/action`:
8484

‎test/browser/review.spec.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,29 @@ for (const runner of [true,false] as const) test(`moves focus off the blockers b
10571057
await expect(page.locator('#merge')).toBeEnabled();
10581058
await expect(page.locator('#merge')).toBeFocused();
10591059
});
1060+
test('moves focus off the blockers button to Refresh when the reload leaves Merge PR disabled (defensive, D16)',async({page})=>{
1061+
// Defensive: the server sends no blockers only with `ready: true`, so Merge PR is enabled then. This pins the fallback's
1062+
// "not disabled" rule for an answer that leaves Merge PR disabled with nothing to explain it.
1063+
const config={...app.service.config,demo:false};await app.close();removeDemoOutOfScope(config);
1064+
const gateway:MergeGateway={inspect:async()=>{const snapshot=(await app.service.load()).snapshot;return {base:snapshot.base,head:snapshot.head,pullRequestState:'OPEN',mergeable:'MERGEABLE',rulesKnown:true,atomicBaseGuard:true,mergeQueue:false,requiredChecks:[],alreadyFixed:'clear',pullRequest:7,draft:false};},merge:async()=>{throw new Error('The browser test answers every merge request itself.');}};
1065+
app=await startServer(config,0,undefined,gateway);
1066+
let view=await app.service.load();for(const segment of view.segments.filter(value=>value.row==='Unplanned'||value.row==='Ambiguous'))view=await app.service.act({action:'accept',key:segment.key,token:view.token});for(const item of view.items)view=await app.service.act({action:'approve',item:item.id,confirmNoChange:item.count===0,token:view.token});
1067+
let reloaded=false;
1068+
await page.route('**/api/review',async route=>{const response=await route.fetch(),body=await response.json();
1069+
// Without a runner (no `job` key): blockers keep Merge PR disabled; the reload clears them but stays not ready.
1070+
body.merge={...body.merge,ready:false,action:null,queue:null,blockers:reloaded?[]:[...body.merge.blockers,...jobResolvedBlockers]};
1071+
await route.fulfill({response,json:body});});
1072+
await page.goto(app.url);
1073+
await expect(page.locator('#merge-details')).toBeVisible({timeout:10_000});
1074+
await page.locator('#merge-details').focus();
1075+
reloaded=true;
1076+
const answered=page.waitForResponse(response=>response.url().endsWith('/api/review'));
1077+
await page.locator('#review-link').dispatchEvent('click');
1078+
await answered;
1079+
await expect(page.locator('#merge-details')).toBeHidden();
1080+
await expect(page.locator('#merge')).toBeDisabled();
1081+
await expect(page.locator('#reload')).toBeFocused();
1082+
});
10601083
for (const control of ['merge','merge-details'] as const) for (const reload of ['unavailable','failed'] as const) test(`moves focus off ${control==='merge'?'Merge PR':'the blockers button'} to Refresh when a reload ${reload==='failed'?'fails':'makes merging unavailable'} (D16)`,async({page})=>{
10611084
const config={...app.service.config,demo:false};await app.close();removeDemoOutOfScope(config);
10621085
const gateway:MergeGateway={inspect:async()=>{const snapshot=(await app.service.load()).snapshot;return {base:snapshot.base,head:snapshot.head,pullRequestState:'OPEN',mergeable:'MERGEABLE',rulesKnown:true,atomicBaseGuard:true,mergeQueue:false,requiredChecks:[],alreadyFixed:'clear',pullRequest:7,draft:false};},merge:async()=>{throw new Error('The browser test answers every merge request itself.');}};

‎web/public/app.js‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,20 @@ async function refresh() {
176176
if (!data) renderPlans();
177177
}
178178
}
179-
/** Where focus goes when the focused merge control hides: Merge PR while it is shown and enabled, otherwise Refresh. */
179+
/**
180+
* Where focus goes when the focused merge control hides: Merge PR while it is shown and not `disabled` (an
181+
* `aria-disabled` Merge PR still takes focus), otherwise Refresh.
182+
*/
180183
function mergeFocusFallback() {
181184
return !$("merge").hidden && !$("merge").disabled ? $("merge") : $("reload");
182185
}
183186
function renderMerge() {
184-
// Read before rendering: hiding the focused control blurs it at once. A render that hides the focused merge control (or
185-
// its blockers button) moves focus to what is still shown and enabled, once the controls' final state is set (AGENTS.md).
187+
// Read before rendering: hiding the focused control itself blurs it at once (hiding its parent does so at the next
188+
// frame). A render that hides the focused merge control, its blockers button or Cancel moves focus to the fallback once
189+
// every control's final state is set (AGENTS.md).
186190
const focused = document.activeElement;
187191
renderMergeControls();
188-
renderMergeSteps();
192+
renderMergeSteps(focused);
189193
if ((focused === $("merge") || focused === $("merge-details")) && focused.hidden) mergeFocusFallback().focus();
190194
}
191195
function renderMergeControls() {
@@ -225,7 +229,6 @@ function renderMergeControls() {
225229
// Keep the control focusable while its job runs; repeat activation is ignored because the merge is not ready.
226230
$("merge").setAttribute("aria-disabled", "true");
227231
$("merge").textContent = mergeJobStepLabel(job);
228-
$("merge-details").hidden = false;
229232
$("merge-details").textContent = "Merge status";
230233
scheduleMergePoll();
231234
return;
@@ -381,15 +384,15 @@ function mergeStepElapsed(step, now = Date.now()) {
381384
* The step list under the review strip, with Cancel, while a job runs and after the page saw it end (until Refresh).
382385
* A job saved before step lists existed has none: the control and banner say its step, as before.
383386
*/
384-
function renderMergeSteps() {
387+
/** `focused` is the element that had focus before the update began (the caller reads it before any control hides). */
388+
function renderMergeSteps(focused = document.activeElement) {
385389
const job = data?.merge?.available ? data.merge.job : null;
386390
const ended = data?.merge?.blockers?.some(blocker => blocker.code === "job-refresh") || (!!job && data.merge.endedJobShown === job.id);
387391
const shown = !!job?.steps && (job.state === "running" || ended);
388392
$("merge-steps-bar").hidden = !shown;
389393
if (mergeStepTimer && !(shown && job.state === "running")) { clearInterval(mergeStepTimer); mergeStepTimer = null; }
390-
// Hiding a focused Cancel (or the whole bar) would drop keyboard focus to the page: it moves to the merge control
391-
// instead, or to Refresh when that control is hidden too.
392-
if ((!shown || job.state !== "running") && document.activeElement === $("merge-cancel")) mergeFocusFallback().focus();
394+
// Hiding a focused Cancel (or the whole bar) would drop keyboard focus to the page: it moves to the fallback instead.
395+
if ((!shown || job.state !== "running") && focused === $("merge-cancel")) mergeFocusFallback().focus();
393396
if (!shown) return;
394397
// Rebuilt only when a step changes; the timer below rewrites the elapsed times alone, so a screen reader keeps its place.
395398
const key = JSON.stringify(job.steps);

0 commit comments

Comments
 (0)