[WICG/webcomponents] Reference Target: Rethinking attribute reflection for invalid reference targets (Issue #1114)

alice created an issue (WICG/webcomponents#1114)

In https://github.com/WICG/webcomponents/issues/1071 there was some consensus that getters for IDL attributes which refer to an element with an invalid reference target should return null:

> ```
> <label id="example-label" for="fancy-input">Example</label>
> <fancy-input id="fancy-input">
>   <template
>    shadowrootmode="closed"
>     shadowrootreferencetarget="real-input"
>   >
>     <div>
>       <!-- In this example, there is nothing with the ID "real-input" in the shadow tree -->
>     </div>
>   </template>
> </fancy-input>
> 
> <script>
> const label = document.getElementById('example-label');
> console.log(label.control); // << What does this log?
> ```

When writing the [relevant spec language](https://whatpr.org/html/10995/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:reflected-idl-attribute-32), I assumed this also referred to settable IDL attributes like `popovertarget`: 

> The getter steps are:
> 
> Let _candidate_ be the result of running [this](https://webidl.spec.whatwg.org/#this)'s [get the attr-associated element](https://whatpr.org/html/10995/common-microsyntaxes.html#get-the-attr-associated-element).
> 
> Return the result of [retargeting](https://dom.spec.whatwg.org/#retarget) _candidate_ against this.

where **get the _attr_-associated-element** requires [resolving the reference target](https://whatpr.org/html/10995/common-microsyntaxes.html#resolve-the-reference-target):

> The steps to resolve the reference target on an element _element_ are:
> 
> 1. If _element_ does not have a [shadow root](https://dom.spec.whatwg.org/#concept-shadow-root), or _element's_ [shadow root](https://dom.spec.whatwg.org/#concept-shadow-root)'s [reference target](https://dom.spec.whatwg.org/#shadowroot-reference-target) is null, return _element_.
> 
> 2. Let _referenceTargetValue_ be the value of _element's_ [shadow root](https://dom.spec.whatwg.org/#concept-shadow-root)'s [reference target](https://dom.spec.whatwg.org/#shadowroot-reference-target).
> 
> 3. Let _candidate_ be the first element in _element_'s [shadow root](https://dom.spec.whatwg.org/#concept-shadow-root) whose [ID](https://dom.spec.whatwg.org/#concept-id) matches _referenceTargetValue_.
> 
> 4. If no such element exists, return null.
> 
> 5. Return the result of [resolving the reference target](https://whatpr.org/html/10995/common-microsyntaxes.html#resolve-the-reference-target) on _candidate_.

meaning that if the reference target is invalid, the getter would return null, even if the attr-associated element not taking reference target into account was non-null.

However, after the discussion in https://github.com/whatwg/html/issues/11577, particularly around validation, I'm wondering whether it might make sense to have a shallower algorithm for the IDL attribute getters, essentially equivalent to the current algorithm.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1114
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1114@github.com>

Received on Thursday, 2 October 2025 09:21:58 UTC