Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jul 6, 2025

Description

This makes plugin return types to be more specialized so that users can do this without type error:

 react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
   .map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))

@hi-ogawa hi-ogawa marked this pull request as ready for review July 6, 2025 09:20
@hi-ogawa hi-ogawa merged commit 11f56d6 into vitejs:main Jul 7, 2025
15 checks passed
sapphi-red added a commit that referenced this pull request Jul 18, 2025
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 4, 2025
| datasource | package              | from  | to    |
| ---------- | -------------------- | ----- | ----- |
| npm        | @vitejs/plugin-react | 4.6.0 | 4.7.0 |


## [v4.7.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#470-2025-07-18)

##### Add HMR support for compound components ([#518](vitejs/vite-plugin-react#518))

HMR now works for compound components like this:

```tsx
const Root = () => <div>Accordion Root</div>
const Item = () => <div>Accordion Item</div>

export const Accordion = { Root, Item }
```

##### Return `Plugin[]` instead of `PluginOption[]` ([#537](vitejs/vite-plugin-react#537))

The return type has changed from `react(): PluginOption[]` to more specialized type `react(): Plugin[]`. This allows for type-safe manipulation of plugins, for example:

```tsx
// previously this causes type errors
react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
  .map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
```
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 5, 2025
| datasource | package              | from  | to    |
| ---------- | -------------------- | ----- | ----- |
| npm        | @vitejs/plugin-react | 4.6.0 | 4.7.0 |


## [v4.7.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#470-2025-07-18)

##### Add HMR support for compound components ([#518](vitejs/vite-plugin-react#518))

HMR now works for compound components like this:

```tsx
const Root = () => <div>Accordion Root</div>
const Item = () => <div>Accordion Item</div>

export const Accordion = { Root, Item }
```

##### Return `Plugin[]` instead of `PluginOption[]` ([#537](vitejs/vite-plugin-react#537))

The return type has changed from `react(): PluginOption[]` to more specialized type `react(): Plugin[]`. This allows for type-safe manipulation of plugins, for example:

```tsx
// previously this causes type errors
react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
  .map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
```
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.

2 participants