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(theme-ui): export jsx as createElement #1604

Merged
merged 1 commit into from
Mar 29, 2021

Conversation

ethanwu10
Copy link
Contributor

@ethanwu10 ethanwu10 commented Mar 28, 2021

Fix for #1603
The new JSX runtime transformation will sometimes use the createElement named export from the jsxImportSource, however theme-ui does not export its pragma under this name, causing crashes. This PR reexports the jsx pragma under the name createElement to fix this. For reference, @emotion/react currently does the same thing

A minimal reproduction case is rendering any JSX element with both spread props and a key prop:

<div {...{}} key='1' />

(codesandbox)

As far as I can tell, the tests use the classic runtime, so there is no way to write a test for this other than explicitly doing import { createElement } from 'theme-ui' and creating a node that way; is such a test worth having, since the use of createElement is essentially an implementation detail of the JSX transform?

📦 Published PR as canary version: 0.6.1-canary.1604.15f511c.0

✨ Test out this PR locally via:

npm install @theme-ui/color-modes@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/color@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/components@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/core@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/css@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/custom-properties@0.6.1-canary.1604.15f511c.0
npm install docs@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/editor@0.6.1-canary.1604.15f511c.0
npm install gatsby-plugin-theme-ui@0.6.1-canary.1604.15f511c.0
npm install gatsby-theme-code-recipes@0.6.1-canary.1604.15f511c.0
npm install gatsby-theme-style-guide@0.6.1-canary.1604.15f511c.0
npm install gatsby-theme-ui-layout@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/match-media@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/mdx@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/parse-props@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-base@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-bootstrap@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-bulma@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-dark@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-deep@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-funk@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-future@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-polaris@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-roboto@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-sketchy@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-swiss@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-system@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-tailwind@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/preset-tosh@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/presets@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/prism@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/sidenav@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/style-guide@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/tachyons@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/tailwind@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/test-utils@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/theme-provider@0.6.1-canary.1604.15f511c.0
npm install theme-ui@0.6.1-canary.1604.15f511c.0
npm install @theme-ui/typography@0.6.1-canary.1604.15f511c.0
# or 
yarn add @theme-ui/color-modes@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/color@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/components@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/core@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/css@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/custom-properties@0.6.1-canary.1604.15f511c.0
yarn add docs@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/editor@0.6.1-canary.1604.15f511c.0
yarn add gatsby-plugin-theme-ui@0.6.1-canary.1604.15f511c.0
yarn add gatsby-theme-code-recipes@0.6.1-canary.1604.15f511c.0
yarn add gatsby-theme-style-guide@0.6.1-canary.1604.15f511c.0
yarn add gatsby-theme-ui-layout@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/match-media@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/mdx@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/parse-props@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-base@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-bootstrap@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-bulma@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-dark@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-deep@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-funk@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-future@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-polaris@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-roboto@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-sketchy@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-swiss@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-system@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-tailwind@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/preset-tosh@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/presets@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/prism@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/sidenav@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/style-guide@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/tachyons@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/tailwind@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/test-utils@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/theme-provider@0.6.1-canary.1604.15f511c.0
yarn add theme-ui@0.6.1-canary.1604.15f511c.0
yarn add @theme-ui/typography@0.6.1-canary.1604.15f511c.0

When using the new JSX runtime, Babel will fall back to calling
`createElement` (name not configurable) from the configured
`jsxImportSource` when there is both an explicit `key` prop and
object spread props. This causes a crash when using theme-ui since the
custom JSX pragma is only exported as `jsx`. Reexport the `jsx` pragma
under the name `createElement` to fix this.
@vercel
Copy link

vercel bot commented Mar 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/systemui/theme-ui/9fXgWjUmTojAoPYStt57JcZ94La2
✅ Preview: https://theme-ui-git-fork-ethanwu10-jsx-runtime-createelement-systemui.vercel.app

@lachlanjc
Copy link
Member

Thanks for your PR! Going to leave this to @hasparus since I don't know much about this area.

@hasparus
Copy link
Member

Thanks for the PR @ethanwu10! Good catch!

@hasparus
Copy link
Member

hasparus commented Mar 29, 2021

@ethanwu10 This PR was released with 0.6.1-canary.1604.15f511c.0.

I'll merge it to stable and release 0.6.1 in few several hours :)

Here's your CodeSandbox with updated Theme UI — https://codesandbox.io/s/staging-surf-psxdy?file=/src/index.js.

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