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(plugin-react): wrong substitution causes React is not defined #9386

Merged
merged 4 commits into from Aug 10, 2022

Conversation

Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Jul 27, 2022

Description

fix: #9371

I don't think it's necessary to replace reactAlias.createElement/Fragment with React.createElement/Fragment before transform to jsx, which results in a lot of edge cases.

We can just use reactAlias to determine if we can transform to jsx, which will also become faster!

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

// Assume `Fragment` is equivalent to `React.Fragment` so modules
// that use `import {Fragment} from 'react'` are reverse compiled.
(component === 'Fragment' ? 'React.Fragment' : component)
Copy link
Member

Choose a reason for hiding this comment

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

This PR is missing special handling for import { Fragment } from 'react' usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it was handled 79ff627

@Dunqing
Copy link
Contributor Author

Dunqing commented Aug 3, 2022

This should be R.createElement(Fragment), no?

Yes, updated.

@patak-dev patak-dev merged commit 8a5b575 into vitejs:main Aug 10, 2022
12 checks passed
@patak-dev
Copy link
Member

@aleclarson do you think this should be in a patch or in a minor for plugin-react?

@aleclarson
Copy link
Member

@patak-dev Patch, since this fixes intended behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-has-workaround 🍰 Bug, but has workaround (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plugin-react: React default import in node_modules results to React is not defined
4 participants