Bug 217537 - replaceChildren() (with no arguments) silently does nothing rather than removing the children
Summary: replaceChildren() (with no arguments) silently does nothing rather than remov...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari Technology Preview
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on: 198578
Blocks:
  Show dependency treegraph
 
Reported: 2020-10-09 15:26 PDT by Ashley Gullen
Modified: 2020-10-13 22:25 PDT (History)
11 users (show)

See Also:


Attachments
Patch (6.47 KB, patch)
2020-10-10 11:37 PDT, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (6.47 KB, patch)
2020-10-10 12:02 PDT, Darin Adler
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ashley Gullen 2020-10-09 15:26:39 PDT
Safari TP114 appears to ship a broken implementation of elem.replaceChildren() which is enabled by default.

Demo: https://downloads.scirra.com/labs/replacechildren.html

Click the button. It calls replaceChildren() with empty arguments to remove the three paragraphs.

It works in Chrome and Firefox and the elements disappear. In Safari it does nothing - no elements are removed.
Comment 1 Alexey Proskuryakov 2020-10-09 18:18:57 PDT
Same behavior in Safari 14.0.1 beta.
Comment 2 Radar WebKit Bug Importer 2020-10-09 18:19:12 PDT
<rdar://problem/70161896>
Comment 3 Tetsuharu Ohzeki [UTC+9] 2020-10-09 21:44:45 PDT
(In reply to Alexey Proskuryakov from comment #1)
> Same behavior in Safari 14.0.1 beta.

I seem Safari v14 does not enable `ParentNode.replaceChildren()` in the first place.

Oddly Safari TP 114 and the trunk which enables that API also does not work this.
Comment 4 Darin Adler 2020-10-10 01:34:07 PDT
This was added in r262381 and passed all the Web Platform Tests then and since. Haven’t looked at this test here yet.
Comment 5 Darin Adler 2020-10-10 11:19:28 PDT
I took a look at the DOM specification. It has an incorrect step:

https://dom.spec.whatwg.org/#dom-parentnode-replacechildren

Note that step 2 says "Ensure pre-insertion validity of node into this before null." But that should only be done if node is non-null. We should probably report that issue. If we took it literally then the function would need to throw a HierarchyRequestError exception, but clearly that’s needed.

I took a look at the Web Platform Tests.

https://github.com/web-platform-tests/wpt/blob/master/dom/nodes/ParentNode-replaceChildren.html

For some reason it does not include a test case for replaceChildren without any argument, on a parent having a child. So we pass that test even though our algorithm is incorrect.

Fixing the bug is really easy, and it’s also easy for me to add a test to WPT, but I don’t know how to correctly upstream a change like this. Could use some help with that.
Comment 6 Darin Adler 2020-10-10 11:31:28 PDT
(In reply to Darin Adler from comment #5)
> I took a look at the DOM specification. It has an incorrect step:
> 
> https://dom.spec.whatwg.org/#dom-parentnode-replacechildren

Filed https://github.com/whatwg/dom/issues/901
Comment 7 Darin Adler 2020-10-10 11:37:55 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2020-10-10 11:38:39 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 9 Darin Adler 2020-10-10 12:02:15 PDT
Created attachment 411015 [details]
Patch
Comment 10 Darin Adler 2020-10-10 12:02:56 PDT Comment hidden (obsolete)
Comment 12 Darin Adler 2020-10-10 13:39:30 PDT
Committed r268314: <https://trac.webkit.org/changeset/268314>
Comment 13 Ryosuke Niwa 2020-10-13 00:18:47 PDT
FWIW, this is definitely enabled by default on Safari 14.0.1.
Comment 14 Darin Adler 2020-10-13 09:00:25 PDT
You mean that the broken version is included in Safari 14.0.1 or that the fixed version is included in 14.0.1?
Comment 15 Tetsuharu Ohzeki [UTC+9] 2020-10-13 22:07:24 PDT
(In reply to Ryosuke Niwa from comment #13)
> FWIW, this is definitely enabled by default on Safari 14.0.1.

Oh, I'm sorry to add the incomplete implementation in bug 198578...
Comment 16 Ryosuke Niwa 2020-10-13 22:25:32 PDT
(In reply to Darin Adler from comment #14)
> You mean that the broken version is included in Safari 14.0.1 or that the
> fixed version is included in 14.0.1?

The broken version is in Safari 14.0.1.