Visitar URL original
Fix focus stolen by stale delayed focus in predicate editor by chelseakr-exygy · Pull Request #14367 · civiform/civiform · GitHub
Skip to content

Fix focus stolen by stale delayed focus in predicate editor - #14367

Draft
chelseakr-exygy wants to merge 2 commits into
mainfrom
chelseakr-exygy/fix-flaky-predicate-focus-test
Draft

chelseakr-exygy wants to merge 2 commits into
mainfrom
chelseakr-exygy/fix-flaky-predicate-focus-test

Conversation

@chelseakr-exygy

@chelseakr-exygy chelseakr-exygy commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Description

The "Create and edit a new predicate" browser test fails its first attempt in many CI runs and passes on retry. Focus isn't on the new subcondition's question select. This is an app bug: several handlers in admin_predicate_edit.ts focus after a 100ms setTimeout, and nothing cancels a pending one, so a stale focus on #root-node-type can fire after the subcondition already has focus.

Fix: route delayed focus through one helper that keeps a single pending timeout, and cancel it before focusing the subcondition directly. Also skip the root select focus when there are no conditions (that select is hidden then), so the Add condition button keeps its focus.

AI use: Claude Code traced the cause and wrote the change. I reviewed it.

Testing

Before: 20 of 30 local runs failed on the focus assertion. After: 17 of 20 passed, none on focus (the 3 failures were page-load timeouts on my local stack). The whole admin_predicates_expanded.test.ts file passes (11 of 11).

Checklist

General

  • Added the correct label: bug
  • Assigned to a specific person, civiform/developers, or a more specific round-robin list
  • Added an additional reviewer from civiform/eng-admin as FYI (if this PR includes functionality changes and neither you nor the primary reviewer is an admin)
  • Removed the release notes section if the title is sufficient for the release notes description
  • Created unit and/or browser tests which fail without the change (existing browser test, reproduced failing 20 of 30 runs before the change)
  • Performed manual testing (Chrome and Firefox if it includes front-end changes). Only the browser test was run so far.
  • Ensured PII wasn't added to any new logs
  • Noted in the PR description which, if any, code in this PR was generated by AI.

Several handlers focus an element after a 100ms timeout. A pending timeout
from an earlier handler (for example the root node operator focus after
adding a condition) could fire after a newer focus, such as the new
subcondition's question select, and move focus away from it.

Route delayed focus through one helper that keeps a single pending timeout,
and cancel it before focusing the subcondition directly. This also fixes the
flaky 'Create and edit a new predicate' browser test.
@chelseakr-exygy chelseakr-exygy added the bug Something isn't working label Oct 26, 2026
@chelseakr-exygy chelseakr-exygy mentioned this pull request Oct 26, 2026
8 of 28 tasks
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.63%. Comparing base (b32fd8f) to head (6c7dd23).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14367   +/-   ##
=========================================
  Coverage     82.62%   82.63%           
- Complexity     5796     5798    +2     
=========================================
  Files           620      620           
  Lines         26406    26415    +9     
  Branches       2127     2127           
=========================================
+ Hits          21818    21827    +9     
  Misses         3852     3852           
  Partials        736      736           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The delayed focus helper keeps one pending focus, so the root select focus
scheduled on page load replaced the Add condition button focus in the null
state and the button was no longer focused. The root select is hidden then,
so skip focusing it when there are no conditions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant