Skip to content

fix: handle Symbol values in hook dependency size change warning#35898

Open
emmaeng700 wants to merge 1 commit intofacebook:mainfrom
emmaeng700:fix/symbol-in-hook-deps-error-message
Open

fix: handle Symbol values in hook dependency size change warning#35898
emmaeng700 wants to merge 1 commit intofacebook:mainfrom
emmaeng700:fix/symbol-in-hook-deps-error-message

Conversation

@emmaeng700
Copy link

@emmaeng700 emmaeng700 commented Feb 24, 2026

Summary

Fixes a crash where React's dev-mode warning about hook dependency array size changes would itself throw a TypeError: Cannot convert a Symbol value to a string when any dep was a Symbol.

Root cause: Array.prototype.join() implicitly calls .toString() on each element, which throws for Symbol values. The warning code in areHookInputsEqual used .join() directly:

// Before (crashes with Symbol deps)
`[${prevDeps.join(', ')}]`

Fix: Use String() (which handles Symbols correctly) before joining:

// After (works with any dep type)
`[${prevDeps.map(String).join(', ')}]`

Fixed in both ReactFiberHooks.js (client reconciler) and ReactFizzHooks.js (server/Fizz renderer) since both had the same issue.

Closes #19848

Test plan

  • Added a new test case warns about variable number of dependencies when deps contain Symbols to ReactHooks-test.internal.js that:
    • Uses a Symbol as a dep
    • Changes the dep array size between renders
    • Verifies the warning message renders correctly with Symbol(testSymbol) instead of crashing
  • Existing test warns about variable number of dependencies continues to pass unchanged

@meta-cla meta-cla bot added the CLA Signed label Feb 24, 2026
When a hook's dependency array changes size and contains Symbol values,
the error message generation crashes with "Cannot convert a Symbol value
to a string" because Array.join() implicitly calls toString() on each
element. Use String() explicitly to safely convert any dep value.

Fixes facebook#19848
@emmaeng700 emmaeng700 force-pushed the fix/symbol-in-hook-deps-error-message branch from 9c1c076 to 4435fd1 Compare February 24, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant