Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
4.45.2 (regressed in 4.38.0; 4.37.1 works)
Current Behavior
In a dist-custom-elements build, setting an attribute to the empty string (<my-cmp union> in markup, or el.setAttribute('union', '')) on a prop typed boolean | string leaves the prop at its default false. The attribute is silently ignored.
This is the same symptom as #6411, which #6413 fixed for props typed exactly boolean. A union-typed prop compiles to MEMBER_FLAGS.Any, so it skips the boolean coercion #6413 added. It then reaches this check in proxyComponent's attributeChangedCallback (src/runtime/proxy-component.ts):
if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) {
this[propName] = newValue;
}'' != false is false, so the write is skipped. The loose comparison came from #6404, which wanted null and undefined to count as equal. As a side effect, it also makes '' equal to false.
The lazy (www/dist) build of the same component is not affected.
Expected Behavior
As in 4.37.1, the attribute sets the prop to '', so the component sees the attribute as present.
System Info
System: node 22.23.2
Platform: darwin (27.0.0)
CPU Model: Apple M5 Pro (18 cpus)
Stencil: 4.45.2
TypeScript: 5.8.3
Rollup: 4.44.0Observed in Chromium (Playwright 1.62.1).
Steps to Reproduce
-
Build a component with a
boolean | stringprop using thedist-custom-elementsoutput target:@Component({ tag: 'my-cmp', shadow: true }) export class MyCmp { @Prop() bool: boolean = false; @Prop() union: boolean | string = false; render() { return <span>bool={JSON.stringify(this.bool)} union={JSON.stringify(this.union)}</span>; } }
-
Define it from
dist/componentsand set both attributes to"":<my-cmp bool union></my-cmp> <script type="module"> import { defineCustomElementMyCmp } from '/dist/components/index.js'; defineCustomElementMyCmp(); </script>
-
Read the props:
@stencil/coreboolunion4.37.1 true""4.38.0 falsefalse4.45.2 truefalseCalling
setAttribute('union', '')after definition gives the same results. Setting the property directly (el.union = '') works on every version.
Code Reproduction URL
Additional Information
Changing that comparison back to newValue !== this[propName] in @stencil/core/internal/client/index.js fixes the reproduction on 4.45.2. To keep #6404's intent, the check could treat only null and undefined as equal, for example:
const unchanged = newValue === this[propName] || (newValue == null && this[propName] == null);The loose comparison may also drop other writes on Any props, such as '0' over a current value of false or 0. We haven't tested those.
We hit this in a design system where many props are typed boolean | string so that they accept bare attributes. On 4.38 and later, every bare attribute on those props stops working in the custom-elements build.
Activity
visualkhh commentedon Nov 1, 2026
Hit the same class on my side — empty-string attributes silently becoming
false— and the loose!=in the quoted check is exactly the shape to look at.Browser ground truth (Chromium). Presence is truth for booleans, no coercion games:
setAttribute('disabled', '')→disabled === true, value stays""hidden="until-found"round-trips verbatim (enumerated, not boolean)So
''must never read back as thefalsedefault. What I use (@dooboostore/simple-web-component) handles this with a strict presence rule instead of a loose comparison: only the literal strings'false'/'0'coerce tofalse, everything else present — including''— istrue. Its own test pins it:setAttribute('open', '')→true, then'false'→false,'0'→false. No union-type special path exists to skip, so there's noMEMBER_FLAGS.Any-shaped hole for''to fall through.For the Stencil fix, the same shape applies: the
boolean | stringbranch needs the boolean-coercion path #6413 added (presence →truefor''), not the loosenewValue != this[propName]gate — that comparison is what equates''withfalsetoday. A strict== null-style null/undefined check would keep #6404's intent without swallowing empty strings.fix(runtime): keep empty attributes on boolean | string props (stenci…