Instantiator Adjustments#1478
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors RecommendationInstantiator to improve SPA navigation behavior by creating more granular DomTargeter instances, tracking targeted elements, and adding controller cleanup to prevent stale controllers from lingering.
Changes:
- Added
DomTargeter.getTargetedElems()and began tracking targeted elements for non-inject targets. - Refactored
RecommendationInstantiatorto use per-profile/per-element targeters and introducedcleanupStaleControllers()for SPA DOM replacement scenarios. - Expanded tests for SPA navigation, controller uniqueness per element, and cleanup behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/snap-toolbox/src/DomTargeter/DomTargeter.ts | Exposes targeted elements and expands tracking of targeted nodes. |
| packages/snap-toolbox/src/DomTargeter/DomTargeter.test.ts | Adds unit coverage for getTargetedElems(). |
| packages/snap-preact/src/Snap.tsx | Adjusts RecommendationInstantiator import to type-only. |
| packages/snap-preact/src/Instantiators/RecommendationInstantiator.tsx | Refactors instantiation/targeting logic; adds stale controller cleanup. |
| packages/snap-preact/src/Instantiators/RecommendationInstantiator.test.tsx | Adds/updates tests for unique controllers and SPA cleanup flows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
korgon
commented
Apr 23, 2026
korgon
commented
Apr 23, 2026
korgon
commented
Apr 23, 2026
…ck and reusing controller
… integration docs
… controller id on targetElem
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
chrisFrazier77
previously approved these changes
Apr 24, 2026
chrisFrazier77
approved these changes
Apr 24, 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.
This pull request significantly improves the documentation and implementation of the
RecommendationInstantiator, clarifies the behavior for grouped and legacy script block integrations, and adds robust test coverage for edge cases such as SPA navigation, DOM changes, and controller cleanup. The changes ensure that controllers are managed correctly when DOM elements are added or removed, and clarify how controllers are shared or separated based on profile configuration.Documentation Updates:
Behavioral Clarifications and Implementation:
DomTargeterinstances ensure each controller tracks its specific elements, and controllers are only created if the source script element is still connected to the DOM (important for SPA navigation). [1] [2] [3] [4] [5]Testing Enhancements:
profileCountincrements correctly when DOM is replaced and retargeted.Other Notable Improvements:
createRecommendationControllerand improving code comments.These changes collectively make the recommendation integration more robust, maintainable, and easier for both developers and users to understand.
Documentation and Integration Behavior:
config.beaconoption for beacon tracking settings.Controller Management and SPA Support:
Testing and Edge Case Handling:
Code Quality and Maintainability:
createRecommendationController.Test Setup Improvements: