Skip to content

Conversation

@karlseguin
Copy link
Collaborator

1 - Always fire the callback on the next tick. This is probably the most important change, as frameworks like React don't react well if the callback is fired immediately (they expect to continue processing the page in its current state, not in the mutated state from the callback)

2 - Always fire the callback for observed elements with a parent, whether or not those intersect or are connected. From MDN, the callback is fired "The first time the observer is initially asked to watch a target element."

3 - Add a mutation observer so that if a node is added to the root (or removed) the callback is fired. This, I think, is the best we can currently do for "intersection".

karlseguin added a commit to lightpanda-io/demo that referenced this pull request Oct 8, 2025
Previously, we were reusing the same page for all cases. But that causes an
issue with lightpanda-io/browser#1130 and, from Google
AI answer, seems to be a common cause of various errors (network, timeouts, ...)

For us, the specific problem is that puppeteer registers an
IntersectionObserver (why?), but the scrip then does another page.goto,
preventing the IntersectionObserver from ever calling back. This ends up
blocking puppeteer.

It wasn't an issue before, because we fired the callback synchronously. But that
was not a correct behavior. This is probably something we should support, but
it isn't clear how. Does Chrome keep the "old" page context around to fulfill
these events?
1 - Always fire the callback on the next tick. This is probably the most
important change, as frameworks like React don't react well if the callback is
fired immediately (they expect to continue processing the page in its current
state, not in the mutated state from the callback)

2 - Always fire the callback for observed elements with a parent, whether or
not those intersect or are connected. From MDN, the callback is fired
"The first time the observer is initially asked to watch a target element."

3 - Add a mutation observer so that if a node is added to the root (or removed)
the callback is fired. This, I think, is the best we can currently do for
"intersection".
@karlseguin karlseguin force-pushed the intersection_observer branch from b6c52e3 to 75e0637 Compare October 9, 2025 08:29
@karlseguin karlseguin merged commit f6d77af into main Oct 10, 2025
10 checks passed
@karlseguin karlseguin deleted the intersection_observer branch October 10, 2025 03:10
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants