fix(babel-plugin,compiler): assign bare variable refs inside ref arrays (#3285) - #3288
Open
javascript-unsafe wants to merge 1 commit into
Open
fix(babel-plugin,compiler): assign bare variable refs inside ref arrays (#3285)#3288javascript-unsafe wants to merge 1 commit into
javascript-unsafe wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 0479d25 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
) `ref={[el]}` type-checked and compiled but `el` was never assigned. The ref-array branch in both compilers passed the array straight through, and the runtime applyRef only *calls* flattened ref-array entries — a bare variable evaluates to `undefined` at mount, so it was silently skipped. Bare identifiers and non-optional member expressions inside a ref array are now lowered to assignment callbacks that mirror the non-array lval contract: read the target once, call it with the element when it holds a function, otherwise assign the element. Nested arrays are recursed, callback refs and const/module refs pass through untouched, globals (`undefined`) are not treated as assignment targets, and falsy slots keep short-circuiting. - babel-plugin: new transformRefArrayLiteral helper wired into the dom, universal, and component ref branches - compiler (Rust): transform_ref_array_literal in shared/refs, wired into dom_ref_statements, universal_ref_statements, universal_component_ref, and the shared component ref property; BindingTable::is_declared for the globals guard - tests: babel-plugin refArrays fixture (+ oxc fixture reuse), compiler cross-mode parity, packages/web behavioral specs (9 cases) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
javascript-unsafe
force-pushed
the
fix/ref-array-lval-3285
branch
from
September 5, 2026 18:02
498b3e4 to
0479d25
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3285
What was broken
<div ref={[el]} />compiled without errors and passed type-checking, butelwas never assigned the element:while the callback form worked:
Why
ref={el}works: the compiler emits a callback that assigns the element toelwhen it's not callable.ref={[el]}took a different branch — the array was passed through untouched (wrapped as_$ref(() => [el], element)), with nothing done to theelinside.f && f(element)). A bare variable evaluates toundefinedat mount time, so it gets silently skipped and nothing is ever assigned.The runtime only sees the evaluated value (
undefined), not the binding, so this can't be fixed at runtime — the compiler has to turn the bare variable into something callable.The fix
Both compilers (the babel plugin and the native Rust compiler) now transform ref array literals element by element:
letvariableref={[el]}ref={[obj.el]}ref={[[el]]}ref={[...refs]}ref={[fn]},const/module bindings, globals (undefined)undefinedwould throw in strict modenull/falseThis also preserves the existing
let cb = someFn; <div ref={[cb]} />semantics —someFngets called with the element rather thancbbeing overwritten.Tests
packages/web/test/ref-array.spec.tsx(the issue's case plus multiple variables, callbacks, mixed arrays, member expressions, nested arrays, falsy slots, mutable/constfunction bindings) — green with both the native compiler andJSX_COMPILER=babelrefArraysbabel-plugin fixture, reused as an oxc fixture — zero parity diff between the two compilers' outputclippy -D warningscleanChangeset
Patch bumps for
@solidjs/babel-pluginand@solidjs/compiler.