fix(children directive): Capture target via closure to fix NgZone compatibility#7241
Merged
janechu merged 2 commits intomicrosoft:mainfrom Feb 27, 2026
Merged
Conversation
d4ae70f to
90e695e
Compare
Collaborator
|
Hi @Mich0608, thanks for the contribution! Could you post a comment to agree to the license? |
Contributor
Author
|
@janechu Sorry, I just saw this! @microsoft-github-policy-service agree company="Microsoft" |
added 2 commits
February 27, 2026 09:36
…standard observer.target property assignment
90e695e to
25d0a3a
Compare
janechu
approved these changes
Feb 27, 2026
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.
Pull Request
📖 Description
This PR refactors the
ChildrenDirectiveto use proper closure-based state management instead of dynamically assigning properties toMutationObserverinstances, fixing compatibility issues with Angular and improving overall code quality.Problem with current implementation:
The current code assigns a custom
targetproperty directly toMutationObserverinstances:This approach has several issues:
targetis not a defined property onMutationObserver, so this relies on JavaScript's dynamic property assignmentMutationObserverto intercept callbacks for change detection, the observer instance passed to the callback is the patched version, not the native instance where thetargetproperty was assigned. This causesCannot read property 'target' of undefinederrors in Angular applications.Solution:
Refactor to use closure scope for state management. By creating the callback function inside
observe(), thetargetis naturally captured in the closure, eliminating the need to attach custom properties to the observer.🎫 Issues
👩💻 Reviewer Notes
📑 Test Plan
ChildrenDirectiveshould pass unchanged✅ Checklist
General
$ npm run change⏭ Next Steps