vulcan-next icon indicating copy to clipboard operation
vulcan-next copied to clipboard

Detect unimported "React" global

Open eric-burel opened this issue 5 years ago • 3 comments

Next does some magic that makes the iconic import React from "react" optional. But... that barely works with 3rd party tools, that will cringe when they encounter JSX with React not present as a global (it make sense, as built code will massively rely on the React global under the hood).

Repro branch: "bugfix/jest-optional-react-import"

Steps to solve

  • [ ] Decide whether we keep React standard behaviour (import React mandatory in JSX/TSX) or Next standard behaviour (import React optional)
  • [ ] if we prefer Next manage to make this import optional in Jest, Storybook, Cypress
  • [ ] if we prefer React show a warning when React is not imported in Next

eric-burel avatar Jun 05 '20 14:06 eric-burel

https://github.com/vercel/next.js/discussions/13528

eric-burel avatar Jun 05 '20 15:06 eric-burel

It's possible to alter the eslint config using an override:

    {
      "files": [
/* test files for example */      
],
      "rules": { "react/react-in-jsx-scope": "off" }

eric-burel avatar Aug 30 '21 13:08 eric-burel

Nowadays Next.js brings Jest support out of the box, we need to handle that

eric-burel avatar Nov 17 '21 17:11 eric-burel