Skip to content

Fix canSkipBabel not checking babel.overrides#1098

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-canskipbabel-overrides
Open

Fix canSkipBabel not checking babel.overrides#1098
Copilot wants to merge 3 commits intomainfrom
copilot/fix-canskipbabel-overrides

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Fix canSkipBabel to account for babel.overrides

  • Understand the issue: canSkipBabel function doesn't check babelOptions.overrides.length
  • Add babelOptions.overrides.length check to the canSkipBabel function
  • Update CHANGELOG.md with a note about the fix
  • Update CHANGELOG with correct PR number (Fix canSkipBabel not checking babel.overrides #1098)
  • Build and validate the changes
Original prompt

This section details on the original issue you should resolve

<issue_title>canSkipBabel does not account for overrides, causing Babel to be skipped entirely</issue_title>
<issue_description>### Related plugins

Describe the bug

When configuring babel.overrides without any top-level plugins or presets, the canSkipBabel function incorrectly determines that Babel can be skipped. This causes override test functions/patterns to never be evaluated, and override plugins to never run.

The test callback is never invoked. No override plugins are applied.

https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L563-L573

function canSkipBabel(
  plugins: ReactBabelOptions['plugins'],
  babelOptions: ReactBabelOptions,
) {
  return !(
    plugins.length ||
    babelOptions.presets.length ||
    babelOptions.configFile ||
    babelOptions.babelrc
  )
}

It does not check babelOptions.overrides.length. When overrides are the sole source of plugins, this function returns true and Babel is skipped.

This has two effects:

  1. In configResolved (production builds or rolldown-vite), the entire transform handler is deleted via delete viteBabel.transform — Babel never runs.
  2. In the per-file transform path, the early return at if (canSkipBabel(...)) return prevents Babel from processing the file.

Reproduction

https://

Steps to reproduce

react({
  babel: {
    overrides: [
      {
        plugins: ['babel-plugin-react-compiler'],
        test: /\+Page\.tsx?$/,
      },
      {
        plugins: ['babel-plugin-zod-hoist'],
        test: (filename) => {
          console.log('filename>>>', filename); // never fires
          return filename?.endsWith('.tsx') ?? false;
        },
      },
    ],
  },
}),

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

<agent_instructions>Add the overrides.length check
Add a note in the changelog
no need to update tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ArnaudBarre We can probably add `babelOptions.overrides.length` check. Out of curiosity, why do you have overrides without any plugins? (I never used the babel overrides option so I don't know its intent)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ArnaudBarre <14235743+ArnaudBarre@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix canSkipBabel to account for overrides Fix canSkipBabel not checking babel.overrides Feb 6, 2026
Copilot AI requested a review from ArnaudBarre February 6, 2026 15:10
@ArnaudBarre
Copy link
Member

@copilot The PR is 1098, update the changelog

Co-authored-by: ArnaudBarre <14235743+ArnaudBarre@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot The PR is 1098, update the changelog

Updated in a74c426

@ArnaudBarre ArnaudBarre marked this pull request as ready for review February 6, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

canSkipBabel does not account for overrides, causing Babel to be skipped entirely

2 participants