Repository navigation
refactor: remove unnecessary React imports, add jsxImportSource to tsconfigs (AI-assisted) - #12554
Merged
Merged
Conversation
…configs (AI-assisted)
All JSX goes through the automatic runtime (Babel preset and SWC/Rspack
both use runtime: 'automatic'), so `import React` is only needed where
the `React` namespace is actually used.
- Add "jsxImportSource": "react" to tsconfig.base.json and
@docusaurus/tsconfig, so TypeScript resolves JSX types from
react/jsx-runtime instead of the in-scope/UMD `React` global.
- Codemod: drop the default React import from the 269 files under
packages/*/src (233 non-test) that never reference the `React`
identifier (TS AST check, comments ignored). Files using the React
namespace (e.g. React.ReactNode, ReactLiveScope) are unchanged.
- Normalize resulting `import {type X} from 'react'` to
`import type {X} from 'react'`.
- The swizzle wrap generator no longer emits `import React`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With jsxPragma: null, the typescript-eslint scope manager no longer treats JSX as a reference to the in-scope `React` variable, so @typescript-eslint/no-unused-vars reports unused `import React`. Scoped to packages/ for now: the website still has 52 such imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: -216 B (0%) Total Size: 12.4 MB 📦 View Changed
ℹ️ View Unchanged
|
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: -200 B (0%) Total Size: 12.6 MB 📦 View Changed
ℹ️ View Unchanged
|
…-wide (AI-assisted) Run the same codemod on the 52 website files (src, _dogfooding test pages, a blog post component) that import React without using it, and apply the ESLint jsxPragma: null guard to the whole repo instead of only packages/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apply the consistent-type-imports autofix to website files that only
use React in type positions (now detected with jsxPragma: null), and
normalize `import {type X}` to `import type {X}`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
All JSX already goes through the automatic runtime: the Babel preset and the SWC/Rspack config use
runtime: 'automatic', and ESLint already turns offreact/react-in-jsx-scope. Soimport Reactis only needed where theReactnamespace is actually used. (AI-assisted)"jsxImportSource": "react"intsconfig.base.jsonand@docusaurus/tsconfig. TypeScript now resolves JSX types fromreact/jsx-runtimeinstead of the in-scopeReact/ the@types/reactUMD global. This only affects type-checking:jsxstaysreact-native/preserve, so JSX is emitted as before. Without it, TS 6/7 raise TS7026 only when nothing in the program loads@types/react. So this is mostly a robustness fix that stops relying on the UMD global.packages/*/src(233 non-test) that never reference theReactidentifier. The check uses the TS AST, so mentions in comments don't count. Files using the namespace (React.ReactNode,React.memo,ReactLiveScope…) are unchanged. The resultingimport {type X} from 'react'imports were normalized toimport type {X} from 'react'.wrapgenerator no longer emitsimport React. The init templates already had none.src/,_dogfoodingtest pages, a blog post component). No docs code samples are touched.jsxPragma: null, repo-wide. JSX no longer counts as a use of the in-scopeReact, so@typescript-eslint/no-unused-varsreports unused React imports. As a side effect,consistent-type-importsnow catches files that useReactonly in type positions, so 9 of them switch toimport type React from 'react'.Swizzle impact: ejected TS components without
import Reacttypecheck with@docusaurus/tsconfig. Ejected JS components (copied fromlib/theme) now rely on the automatic JSX runtime, which Docusaurus's Babel preset and SWC/Rspack configuration already use. Only a site overriding Babel with the classic runtime would notice.Published
lib/output: compared with a build ofmain, emitted JS differs only by the removedimport Reactlines..d.tsfiles change in an equivalent way (React.JSX.Element→import("react").JSX.Element). In 2 files I added a blank line after the license header, so TS keeps the header when it elides the now type-only first import.Test Plan
pnpm build:packages,pnpm lint:ci,pnpm format:diff,pnpm test(193 files, 3163 tests)tsconfig.skipLibCheck.json), as intests.ymlclassic-typescriptinit template typecheck with TS 7.0.2 and TS 6.0.3pnpm build:website:fasteject/wrap×js/ts(as intests-swizzle.yml), each followed bybuild:website:fastand the website typecheck: all pass. About 200 swizzled JSX files per variant have noimport React.import Reactin.tsxand.jsfiles, and doesn't flag files that useReact. 0 remainingconsistent-type-importswarnings.Test links
No UI change expected. Smoke test:
Deploy preview: https://deploy-preview-12554--docusaurus-2.netlify.app/
Related issues/PRs
🤖 Generated with Claude Code