Skip to content

Conversation

@zekariasasaminew
Copy link
Contributor

@zekariasasaminew zekariasasaminew commented Sep 15, 2025

Summary

The React Compiler rejected a default parameter that contains a TSInstantiationExpression with the todo message that the expression cannot be safely reordered. This change teaches the reorder check in BuildHIR.ts to treat TSInstantiationExpression as reorderable. This is safe because TypeScript instantiation only affects types and is erased at runtime, so it has no side effects and does not change semantics.

How did you test this change?

Set-Content testfilter.txt 'ts-instantiation-default-param'

yarn test --filter --update

yarn test --filter
I added a fixture:

compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/ts-instantiation-default-param.js

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 contribution! See comments before we can land

@zekariasasaminew zekariasasaminew marked this pull request as draft September 15, 2025 20:32
Updated the fixture to be a component and implemented id as a real function. Regenerated the snapshot. Eval output now renders <div>hi</div>.
@zekariasasaminew zekariasasaminew marked this pull request as ready for review September 15, 2025 21:24
@zekariasasaminew
Copy link
Contributor Author

@josephsavona Made the requested changes. PR is ready for another review

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.

awesome thanks!

@zekariasasaminew
Copy link
Contributor Author

@josephsavona I updated the branch to satisfy the up to date requirement. CI is green. Could you please re approve when you have a moment 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.

See comments, sorry i missed that this needs to check the inner expression

…tantiationExpression-as-reorderable-in-BuildHIR
…in-BuildHIR' of https://github.com/zekariasasaminew/react into compiler-mark-TSInstantiationExpression-as-reorderable-in-BuildHIR
use id<string> as default value and call inside the body
@zekariasasaminew
Copy link
Contributor Author

@josephsavona Thanks for the guidance. I updated isReorderableExpression to recurse for TSInstantiationExpression and switched the fixture to default to id as a value with the call inside the body. Snapshot regenerated and the filtered test passes locally. Ready for another look.

@zekariasasaminew zekariasasaminew force-pushed the compiler-mark-TSInstantiationExpression-as-reorderable-in-BuildHIR branch from d095ca7 to 1db579e Compare September 16, 2025 21:23
@zekariasasaminew
Copy link
Contributor Author

zekariasasaminew commented Sep 17, 2025

This should be ready @josephsavona

@josephsavona
Copy link
Member

Please stop pushing, every time you do it forces me to re-approve the workflow to make sure CI is green.

@josephsavona josephsavona merged commit 5813211 into facebook:main Sep 18, 2025
21 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 18, 2025
…le in build hir (#34488)

<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
--> The React Compiler rejected a default parameter that contains a
TSInstantiationExpression with the todo message that the expression
cannot be safely reordered. This change teaches the reorder check in
BuildHIR.ts to treat TSInstantiationExpression as reorderable. This is
safe because TypeScript instantiation only affects types and is erased
at runtime, so it has no side effects and does not change semantics.

## How did you test this change?

```
Set-Content testfilter.txt 'ts-instantiation-default-param'

yarn test --filter --update

yarn test --filter
```

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
--> I added a fixture:
>
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ts-instantiation-default-param.js

DiffTrain build for [5813211](5813211)
github-actions bot pushed a commit that referenced this pull request Sep 18, 2025
…le in build hir (#34488)

<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
--> The React Compiler rejected a default parameter that contains a
TSInstantiationExpression with the todo message that the expression
cannot be safely reordered. This change teaches the reorder check in
BuildHIR.ts to treat TSInstantiationExpression as reorderable. This is
safe because TypeScript instantiation only affects types and is erased
at runtime, so it has no side effects and does not change semantics.

## How did you test this change?

```
Set-Content testfilter.txt 'ts-instantiation-default-param'

yarn test --filter --update

yarn test --filter
```

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
--> I added a fixture:
>
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ts-instantiation-default-param.js

DiffTrain build for [5813211](5813211)
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.

2 participants