`useDefault: true` doesn't work when a property is initialized to `null`
Author: justinfagnaniCreated Jul 25, 2026Updated Jul 25, 2026
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
The docs for useDefault say a property must be initialized, but don't say the initial value can't be null or undefined and it can't: useDefault uses ?? to both record and restore the default value, so it can't tell "no default recorded" from "the default is null/undefined".
This causes bugs in a few cases:
nullinitial value with standard decorators throws when the element is constructed.foo: string | undefined = undefined: removing the attribute sets the property tonullrather thanundefined.accessor foo: string | undefined = undefined, or a getter/setter pair: the default is never recorded at initialization (the init paths skipundefinedvalues), so the first value the user sets is recorded as the "default". Removing the attribute then restores that value instead ofundefined, i.e. it appears to do nothing.
Reproduction
The null-default case:
class MyEl extends LitElement {
@property({reflect: true, useDefault: true})
accessor foo: string | null = null;
}
new MyEl();
// TypeError: Private element is not present on this object
// at ReactiveElement._$changeProperty (reactive-element.ts:1339)
// at init (decorators/property.ts:157)
Workaround
Don't use null defaults?
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
3.3
Browser/OS/Node environment
n/a
Source: lit/lit