Skip to content

[V4] Bug: fragments with JSX transform #9877

Description

@sumanthratna

React version: 17.0.1

Steps To Reproduce

  1. yarn create react-app my-app (make sure react-scripts is 4.0.0 and react and react-dom are 17.0.1)
  2. remove the React import in src/App.tsx (everything should still work)
  3. add in a random <> (e.g., src/App.tsx should look like the following)
importlogofrom'./logo.svg';import'./App.css';functionApp(){return(<><divclassName="App"><headerclassName="App-header"><imgsrc={logo}className="App-logo"alt="logo"/><p>
Edit <code>src/App.tsx</code> and save to reload.
</p><aclassName="App-link"href="https://reactjs.org"target="_blank"rel="noopener noreferrer">
Learn React
</a></header></div>
physics test was bad
</>);}exportdefaultApp;

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions