Repository navigation
Fix focus stolen by stale delayed focus in predicate editor - #14367
Draft
chelseakr-exygy wants to merge 2 commits into
Draft
chelseakr-exygy wants to merge 2 commits into
chelseakr-exygy wants to merge 2 commits into
Conversation
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.
8 of 28 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsfocus after a 100mssetTimeout, and nothing cancels a pending one, so a stale focus on#root-node-typecan 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.tsfile passes (11 of 11).Checklist
General
civiform/developers, or a more specific round-robin listciviform/eng-adminas FYI (if this PR includes functionality changes and neither you nor the primary reviewer is an admin)