In #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, I assumed this also referred to settable IDL attributes like popovertarget, i.e.:
<button popoverTarget="myPopover">Open popover</button>
<my-popover id="myPopover">
<template
shadowRootMode="closed"
shadowRootReferenceTarget="BROKEN">
<div popover>The real popover target</div>
</template>
</my-popover>
console.log(button.popoverTarget); // logs null
The getter steps are:
Let candidate be the result of running this's get the attr-associated element.
Return the result of retargeting candidate against this.
where get the attr-associated-element requires resolving the reference target:
The steps to resolve the reference target on an element element are:
-
If element does not have a shadow root, or element's shadow root's reference target is null, return element.
-
Let referenceTargetValue be the value of element's shadow root's reference target.
-
Let candidate be the first element in element's shadow root whose ID matches referenceTargetValue.
-
If no such element exists, return null.
-
Return the result of resolving 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 whatwg/html#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.
In #1071 there was some consensus that getters for IDL attributes which refer to an element with an invalid reference target should return null:
When writing the relevant spec language, I assumed this also referred to settable IDL attributes like
popovertarget, i.e.:where get the attr-associated-element requires resolving the reference target:
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 whatwg/html#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.