Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !10583

feat: allow custom jsxImportSource

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/hermansje/feat/jsxImportSource into main Feb 20, 2021
  • Overview 12
  • Commits 2
  • Pipelines 0
  • Changes 4

Created by: hermansje

PR content

This PR allows configuring a custom value for the importSource option of @babel/preset-react.

TypeScript users can set the corresponding compiler option jsxImportSource in tsconfig.json (introduced in TypeScript 4.1) to configure the JSX import source. The compiler option will be removed if from tsconfig.json if Babel won't use it.

JavaScript users, or TypeScript users that want to override tsconfig.json, can set the environment variable JSX_IMPORT_SOURCE.

Motivation

This PR implements the feature request motivated in https://github.com/facebook/create-react-app/issues/9847 (Emotion without pragma + consistency between tsconfig and Babel) and supersedes the implementations of two existing pull requests https://github.com/facebook/create-react-app/pull/10138 (why-did-you-render, Preact) and https://github.com/facebook/create-react-app/pull/10580.

While this project tries to avoid flags, there are some considerations that might make the case for an exception: the limited logic, the parallel in the implementation with the React runtime heuristic, the integration with tsconfig.json, the assistance to TypeScript users and the benefits of the feature for React users (e.g. ease of use of libraries like Emotion, compatibility with developer tooling like why-did-you-render).

Test plan

I tested with a React + TypeScript + Emotion setup (compilerOptions.jsxImportSource in tsconfig.json set to "@emotion/react").

  • With the published version, the css prop is not transformed to classes.
  • With this branch, the css prop is correctly transformed to classes
  • When called with JSX_IMPORT_SOURCE=react the result is the same again as with the published version (because the environment variable takes precedence)
  • When the requirements for this feature are not met, a message is added to the list of tsconfig changes and jsxImportSource is removed
Screenshot 2021-02-20 at 17 06 55
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/hermansje/feat/jsxImportSource