[V4] Bug: fragments with JSX transform
See original GitHub issueReact version: 17.0.1
Steps To Reproduce
yarn create react-app my-app
(make sure react-scripts is 4.0.0 and react and react-dom are 17.0.1)- remove the React import in
src/App.tsx
(everything should still work) - add in a random
<>
(e.g.,src/App.tsx
should look like the following)
import logo from './logo.svg';
import './App.css';
function App() {
return (
<>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
physics test was bad
</>
);
}
export default App;
code example: (see code block above)
The current behavior
with the shorthand syntax, I get this error:
Failed to compile.
/tmp/my-app/src/App.tsx
TypeScript error in /tmp/my-app/src/App.tsx(6,5):
'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. TS2686
4 | function App() {
5 | return (
> 6 | <>
| ^
7 | <div className="App">
8 | <header className="App-header">
9 | <img src={logo} className="App-logo" alt="logo" />
If I change the <>
to React.Fragment
, I get this error:
Failed to compile.
/tmp/my-app/src/App.tsx
Line 13:3: Prefer fragment shorthand over React.Fragment react/jsx-fragments
Search for the keywords to learn more about each error.
If I change the <>
to React.Fragment
and add an eslint disable rule:
Failed to compile.
/tmp/my-app/src/App.tsx
TypeScript error in /tmp/my-app/src/App.tsx(6,5):
'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. TS2686
4 | function App() {
5 | return (
> 6 | <Fragment>
| ^
7 | <div className="App">
8 | <header className="App-header">
9 | <img src={logo} className="App-logo" alt="logo" />
The expected behavior
react should display the spinning logo, and under the “Learn React” header, there should be text. In other words, no errors should occur when upgrading from react 16 to react 17.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Introducing the New JSX Transform – React Blog
Your source code doesn't need to change in any way. We're describing how the JSX transform turns your JSX source code into the...
Read more >[Call for help] Test the React JSX v4 - ReScript Forum
We'd like to share the progress of React JSX v4 and the example project to test. The first version of React JSX v4...
Read more >Custom Render function in JSX - How to handle fragments
I'm trying to use JSX by itself (without React) to render some dynamic content, with a custom createElement function. I'm using webpack with...
Read more >babel/plugin-transform-react-jsx
Fragments are a feature available in React 16.2.0+. React. In const descriptions = items.map(item => ...
Read more >TSConfig Reference - Docs on every TSConfig option
Specify the JSX fragment factory function to use when targeting react JSX emit with jsxFactory compiler option is specified, e.g. Fragment . For...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will try to take a look later and dig into it.
Hmm. I assumed not but I haven’t checked. 😄 Let’s wait to hear from the maintainers.