[rust-compiler] Preserve ref access location across phi joins (#37524)
Summary
This change preserves the RefValue source location when joining mixed ref types, ensuring that validation errors point to the original ref access rather than an incorrect location. Previously, the rust compiler would display the wrong location when using mixed ref types, causing confusing error messages.
The Problem
Before this change, when using the rust compiler with mixed ref types, validation errors would incorrectly point to the wrong location. For example, consider the following pattern:
const ref = useRef(null);
const x = cond ? ref : ref.current;
return x;
When executed, the compiler would report:
> Cannot access ref value during render
instead of pointing to the actual source of the ref access, making debugging difficult.
Solution
The fix ensures that when phi joins combine mixed ref types, the RefValue's source location is preserved. This way, any subsequent validation errors will correctly reference the original ref access site, improving developer experience and reducing confusion.
Technical Details
Commit: f1f7ed2
Issue: #37524 - Preserve ref access location across phi joins
The commit modifies three files:
- compiler/ - core compiler implementation
- packages/babel-plugin-react-compiler/src/tests/fixtures/compiler - test fixtures
- packages/babel-plugin-react-compiler/src/ - related plugin source
Line changes:
- Total: 41 lines changed (additions & deletions combined)
- Specific file (compiler/): 34 additions, 0 deletions (line 185 modified)
- Overall: 1 addition & 4 deletions across all files
Diff summary:
| Original Line | Diff Line | Change |
|---|---|---|
| 185 | 188 | Added new code block |
The change adds back the correct source location tracking for RefValue objects during phi join operations, resolving the previous misreporting of error locations.
Comments
No comments yet. Start the discussion.