Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for react-compiler-runtime #12735

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Conversation

stipsan
Copy link
Contributor

@stipsan stipsan commented Dec 13, 2024

Changes

Adds support for libraries publishing code pre-compiled with the React Compiler

Testing

Don't know enough about astro internals to add a test 🤷

Docs

Don't think docs need to change, support for react-compiler-runtime is just expected to work, same way the react/jsx-runtime is.

Copy link

changeset-bot bot commented Dec 13, 2024

⚠️ No Changeset found

Latest commit: 0764e5e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) labels Dec 13, 2024
@matthewp
Copy link
Contributor

lgtm, waiting for confirmation from the Sanity team that this fixes the bug they are experiencing.

@matthewp
Copy link
Contributor

They were able to confirm. Thanks again!

@matthewp matthewp merged commit 0ac0f25 into withastro:main Dec 16, 2024
14 checks passed
@matthewp
Copy link
Contributor

I forgot to add a changeset here, so I did so here instead: #12755

@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

Unfortunately this is logging a warning for users who don't have react-compiler-runtime installed (so most people). It would be great if we could conditionally include it or suppress the warnign somehow. #12896

@bluwy
Copy link
Member

bluwy commented Jan 6, 2025

Is there an example library or repro that uses react-compiler-runtime and requires this config? Vite should be able to optimize it beforehand and doesn't need to be manually specified.

@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

There are some Sanity libraries listed here that need it.

@stipsan
Copy link
Contributor Author

stipsan commented Jan 6, 2025

Is there an example library or repro that uses react-compiler-runtime and requires this config? Vite should be able to optimize it beforehand and doesn't need to be manually specified.

That's true in general, but this is a special case similar to react/jsx-runtime, where the imports are added during a compile step, and while the library is ESM, the react published packages are still CJS. If Vite always optimizes these deps correctly, then we wouldn't need to have these in the list either

@bluwy
Copy link
Member

bluwy commented Jan 7, 2025

In your PR description you mentioned "libraries publishing code pre-compiled with the React Compiler", so isn't react-compiler-runtime already visible before compilation by the consumer? Vite should already be handling this correctly by default, even with CJS.

And if any change needs to be made, it should be in @vitejs/plugin-react, which it already has handling for the react compiler: https://github.com/vitejs/vite-plugin-react/blob/ab12dfafbab3260bfd4904d85375ea2c02c36afe/packages/plugin-react/src/index.ts#L282-L296. The optimizeDeps.include list we have is an artifact for when we didn't use @vitejs/plugin-react before. Now we could remove if we want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants