Skip to content

Conversation

@lluisemper
Copy link

Allow ref.current === undefined and !ref.current patterns when using
useRef(undefined). Previously, the compiler incorrectly rejected these valid
ref initialization patterns due to missing refId handling in validation logic.

Summary

Fixes: #34278

How did you test this change?

Added test cases:
- ref-undefined-initialization.js - tests ref.current === undefined pattern
- ref-undefined-initialization-negation.js - tests !ref.current pattern
- valid-ref-initialization-unary-not.js - existing test renamed to reflect it now passes

  Allow `ref.current === undefined` and `!ref.current` patterns when using
  useRef(undefined). Previously, the compiler incorrectly rejected these valid
  ref initialization patterns due to missing refId handling in validation logic.
@meta-cla meta-cla bot added the CLA Signed label Sep 17, 2025
@josephsavona
Copy link
Member

josephsavona commented Sep 17, 2025

Thanks for the contribution! Note that I landed support for these patterns already in #34449, we're intentional about disallowing the if (!ref.current) pattern but with a hint about what to do instead.

@lluisemper lluisemper deleted the 34278 branch November 29, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: ref.current === undefined, !ref.current are not allowed

2 participants