Skip to content

fix(reactivity): ignore helper parameters in staleCapture - #269

Open
anubhavlal07 wants to merge 1 commit into
solidjs:mainfrom
anubhavlal07:fix/stale-capture-helper-param
Open

anubhavlal07 wants to merge 1 commit into
solidjs:mainfrom
anubhavlal07:fix/stale-capture-helper-param

Conversation

@anubhavlal07

Copy link
Copy Markdown
Contributor

solid/reactivity reports staleCapture on a snapshot taken inside an event handler when a helper function declared inside that handler reads it, even though the helper is only called synchronously and never returned.

This is a regression from #260. isDeclaredClosureReturned calls scopeManager.getDeclaredVariables(declaration). For a FunctionDeclaration, that returns the function-name variable plus one variable per parameter, so references to the helper's own parameters were also checked for escaping. In the repro, the id in return snapshot.get(id) ?? id; sits inside look's own return. isReferenceReturned hits that ReturnStatement before it reaches look's function boundary, so the rule concludes that look escapes handleSave.

Fix

isDeclaredClosureReturned now skips variables whose only definition is a Parameter. Only the variable that names the closure is checked. The VariableDeclarator branch already returned only the declared name, so its behavior is unchanged.

Tests

Added three valid cases to test/rules/reactivity.test.ts:

  • the issue's repro, with look("a") called synchronously
  • the ["a"].map(look) variant
  • a helper that reads the snapshot and returns its bare parameter (return id;), which tests the parameter trigger directly

All three fail without the fix, on every parser. The existing #258 invalid cases (return <button onClick={onClick}>, return read) still report. PARSER=all vitest --run passes, and so do pnpm build, pnpm lint and pnpm tsc. docs/reactivity.md was regenerated from the new cases.

Fixes #268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.20.1 (reactivity): staleCapture reports a helper declared inside an event handler

1 participant