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

feat: try to implement jsxRuntime option #406

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

Conversation

slorber
Copy link

@slorber slorber commented Dec 24, 2024

Description

Attempt to add a new jsxRuntime option, forwarded to Sucrase

This gets rid of a new warning under React 19 in dev mode

Fixes #405

See also https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Unit tests

Checklist: (Feel free to delete this section upon completion)

  • I have included a changeset if this change will require a version change to one of the packages.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have run all builds, tests, and linting and all checks pass
  • I have added tests that prove my fix is effective or that my feature works
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link

changeset-bot bot commented Dec 24, 2024

⚠️ No Changeset found

Latest commit: 35c748b

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

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-live-docs-website ❌ Failed (Inspect) Dec 24, 2024 0:21am

Comment on lines +21 to +31
function createRequire() {
return (val: string) => {
if (val === "react/jsx-runtime") {
return require("react/jsx-runtime");
} else if (val === "react/jsx-dev-runtime") {
return require("react/jsx-dev-runtime");
} else {
return require(val);
}
};
}
Copy link
Author

Choose a reason for hiding this comment

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

I'm not super fan of this part, any idea how to deal with the new require("react/jsx-runtime") that Sucrase adds?

The transformed code looks like this now:

const _jsxFileName = "";
("use strict");
var _jsxdevruntime = require("react/jsx-dev-runtime");
return _jsxdevruntime.jsxDEV.call(
  void 0,
  "div",
  { children: "Hello World!" },
  void 0,
  false,
  { fileName: _jsxFileName, lineNumber: 1 },
  this,
);

Maybe it would be better to use Sucrase to remove the require call directly, and inject a _jsxdevruntime variable in scope directly?

Can injecting a require() function in scope be a problem?

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.

Support for JSX automatic runtime
1 participant