Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
❓ is the ref directive supposed to accept an undefined for argument?
Looks like that yes based on the exported types (that are derived from here
However, both the disconnected & reconnected lifecyles are doing unsafe usage of the ref.
I'll be glad to bring a fix upstream for that 🙂
However, I see two possible fixes, and I'd like to see which one we want to go with:
Either we consider the issue to be the looseness of the argument, and restrict it from RefCallback|undefined to RefCallback
Or, we go the opposite way and we ensure the internal _ref property is used safely.****
Reproduction
https://lit.dev/playground/#sample=examples%2Fhello-world&gist=0b002ac6df87f09ff2344481e719cce4
- Open DevTools
- Check the console
- It throw a runtime error
Workaround
Marshall value prior to using the directive, <div ${arg ? ref(arg) : nothing}></div>
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
3.3.1
Browser/OS/Node environment
Browser: Chrome 144.0.7559.97
OS: macOS 26.2 (25C56)
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
❓ is the ref directive supposed to accept an undefined for argument?
Looks like that yes based on the exported types (that are derived from here
However, both the disconnected & reconnected lifecyles are doing unsafe usage of the ref.
I'll be glad to bring a fix upstream for that 🙂
However, I see two possible fixes, and I'd like to see which one we want to go with:
Either we consider the issue to be the looseness of the argument, and restrict it from RefCallback|undefined to RefCallback
Or, we go the opposite way and we ensure the internal _ref property is used safely.****
Reproduction
https://lit.dev/playground/#sample=examples%2Fhello-world&gist=0b002ac6df87f09ff2344481e719cce4
Workaround
Marshall value prior to using the directive,
<div ${arg ? ref(arg) : nothing}></div>Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
3.3.1
Browser/OS/Node environment
Browser: Chrome 144.0.7559.97
OS: macOS 26.2 (25C56)