🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Oct 13, 2019

Summary

qSA in IE often (but not always) doesn't find elements with an empty name
attribute selector ([name=""]). Assigning a temporary name attribute to
the document root (& removing it afterwards) seems to resolve the issue.

EDIT: Detect that & fall back to Sizzle traversal.

Fixes gh-4435

Checklist

@mgol
Copy link
Member Author

mgol commented Oct 13, 2019

+21 bytes

This only fixes the issue in IE, not Edge. See the comment at #4435 (comment) for the rationale.

@mgol
Copy link
Member Author

mgol commented Oct 13, 2019

We could also accept the perf hit & assign such a temporary name attribute in all browsers, at least once. Hopefully that wouldn't cause style recalculation as the final value would be the same as the initial one, worth checking.

@mgol mgol force-pushed the attr-empty branch 4 times, most recently from 6532f6e to c9bb72b Compare October 14, 2019 18:14
@mgol
Copy link
Member Author

mgol commented Oct 14, 2019

PR updated.

I build a test case similar to https://jsbin.com/cocaqis/1/edit?html,js but with one iframe being available immediately in the DOM (with similar DOM contents) and another similar one being added after a few seconds. If there was no workaround, all of them failed. If I added a workaround in the main doc, all succeeded. If I added one in the first iframe, the selection in the main DOM failed & then the selection in both iframes succeeded. If I added it to the second one, it was failing until the selection happened in that second iframe, then all started suceeding.

Also, if I see success, after refreshing the page (with "Always refresh from server" checked in the Network DevTools tab) I see every selection succeeding as well so the workaround even survives page refreshes.

Of course, IE being IE, it's not impossible that the workaround stops working after a while but for now I think we can work on the assumption it survives long enough. If that proves not enough, we'll depend on someone submitting an issue.

@mgol
Copy link
Member Author

mgol commented Oct 14, 2019

+30 bytes, BTW.

@mgol
Copy link
Member Author

mgol commented Oct 14, 2019

Sizzle version of the PR: jquery/sizzle#461

@mgol mgol force-pushed the attr-empty branch 3 times, most recently from 2c81e75 to ea031e8 Compare October 15, 2019 19:06
@mgol
Copy link
Member Author

mgol commented Oct 15, 2019

PR updated. [name=''] now falls back to Sizzle traversal & both IE 11 & Edge 15-18 pass all tests. +49 +50 bytes.

@mgol mgol force-pushed the attr-empty branch 4 times, most recently from 02f1756 to 4ee9ec3 Compare October 22, 2019 23:00
qSA in IE 11/Edge often (but not always) don't find elements with an empty
name attribute selector (`[name=""]`). Detect that & fall back to Sizzle
traversal.

Interestingly, IE 10 & older don't seem to have the issue.

Fixes jquerygh-4435
@mgol mgol removed the Needs review label Nov 18, 2019
@mgol mgol merged commit 05184cc into jquery:master Nov 18, 2019
@mgol mgol deleted the attr-empty branch November 18, 2019 21:11
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

Bug of find element with empty attribute in v3.4

3 participants