-
Notifications
You must be signed in to change notification settings - Fork 951
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
Mutation handling breaks querySelectorAll initialization #445
Comments
Please hold off on this for now -- I have a feeling it isn't mutations that's the problem, but The same principle applies, though. During the context of an insertion after a change in context, the handler of a |
Mutation Events like |
I'm going to close the issue now; we can reopen if we have a test case showing the issue with Mutation Observers instead of Mutation Events. |
I also experience this problem on jQuery 1.12.4 A quick fix that removes the error would be to replace
with
although it is not entirely clear if there are any negative consequences of this change. |
During initialization, mutation event handling can mean that
rbuggyQSA
is temporarily in an inconsistent state. This breaksSizzle.matchesSelector()
, and thereforeJQuery.find()
, for example, when used in certain mutation event handler.The issue is:
rbuggyQSA
is initialized to an empty arrayquerySelectorAll
, values are added torbuggyQSA
rbuggyQSA
is converted to a RegexpBecause a mutation observer might be called at Step 2 (it turns out, this isn't in my code, but a library I am using), and if that library happens to call
jQuery.find()
,rbuggyQSA
will still be an array, and thereforeSizzle.matchesSelector()
will error out with a message like:I just came across this awkward issue in the wild. I'm working on a small reproduction, but the stack trace makes it fairly clear where the issue lies. It's also been observed elsewhere, e.g.: StevenDevooght/tinyMCE-mention#64.
I'm not sure what the best resolution of this is. If we could detect the issues without adding elements, that would be one strategy. A second might be to ensure that rbuggyQSA is handled more atomically, with the candidate patterns in a second variable before conversion to a Regexp. (This is because my code is actually using
jQuery.parseHTML()
, which is setting up a new document temporarily, and, therefore,rbuggyQSA
probably doesn't need to be re-computed for each new document (and right now, that does seem to be the case).The text was updated successfully, but these errors were encountered: