fix: stop stale refs from silently no-oping and suggest the current ref - #342
Merged
Merged
Conversation
# Conflicts: # CHANGELOG.md # test/unit/accessibility-tree.test.ts
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.
A ref whose element was re-rendered usually didn't fail.
surf click e4printed OK and did nothing. Surf kept the removed node reachable throughwindow.__piRefs, so the click went to an element no longer on the page. On pages where handlers sit on the document (React), nothing happened. The "not found" error only appeared after garbage collection.Now a ref works only if its element is still on the page. When it isn't, the error suggests the current element when exactly one visible element has the same role and accessible name:
With zero or several matches it says to run
surf read. It never suggests an element with a different role or name, or one inside anaria-hiddensubtree.locate.role,locate.textandlocate.labelnow record the element's real role and name for its ref instead of the search text, so their refs get correct suggestions.generateAccessibilityTree, and the identical copy ingenerateYamlTreeis deleted, so suggestion names matchsurf readoutput.readoutput is unchanged.stale_observation, which the semantic CLI already refreshes and retries.Refs that survive re-renders are deferred. Checking real sites: keyed React updates (sorting, tabs, react-select, controlled inputs) keep their nodes. A Vue list filter and restore replaced 419 of 499 nodes, and a react.dev page change replaced 583 of 623. Many replaced elements share a role and name: 210 of 419 and only 9 of 208 had a unique match. Carrying refs over automatically would often pick the wrong element. Revisit if the "Did you mean" error shows up often in real agent runs.
Tests: unit tests for a swapped button, different role or name, several matches, unknown refs, locate refs with a partial name, and an
aria-hiddencontainer. A real-Chrome e2e case checks the suggestion and that clicking the suggested ref works. Full unit suite, check, lint and real-Chrome e2e pass locally under Node 24.Closes #340