fix(mock-doc): prevent infinite recursion in blur event handlers#6310
Merged
christian-bromann merged 2 commits intomainfrom Jun 20, 2025
Merged
fix(mock-doc): prevent infinite recursion in blur event handlers#6310christian-bromann merged 2 commits intomainfrom
christian-bromann merged 2 commits intomainfrom
Conversation
Fixes a regression introduced in commit 1304ffc where blur event handlers calling blur() on input elements would cause infinite recursion and "Maximum call stack size exceeded" errors. The issue occurred when: 1. input.blur() dispatches a blur event 2. blur event handler calls blur() on the same element 3. This creates an infinite loop leading to stack overflow Solution: - Add recursion prevention mechanism using WeakMap to track elements currently processing specific event types - Modify MockElement.blur() to check for existing blur processing - Allow first blur event to process normally while preventing recursive calls - Add comprehensive test case to verify fix and prevent regressions Closes: #6307
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.
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 eventquerySelectorto 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 blurthat:blur()on an input elementTest Coverage:
@Element,@State,@Listen, and@MethoddecoratorsManual 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.