-
Notifications
You must be signed in to change notification settings - Fork 298
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
mutationObserver.disconnect({ flush: true })
#1283
Comments
as one that has been using MO forever (polyfills included) I never even thought the leaky records would be a problem but I fully agree with this issue concerns and I also need to likely update all my libraries heavily based on MO to guarantee something not observed anymore won't be processed after a Thanks for considering this bug and raising its importance too, if needed. |
Definitely interesting and I think it'd be nice to have this as a feature of MutationObserver...from a topical assessment it doesn't seem like this would break anything. I agree that I'm open to implementing something or helping out with the specs if this issue ready for those! |
I actually wonder if this might be something we could simply fix. Code that follows the pattern in my first comment won't break, it will simply take the records before If not, another solution is to introduce a different method, and deprecate @annevk What do you think? |
I'm not sure. @smaug---- and @rniwa are probably better equipped to judge the impact of such a change. |
Adding option to |
The rest is not already broken. disconnect() was designed to stop observing anything, very explicit. No different to removeEventListener. (There might be an event queued in a task, and you won't get that event if removeEventListener is called). If we add a dictionary to disconenct() for flush, I wonder if we want also explicit flush() which is like takeRecords() but calls the callback. |
We can't keep adding API surface for every fix. How would sites be depending on the behavior of pending records not being taken? Anyhow, if the compat risk is deemed too high I think a new method might be better, so we can gradually steer people towards using that, rather than being stuck with a method where you need to pass an optional parameter in 99.9% of the time (like
How frequently does that happen though? It sounds like an extremely rare race condition, whereas what I’m talking about here happens way more.
That seems like a good idea! |
👍 for edit if there's any doubt around why the edit 2 dare I say |
@LeaVerou what do you envision this addition looking like? Is it better to have redundant options (like giving developers the choice between passing in a dictionary to @smaug---- Do you know why |
The proposed disconnect option would also be useful to me — and a (And yep: I’d also love an unobserve-specific-node-only method — though I imagine that would probably merit its own issue.) |
What problem are you trying to solve?
Calling
mutationObserver.disconnect()
while forgetting to handle any pending records is a common footgun.What solutions exist today?
Having to write boilerplate like:
Every time you want to stop observing is quite repetitive, and it cannot be done with just a reference to the mutation observer, since it requires a reference to its callback too.
How would you solve it?
Add a dictionary argument to
disconnect()
with aflush
option (name TBB) that does exactly this.Anything else?
No response
The text was updated successfully, but these errors were encountered: