Skip to content

Clarify that declarative custom element definitions don't contain declarative shadow roots. #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

justinfagnani
Copy link
Contributor

The current Declarative Custom Elements Strawman was authored before Declarative Custom Elements was specified, and the pattern of putting shadow root instance options on the <template> element. Now that that pattern does exist, it has created something of an semantic ambiguity with the strawman syntax. (with the assumption that shadowmode should be updated to shadowrootmode).

In this example, is <template shadowmode="open"> intended to do?

<definition name="my-element" constructor="MyElement">
    <template shadowmode="open">~</template>
</definition>

Does it:

  1. Create a shadow root on the <definition> element
  2. Define a template with options to be used to initialize instance shadow roots.

If the answer is (2), then we have the same syntax with two different behaviors: one creates a shadow root instance, one defines future shadow roots.

Since the strawman was created before DSD, it doesn't seem like this collision was intended. I think to separate DSD from declarative custom elements, even just in this strawman syntax, we should make a small edit to put the options on a new element. This has the benefit of shortening the option names by not requiring the shadowroot prefix on every one.

<definition name="my-element" constructor="MyElement">
    <shadowoptions mode="open"></shadowoptions>
    <template>~</template>
</definition>

cc @rniwa

@sashafirsov
Copy link

<shadowoptions mode="open"></shadowoptions> given an impression that multiple modes can be applied to the DCD.

Alternatively mode placed on <template> or <definition> is always unique. Which IMO is preferred to avoid potential mistakes and validation ambiguity.

@trusktr
Copy link
Contributor

trusktr commented Apr 16, 2025

@sashafirsov the rule could be only one <shadowoptions> element is allowed (any more are ignored).

@sashafirsov
Copy link

@trusktr

the rule could be only one element is allowed (any more are ignored).

which creates ambiguity as on implementor' side( last or first to be used?) as for web app developer. Better to avoid that. Attributes been created exactly for the case when only one key is permitted.

@JRJurman
Copy link

@justinfagnani - I think this makes sense, but did you have an idea of what the behavior should be when this <shadowoptions> is missing? Is there a default behavior expected, or should we fail to build the component if these options aren't defined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants