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

[jsx-runtime] createElement fallback shoud from @jsxImportSource #41146

Closed
morlay opened this issue Oct 17, 2020 · 2 comments · Fixed by #41151
Closed

[jsx-runtime] createElement fallback shoud from @jsxImportSource #41146

morlay opened this issue Oct 17, 2020 · 2 comments · Fixed by #41151

Comments

@morlay
Copy link

morlay commented Oct 17, 2020

if using React.createElement, it is a different results from babel, and will broken react-like lib.

why createElement fallback: facebook/react#20031 (comment)

TypeScript Version: 4.1.0-dev.20201015

Search Terms:

Code

/** @jsxImportSource preact */

const keyBeforeSpread = <span key="a" {...props} />
const keyAfterSpread =<span {...props} key="das" />

Expected behavior:

/** @jsxImportSource preact */
import { jsx } from "preact/jsx-runtime"
import { createElement } from "preact"

const keyBeforeSpread = jsx("span", Object.assign({}, props), "a");
const keyAfterSpread = createElement("span", Object.assign({}, props, { key: "das" }));

Actual behavior:

/** @jsxImportSource preact */
const keyBeforeSpread = _jsx("span", Object.assign({}, props), "a");
const keyAfterSpread = React.createElement("span", Object.assign({}, props, { key: "das" }));

Playground Link:
https://www.typescriptlang.org/play?ts=4.1.0-dev.20201015#code/PQKhAIAECsGcA8CSBbADgewE4BcDK6BXTAYwFNxVNSBDY7cEYAKCePQDtZ6BrUgTwBCpAGZZSuSjQAm4ALzgAPLFTV24Xn1kAialvABvAHTHK6VLAC+4YAD5WHLuv4BBYdlKYJVajNlKVakYmmGaWTppaUtSwerZAA

Related Issues:

@gaearon
Copy link

gaearon commented Oct 17, 2020

Note that even without @jsxImportSource, it's very important that in react-jsx mode, <span {...props} key="foo" /> does auto-import of createElement (from 'react' by default, or from @jsxImportSource if specified — and note no /jsx-runtime in this case).

Otherwise people will have unexpected crashes when you add a spread because React will not exist. (Since they thought they didn't need to import it.)

@gaearon
Copy link

gaearon commented Oct 17, 2020

cc @weswigham it would be nice to avoid releasing without this fix since it's very subtle and hard to catch.

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 a pull request may close this issue.

2 participants