New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 662036 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
NOT IN USE
Closed: Nov 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

:last-of-type not working for children of body in JS

Reported by chrisbru...@gmail.com, Nov 3 2016

Issue description

Chrome Version       : 54.0.2840.71 (Official Build) (64-bit)
URLs (if applicable) :
Other browsers tested:
  Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
     Safari:
    Firefox: OK 47.0.1
         IE: 11

What steps will reproduce the problem?
(1) Create a new HTML document with 3 SECTION elements within the BODY
(2) Attempt to use document.querySelector('section:last-of-type') to select the last section

What is the expected result?
Should return the last section

What happens instead?
Returns undefined


Please provide any additional information below. Attach a screenshot if
possible.
If nested in another element (such as a MAIN) then the selector works as expected
 
Cc: hdodda@chromium.org
Labels: Needs-Feedback
@chrisbruford -- Could you please provide us the sample test file or a test case to reproduce the issue , it would be helpful for us to triage the issue better. 

Please provide us the OS details , in which you faced the issue.

Thanks !
Example attached. If you simply wrap the 3 paragraph elements in a <section> then the selector then works as expected.

This is Windows 10 and OSX (El Capitan)

Works in IE and Firefox
Fails in Chrome and Safari
bug.html
998 bytes View Download
Components: Blink>CSS

Comment 4 by r...@opera.com, Nov 15 2016

Labels: -Needs-Feedback OS-All
Owner: r...@opera.com
Status: Started (was: Unconfirmed)

Comment 5 by r...@opera.com, Nov 15 2016

Labels: Hotlist-Interop
Project Member

Comment 7 by bugdroid1@chromium.org, Nov 16 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/2b2e6f1d8ded02c97fbdda7088e24f84ad035ea3

commit 2b2e6f1d8ded02c97fbdda7088e24f84ad035ea3
Author: rune <rune@opera.com>
Date: Wed Nov 16 15:22:26 2016

Let querySelector(All) match (nth-)last with unclosed parent.

While parsing, we don't match :last*, :nth-last* etc until we finish
parsing children to avoid alternating between different computed styles
during loading. For querying selectors, however, we should. I couldn't
find this explicitly mentioned in w3c or whatwg specs for
querySelector(All), but Firefox and IE does this.

This could happen if you have:

<body>
  <p></p>
  <p></p>
  <script>document.querySelector("p:last-of-type")</script>
</body>

Adding expectations file for a wpt which now fails. The modifications
to the test has been upstreamed to the github repo. See PR [1].

[1] https://github.com/w3c/web-platform-tests/pull/4216

R=sashab@chromium.org
BUG= 662036 

Review-Url: https://codereview.chromium.org/2505543004
Cr-Commit-Position: refs/heads/master@{#432493}

[add] https://crrev.com/2b2e6f1d8ded02c97fbdda7088e24f84ad035ea3/third_party/WebKit/LayoutTests/imported/wpt/shadow-dom/untriaged/shadow-trees/upper-boundary-encapsulation/test-009-expected.txt
[modify] https://crrev.com/2b2e6f1d8ded02c97fbdda7088e24f84ad035ea3/third_party/WebKit/Source/core/css/SelectorChecker.cpp
[modify] https://crrev.com/2b2e6f1d8ded02c97fbdda7088e24f84ad035ea3/third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp

Comment 8 by r...@opera.com, Nov 16 2016

Status: Fixed (was: Started)
:first-child doesn't match the html element in Chrome, is this a bug?


屏幕快照 2016-11-17 上午11.44.08.png
108 KB View Download
屏幕快照 2016-11-17 上午11.44.55.png
95.3 KB View Download
The html element is the root element of a document and so not a child of
anything. Therefore I don't believe that behaviour to be a bug...

Comment 11 by r...@opera.com, Nov 17 2016

Comment #10 is correct.
Re #10 #11, seems like this has changed in selectors level 4, I raised a  issue 666655 .

Sign in to add a comment