You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rule proposal (Solid 2.0): flag work in ref callbacks that needs an attached element or an owner #243
A ref runs before the element is inserted. At that point el.isConnected is false, and el.ownerDocument is the template's inert document (defaultView is null). Refs also have no owner. So these silently fail inside a ref callback:
<divref={el=>{el.ownerDocument.defaultView.addEventListener("keydown",onKey);// TypeError or no-op: defaultView is nullconst{ width }=el.getBoundingClientRect();// 0: not attached yetonCleanup(()=>…);// never runs: no owner}}/>
Suggested Solution
Inside a function passed to ref (inline or as a referenced function), report:
.ownerDocument.defaultView / .ownerDocument used to reach window or document listeners;
Suggest the global window/document, or moving the work to onSettled in the component.
Possible Alternatives
The runtime warns for onCleanup without an owner (NO_OWNER_CLEANUP). Nothing reports the document and layout cases.
Additional context
Found while helping migrate a large app (OpenClaw) from Lit to Solid 2, mostly with coding agents. Lint is the cheapest place to catch these habits, because agents run it unattended. Docs PR documenting the timing: solidjs/solid#4183.
I would be willing to contribute a PR to implement this feature
Activity