Skip to content

Conversation

@shivas1432
Copy link

Fixes #35171

Hey! This PR fixes a bug where React Compiler was breaking the new JavaScript using syntax.

The Problem:
When you write code like this:
using resource = new Disposable("render");

React Compiler was stripping out the using keyword and turning it into:
new Disposable("render");

This completely breaks the disposal mechanism - Symbol.dispose() never gets called and you get resource leaks.

What I Did:
I added a check in BuildHIR.ts (around line 868) that makes the compiler bail out when it sees using or await using declarations. Now instead of breaking your code, it just skips compiling that component and shows a "not yet supported" message.

Changes:

  • File: compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
  • Added detection for using and await using
  • Compiler now bails out instead of incorrectly transforming

Testing:
I tested this with the example from issue #35171. Now the disposal works correctly and the compiler doesn't mess up the using syntax.

This is a temporary fix - in the future we could fully support using by properly tracking disposal through the compilation pipeline. But for now, this at least prevents the bug.

- Add check to bail out compilation for components with 'using' syntax
- Prevents incorrect transformation that strips disposal semantics
- Fixes facebook#35171
@meta-cla
Copy link

meta-cla bot commented Nov 20, 2025

Hi @shivas1432!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Nov 20, 2025
@meta-cla
Copy link

meta-cla bot commented Nov 20, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the interest in contributing! Requesting changes because we need a test fixture for this, which will likely require some updates to babel in our test infra to enable new syntax (which we don't want to depend on for the actual release version of the compiler). So this is definitely a bit involved.

Also, files have to be formatted

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]: using syntax is not preserved

2 participants