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: use jsx classic runtime to avoid issues on react < 18 #115

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

cjbell
Copy link
Contributor

@cjbell cjbell commented Apr 10, 2024

When using React < 18 users will run into this error:

Module not found: Error: Can't resolve 'react/jsx-runtime' in '[FILE]'
Did you mean 'jsx-runtime.js'?
BREAKING CHANGE: The request 'react/jsx-runtime' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

The issue is described in this thread: facebook/react#20235

The fix was implemented in React 18, but the only "fixes" that exist if we're using the JSX runtime are to patch webpack configs, which is not great.

Instead, this PR implements an option to use the "classic" JSX runtime, which is the createElement API as a workaround so that react/jsx-runtime is never referenced. To do so, we also needed to ensure that import React from "react" was at the top of all of our JSX components, which is what the babel-plugin-require-react does.

I tested this locally in our example apps with a build and everything works

Copy link

changeset-bot bot commented Apr 10, 2024

🦋 Changeset detected

Latest commit: 7f21868

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@knocklabs/react-core Patch
@knocklabs/react Patch
@knocklabs/react-native Patch
nextjs-example Patch
@knocklabs/react-native-example Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

vercel bot commented Apr 10, 2024

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

Name Status Preview Comments Updated (UTC)
javascript-slack-connect-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2024 2:48am
javascript-slack-kit-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2024 2:48am

Copy link
Contributor

@connorlindsey connorlindsey left a comment

Choose a reason for hiding this comment

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

Looks good! Will need a changeset as well

packages/react-core/vite.config.ts Show resolved Hide resolved
Copy link
Member

@kylemcd kylemcd left a comment

Choose a reason for hiding this comment

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

Looks good! Might want to check to see if this has any effect on the bundle size before publishing.

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.

None yet

3 participants