-
Notifications
You must be signed in to change notification settings - Fork 12
feat: support new page triggers - element appeared, element visible and manual #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
📝 Documentation updates detected! New suggestion: Document new page trigger types for Web Experiment |
Add page triggers for element visibility and appearance and add manual trigger via
|
| observerKey, | ||
| observer, | ||
| ] of this.intersectionObservers.entries()) { | ||
| const [selector] = observerKey.split(':'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting observerKey on : breaks selectors with colons (e.g., input:checked, div:nth-child(2)). Consider splitting at the last colon so the selector stays intact.
| const [selector] = observerKey.split(':'); | |
| const selector = observerKey.slice(0, observerKey.lastIndexOf(':')); |
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
| // TODO: to cleanup and centralize state management | ||
| private setupUrlChangeReset = () => { | ||
| // Reset element state on URL navigation | ||
| this.messageBus.subscribe('url_change', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL-change handling isn’t idempotent: stale visibility state/observers persist and event listeners accumulate. Consider a centralized URL-change reset that disconnects IntersectionObservers, clears elementVisibilityState, and guarantees a single reusable element_appeared subscription (or add per-listener unsubscribe in MessageBus).
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
| if (node instanceof Element) { | ||
| try { | ||
| // Check if the added node itself matches | ||
| if (node.matches(selector)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyiuhc From a very brief google search, it seems that node.querySelector needs to traverse the whole document anyways so you might as well just use document.querySelector(selector) once instead of looping through these mutation changes.
Summary
Checklist