Repository navigation
reactivity: report stale captures in handlers declared as statements (fixes #258) - #260
Merged
ryansolid merged 1 commit intoNov 17, 2026
Conversation
Declared closures referenced from a returned expression escape again (fixes solidjs#258).
Merged
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.
Fixes #258
Bug
Since 0.19.0,
staleCaptureno longer reports a component handler that is declared as a statement and then passed into the returned JSX:The same happens with
function onClick() { ... }. The inline version,onClick={() => console.log(current)}, is still reported.Root cause
#251 added
child.type !== "BlockStatement"toisCapturedInReturnedFunctionso that a helper declared in a block-bodied memo (const share = ...; return share(2)) is no longer treated as returned (#250). Before that change every closure declared as a statement counted as returned. After it, none do, even when the closure is referenced from the return value.Fix
When the walk from the outermost closure reaches the boundary through its block body, and that closure is a
FunctionDeclarationor theinitof aVariableDeclarator, the rule now looks up its declared variables and checks each non-init reference. A reference escapes if it reaches aReturnStatementbefore it hits aCallExpression/NewExpressionor another function. So:return <button onClick={onClick} />andreturn onClickare reportedreturn share(2)(solid/reactivity false positives: helper closure in a block-bodied memo reported as staleCapture; Array.from map callback not treated as synchronous #250) andreturn items.map(scale)(solid/reactivity false positive (since 0.16.1): capture read inside a synchronous array-method callback in createMemo/createEffect #223) stay valid, because the reference is a callee or a call argumentTests
New invalid cases in
test/rules/reactivity.test.ts: an arrow handler, a function-declaration handler, a handler in a function-declaration component, and a closure returned directly from a block-bodied memo. New valid case:return items.map(scale)in a memo. The existing #250 and #223 cases still pass. The four invalid cases fail without the change.PARSER=all vitest --runpasses for the plugin package (3122 tests), anddocs/reactivity.mdhas been regenerated.