Skip to content

Fix bug where "import * as React from 'react'" is incompatible with @babel/plugin-transform-runtime #1816

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dddlr
Copy link
Collaborator

@dddlr dddlr commented Mar 13, 2025

What is this change?

@compiled/babel-plugin automatically inserts a React import at the start of the file by default (as long as importReact is not turned off), in the form of import * as React from 'react'. This PR changes this import to import React from 'react'.

Why are we making this change?

Fix bug where "import * as React from 'react'" is incompatible with @babel/plugin-transform-runtime


PR checklist

Don't delete me!

I have...

  • Updated or added applicable tests
  • Updated the documentation in website/
  • Added a changeset (if making any changes that affect Compiled's behaviour)

Copy link

changeset-bot bot commented Mar 13, 2025

⚠️ No Changeset found

Latest commit: c30b206

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

Copy link

netlify bot commented Mar 14, 2025

Deploy Preview for compiled-css-in-js canceled.

Name Link
🔨 Latest commit c30b206
🔍 Latest deploy log https://app.netlify.com/sites/compiled-css-in-js/deploys/67d3716435ca360008ef87a3

1 similar comment
Copy link

netlify bot commented Mar 14, 2025

Deploy Preview for compiled-css-in-js canceled.

Name Link
🔨 Latest commit c30b206
🔍 Latest deploy log https://app.netlify.com/sites/compiled-css-in-js/deploys/67d3716435ca360008ef87a3

@@ -198,7 +198,7 @@ export default declare<State>((api) => {

if (!pragma.jsxImportSource && shouldImportReact && !path.scope.getBinding('React')) {
// React is missing - add it in at the last moment!
path.unshiftContainer('body', template.ast(`import * as React from 'react'`));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just put this behind a configuration, ship it disabled by default, try it internally, and swap the default…?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants