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
ref={…} reading an equation compiles to an untracked memo read in element setup (STRICT_READ_UNTRACKED on Solid's dev build) #79
An element ref={…} whose value comes from an equation compiles to an untracked read of that equation's memo in the element's setup code. Solid's dev build then warns STRICT_READ_UNTRACKED on every mount.
w = createWidget({ key: "k" })
...
<div ref={w.ref} />
This lowers to const v$w = __rt.memo(null, () => ({ ref: r$w["ref"], token: r$w["token"](), reset: r$w["reset"] })) and var _ref$ = v$w()?.ref;, with the same warning. Destructuring instead ({ ref: wref, token } = createWidget(...)) binds v$wref = () => r$w["ref"], which is not a node, and does not warn. ref={peek o.f} also does not warn (__rt.untrack(() => v$o()?.f)).
Expected
No warning for a plain ref={…}. Solid applies a ref once, when the element is created, so the read cannot be tracked whatever it reads. The compiler should lower the ref attribute's expression as a one-time read (__rt.untrack(() => …), what peek emits), or the checker should ask for peek there. As it is, .rx code that looks correct triggers a Solid diagnostic the author can't trace back to their source.
A second, smaller point for the MO-10 case: a projection of a declared object part in an expression (w.ref, w.token in markup) goes through the whole-result memo. That memo rebuilds the object whenever token changes. The declaration-level projection path already reads the part directly (x = w.ref → r$w["ref"]). Doing the same for a projection in an expression (r$w["ref"] for a function part, r$w["token"]() for a ref part) would avoid both the memo read and the object churn.
Cause
compiler/src/emit.rs:1666 (attr) lowers ref like any other attribute, in reactive context. The JSX transform then emits its once-only var _ref$ = <expr> in the element's setup code.
compiler/src/emit.rs:1215-1233 handles Member on an instance with a declared shape only when it is an equation's whole right-hand side. In an expression, compiler/src/emit.rs:1356 lowers it generically to v$w()?.ref.
Activity