Closed
Bug 1007649
Opened 11 years ago
Closed 11 years ago
querySelector for id on shadowRoot returns null
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
mozilla32
People
(Reporter: wilsonpage, Assigned: wchen)
References
Details
Attachments
(1 file)
3.58 KB,
patch
|
Details | Diff | Splinter Review |
myElement.shadowRoot.querySelector('#some-id'); //=> null
myElement.shadowRoot.getElementById('some-id'); //=> HTMLElement
![]() |
||
Comment 1•11 years ago
|
||
This is because querySelector makes certain optimizations for ID selectors when the node is in a document (mapping to document.getElementById in that case). And shadow roots lie about being in a document: see bug 992521.
That said, we should perhaps disable that querySelector optimization when aRoot is anonymous!
Wilson, can you please attach the testcase you were using to reproduce this bug?
Depends on: 992521
![]() |
||
Updated•11 years ago
|
Flags: needinfo?(wilsonpage)
Reporter | ||
Comment 2•11 years ago
|
||
Flags: needinfo?(wilsonpage)
![]() |
||
Comment 3•11 years ago
|
||
OK, this stuff is just totally busted. Clearly no one has ever written a test trying to querySelector on a shadowroot, since it immediately fails an assertion in FindMatchingElements:
NS_ASSERTION(aRoot->IsElement() || aRoot->IsNodeOfType(nsINode::eDOCUMENT) ||
!aRoot->IsInDoc(),
"The optimization below to check ContentIsDescendantOf only for "
"elements depends on aRoot being either an element or a "
"document if it's in the document.");
Furthermore, the shadow root does not claim to be in an anonymous subtree, so the obvious fix I was going to try won't even work.
We really need to fix bug 992521.
![]() |
||
Comment 4•11 years ago
|
||
Of course this doesn't fix the bug, because ShadowRoot is just completely fucked up
Boris, would this have to do with the crash seen here:
https://crash-stats.mozilla.com/report/index/f834ff19-e794-4eed-a9e3-4266a2140617
We only see the crash on the 6/11 build.
![]() |
||
Comment 6•11 years ago
|
||
No. In fact, I would expect this bug to be fixed now that bug 992521 is fixed. Wilson, can you confirm?
That crash is some other issue that you should probably file a separate bug on.
Flags: needinfo?(wilsonpage)
Reporter | ||
Comment 7•11 years ago
|
||
Confirmed. Original test case in comment 2 is now working as expected.
Status: NEW → RESOLVED
Closed: 11 years ago
Flags: needinfo?(wilsonpage)
Resolution: --- → FIXED
Updated•11 years ago
|
Assignee: nobody → wchen
Target Milestone: --- → mozilla32
Thanks Boris. I'll file it.
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•