selectedcontent element mutation record test is wrong#55849
selectedcontent element mutation record test is wrong#55849
Conversation
|
Thanks for looking at this. The reason that there are two separate mutations in chromium is because when the third option,
This doesn't match the spec because the option element insertion steps just say to run the selectedness setting algorithm which doesn't clone anything into the selectedcontent element, but I'm not sure if that really is good behavior. Consider the following: <select id=select>
<button>
<selectedcontent></selectedcontent>
</button>
<option>one</option>
</select>
<script>
const option = document.createElement('option');
option.setAttribute('selected', '');
option.textContent = 'two';
select.appendChild(option);
</script>I think that the selectedcontent element definitely needs to be updated for the newly selected option in this case, which can only be done through the option element insertion steps, right? I think this was an oversight when I wrote this part of the spec, unless I'm missing something. I think it would probably be best to update the selectedcontent element in the selectedness setting algorithm, what do you think? |
|
My prototype handles that as part of "finishParsingChildren". I don't really care strongly what we do I suppose, but I do get the feeling we lack a lot of test coverage (what if your example was created imperatively for instance) as there's only a minimal set of tests for this new element. And also that the specification is somewhat incomplete. (I spotted Chromium setting |
This PR makes sure that the contents of the selectedcontent element stay up to date when the selected option is changed in the selectedness setting algorithm. This issue was found here: web-platform-tests/wpt#55849 (comment)
|
This PR should fix the selectedness setting issue: whatwg/html#11890 |
Introduce the HTMLSelectedContentElement and integrate it into <select>, <option> and HTMLParser. See whatwg/html#10548. There are two bugs with WPT tests which causes the third subtest in selectedcontent.html and selectedcontent-mutations.html fail. See whatwg/html#11882, web-platform-tests/wpt#55849.
Introduce the HTMLSelectedContentElement and integrate it into <select>, <option> and HTMLParser. See whatwg/html#10548. There are two bugs with WPT tests which causes the third subtest in selectedcontent.html and selectedcontent-mutations.html fail. See whatwg/html#11882, web-platform-tests/wpt#55849.
|
@josepharhar after spending quite a lot of time debugging the new tests here I'm still seeing different results from you and when I look at the Chromium code I think I understand why. Chromium has very different insertion and removal logic for I also find the arrays this test outputs incredibly hard to debug. Claude AI has been helpful, but that really shouldn't be necessary. Not sure I have great suggestions there though, but maybe some guidance as to what is going on would have helped. I'm going to update this PR with what I think the test should look like. This will require one further change to the standard for the removal case. I've added an early return there for |
The replace all primitive uses a single record for additions and removals.
3bfa3bf to
60746af
Compare
This is expected until this patch finishes getting reviewed and merged: https://chromium-review.googlesource.com/c/chromium/src/+/7127725
Agreed, when working on it locally I added console logging to be able to easily rebaseline the test, but such console logs result in lint errors (even when they are commented out if i remember correctly). I could have made a simpler test, but after hearing you say that we are lacking test coverage, I wanted to make sure that I was comprehensively testing many scenarios. |
| "Type: childList | Target: button | Added: [#text: \"\"] | After: selectedcontent", | ||
| "Type: childList | Target: select | Added: [#text: \"\"] | After: button", | ||
| "Type: childList | Target: select | Added: [option] | After: #text: \"\"", | ||
| "Type: childList | Target: selectedcontent | Removed: [#text: \"outer1\", selectedcontent, #text: \"\"]", |
There was a problem hiding this comment.
Moving this "outer1" up matches my expectations: https://chromium-review.googlesource.com/c/chromium/src/+/7127725/11/third_party/blink/web_tests/external/wpt/html/semantics/forms/the-select-element/customizable-select/selectedcontent-mutations.html
| "Type: childList | Target: selectedcontent | Removed: [#text: \"one\"]", | ||
| "Type: childList | Target: option | Added: [#text: \"two\"]", | ||
| "Type: childList | Target: selectedcontent | Added: [#text: \"two\"]", | ||
| "Type: childList | Target: selectedcontent | Added: [#text: \"two\"] | Removed: [#text: \"one\"]", |
There was a problem hiding this comment.
I don't think this change should be necessary after whatwg/html#11890 but if you want to wait for that PR to be merged first then that's ok
There was a problem hiding this comment.
I'm not entirely sure that is the approach we want. Less mutations seems better. WebKit has a single code path for selecting an option HTMLSelectElement::selectOption() which is where I update the selectedcontent element now. That seems to be doing the right thing in all cases and result in fewer mutations here.
There was a problem hiding this comment.
In the interest of keeping things moving, I think we can merge this.
I think this test will be significantly rebaselined after we make every selectedcontent element stay updated, so I anticipate we may revisit this later.
The replace all primitive uses a single record for additions and removals. With this change my prototype passes the test.
I strongly suspect
<option selected><span>span</option> three</option>is also a bug in this test, but I didn't want to change that at the same time.