Skip to content

Conversation

@tyiuhc
Copy link
Collaborator

@tyiuhc tyiuhc commented Dec 16, 2025

Summary

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

@promptless
Copy link

promptless bot commented Dec 17, 2025

📝 Documentation updates detected!

New suggestion: Document new page trigger types for Web Experiment

@macroscopeapp
Copy link

macroscopeapp bot commented Dec 18, 2025

Add page triggers for element visibility and appearance and add manual trigger via DefaultWebExperimentClient.activate across experiment-tag package

Introduce element_visible and element_appeared trigger handling with IntersectionObserver and filtered MutationObserver pipelines, add activate(name) to publish a manual trigger, and define discriminated trigger types in types.ts. Debounce for mutation processing changes to 100ms. Tests add observer mocks.

📍Where to Start

Start with trigger evaluation and publishers in SubscriptionManager in subscriptions.ts, then review the new activate method in experiment.ts and payload/types in types.ts.


📊 Macroscope summarized ca355c0. 5 files reviewed, 4 issues evaluated, 1 issue filtered, 2 comments posted. View details

observerKey,
observer,
] of this.intersectionObservers.entries()) {
const [selector] = observerKey.split(':');
Copy link

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.

Suggested change
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', () => {
Copy link

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)) {
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants