Skip to content

Commit

Permalink
Bug 1878205 [wpt PR 44369] - Change the behavior of clonable to be mo…
Browse files Browse the repository at this point in the history
…re opt-in, a=testonly

Automatic update from web-platform-tests
Change the behavior of clonable to be more opt-in

See the discussion here:

whatwg/html#10107 (comment)

The existing *shipped* behavior (i.e. before the `clonable` concept
was introduced) was that any declarative shadow root *within a `<template>`* would be automatically cloned, but no others.

The semi-new behavior is the `clonable` bit concept, in which all
declarative shadow roots have their `clonable` bit set to true, so
they automatically get cloned by `cloneNode()`. That's regardless of
whether they are inside or outside a template.

The new consensus is that the "semi-new" clonable behavior is likely
web-incompatible, because clones will just start getting shadow roots
included. Plus it wasn't very developer-desirable. The new consensus
is therefore to add a `shadowrootclonable` attribute for declarative shadow dom that allows a shadow root to opt-in to this behavior, but
the default for all shadow roots will be `clonable=false`.

This CL implements the new consensus behind the ShadowRootClonable
flag. If the flag is false, the "shipped" behavior will be emulated
via setting `clonable` in an equivalent way.

See these three spec PRs:
  whatwg/dom#1246
  whatwg/html#10069
  whatwg/html#10117

Bug: 1510466
Change-Id: Ice7c7579094eb08b882c4bb44f93045f23b8f222
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5260748
Reviewed-by: David Baron <dbaronchromium.org>
Auto-Submit: Mason Freed <masonfchromium.org>
Commit-Queue: Mason Freed <masonfchromium.org>
Cr-Commit-Position: refs/heads/main{#1258910}

--

wpt-commits: 33d11f1db34802fda00e64ddeb0b7ef040cf65be
wpt-pr: 44369

UltraBlame original commit: 7d4902dfa32c013568c445861c332c29e4c1134f
  • Loading branch information
marco-c committed Feb 16, 2024
1 parent 4449eb4 commit c078a9a
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -525,6 +526,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -748,6 +750,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -1036,6 +1039,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -520,6 +521,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -737,6 +739,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down Expand Up @@ -1013,6 +1016,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,186 @@
'
)
;
test
(
(
)
=
>
{
const
div
=
document
.
createElement
(
'
div
'
)
;
div
.
setHTMLUnsafe
(
<
div
id
=
"
host
"
>
<
template
shadowrootmode
=
"
open
"
shadowrootclonable
>
<
/
template
>
<
/
div
>
)
;
var
host
=
div
.
querySelector
(
'
#
host
'
)
;
assert_true
(
!
!
host
.
shadowRoot
"
No
shadow
root
found
"
)
;
assert_true
(
host
.
shadowRoot
.
clonable
"
clonable
should
be
true
"
)
;
div
.
setHTMLUnsafe
(
<
div
id
=
"
host
"
>
<
template
shadowrootmode
=
"
open
"
>
<
/
template
>
<
/
div
>
)
;
host
=
div
.
querySelector
(
'
#
host
'
)
;
assert_true
(
!
!
host
.
shadowRoot
"
No
shadow
root
found
"
)
;
assert_false
(
host
.
shadowRoot
.
clonable
"
clonable
should
be
false
without
the
shadowrootclonable
attribute
"
)
;
}
'
Declarative
Shadow
DOM
:
clonable
attribute
'
)
;
<
/
script
Expand Down Expand Up @@ -1531,8 +1711,9 @@
'
)
;
assert_equals
(
const
leftover
=
host
.
querySelector
Expand All @@ -1541,15 +1722,57 @@
template
'
)
null
"
No
;
assert_true
(
!
!
leftover
"
The
second
(
duplicate
)
template
nodes
from
either
root
should
be
left
in
the
DOM
"
)
;
assert_true
(
leftover
instanceof
HTMLTemplateElement
)
;
assert_equals
(
leftover
.
getAttribute
(
'
shadowrootmode
'
)
"
closed
"
)
;
assert_equals
(
leftover
.
shadowRootMode
"
closed
"
)
;
Expand Down Expand Up @@ -1595,14 +1818,14 @@
textContent
'
root
2
1
'
"
Content
should
come
from
last
first
declarative
shadow
root
Expand Down Expand Up @@ -1649,6 +1872,7 @@
shadowrootmode
=
open
shadowrootclonable
>
Content
<
Expand Down Expand Up @@ -2043,6 +2267,10 @@
declarative
shadow
root
(
with
shadowrootclonable
)
'
)
;
Expand Down Expand Up @@ -2092,6 +2320,7 @@
shadowrootmode
=
open
shadowrootclonable
>
Content
<
Expand Down Expand Up @@ -2287,6 +2516,7 @@
shadowrootmode
=
open
shadowrootclonable
>
Content
<
Expand Down Expand Up @@ -2473,6 +2703,7 @@
shadowrootmode
=
open
shadowrootclonable
>
<
video
Expand Down
Loading

0 comments on commit c078a9a

Please sign in to comment.