Re: [whatwg/dom] Disconnect single target instead of all (#126)

I encountered an infinite-loop scenario from improperly using `disconnect` (assuming it works like `unobserve` for all targets in observer's node list)

1. receiving a mutation record at an observed target (inside `MutationObserver`'s callback)
2. stop observing this target by calling `disconnect` (**unexpected: the target still remains in the mutation observer's node list**)
3. handle the mutation record (action here will manipulate the DOM and will trigger another mutation record if this target is still observed)
4. re-observing the previously observed target -- call `observe` on this target (**the target now have two occurrences in the mutation observer's node list**)
5. this already-handled-once mutation record is dispatched again to newly added target due to live editing of node list
6. infinite loop

I think I mistakenly used `disconnect` as `unobserve` for all, which might be another reason why a separate `unobserve` method is beneficial for inexperienced programmer like me.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/126#issuecomment-820989311

Received on Friday, 16 April 2021 07:50:18 UTC