fix(mock-doc): prevent infinite recursion in blur event handlers #6310
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.
What is the current behavior?
A regression was introduced in commit 1304ffc that causes infinite recursion when blur event handlers call
blur()
on input elements within the mock DOM environment. This results in "Maximum call stack size exceeded" errors during Stencil tests.The issue manifests when:
input.blur()
is called, which dispatches a blur eventquerySelector
to find elementsblur()
on the same input element againGitHub Issue Number: #6307
What is the new behavior?
Added a recursion prevention mechanism that:
The fix is targeted specifically at the
MockElement.blur()
method and uses efficient tracking with proper cleanup to avoid memory leaks.Documentation
N/A - This is a bug fix that doesn't require documentation changes.
Does this introduce a breaking change?
This fix maintains full backward compatibility. All existing event tests continue to pass, and the change only affects the specific edge case of recursive blur event dispatching.
Testing
Unit Tests:
should prevent infinite recursion when blur event handler calls blur
that:blur()
on an input elementTest Coverage:
@Element
,@State
,@Listen
, and@Method
decoratorsManual Verification:
Other information
Technical Implementation Details:
MockElement.blur()
level rather than the general event dispatching level for precise controlFiles Modified:
src/mock-doc/node.ts
: Added recursion prevention toMockElement.blur()
methodsrc/runtime/test/event.spec.tsx
: Added test case for recursion preventionThis fix ensures Stencil tests can run reliably without encountering stack overflow errors when blur event handlers interact with input elements.