Skip to content

feat: add filter #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 20, 2025
Merged

feat: add filter #470

merged 6 commits into from
May 20, 2025

Conversation

sapphi-red
Copy link
Member

Description

Adds filter so that it makes these plugin performant when used in rolldown-vite.

@sapphi-red sapphi-red marked this pull request as draft April 28, 2025 08:22
@sapphi-red sapphi-red marked this pull request as ready for review April 28, 2025 09:01
: undefined,
resolveId: {
filter: { id: exactRegex(runtimePublicPath) },
handler: (id) => (id === runtimePublicPath ? id : undefined),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to keep the if statements to keep the compat for Vite older than v6.3.

Comment on lines 200 to 205
id: {
include: ensureArray(include).map(matchWithQuery),
exclude: [
...(exclude ? ensureArray(exclude).map(matchWithQuery) : []),
/\/node_modules\//,
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter conversion and the two utils feels a bit tricky IMO.
Could this be upstream into the Vite createFilter function so that it can be reused by other plugins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add a util function to Vite, we need to bump the required peer dep in this plugin (and the other plugins that wants to use that) which is a breaking change. I think if we do that we probably should add it to a separate package.

I'll consider if we can have @rolldown/pluginutils (since I sent a PR to @rollup/pluginutils that adds some utils functions and it's taking some time to be merged).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be added and then we could do import * as Vite from 'vite' and check for the export name existence so that people using the latest version have the speedup (which is expecting for people running rolldown vite)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code to use @rolldown/pluginutils. ensureArray is still there because we need to combine with /\/node_modules\//, but I think it is now simple enough.

Comment on lines 191 to 192
skipFastRefresh &&
isProduction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isProduction implies skipFastRefresh for now so we can skip the second check but it doesn't hurt so up to you

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this is needed. For example, when config.command === 'build' && !isProduction is true (NODE_ENV=development vite build), this if block should not be executed. Otherwise @babel/plugin-transform-react-jsx-self / @babel/plugin-transform-react-jsx-source won't run.

@sapphi-red
Copy link
Member Author

Just noticed that I forgot to add the changelog. Added 👍

@sapphi-red sapphi-red merged commit 5a94bd7 into main May 20, 2025
11 checks passed
@sapphi-red sapphi-red deleted the feat/add-filter branch May 20, 2025 09:54
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 24, 2025
| datasource | package              | from  | to    |
| ---------- | -------------------- | ----- | ----- |
| npm        | @vitejs/plugin-react | 4.4.1 | 4.5.0 |


## [v4.5.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#450-2025-05-23)

##### Add `filter` for rolldown-vite [#470](vitejs/vite-plugin-react#470)

Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.

##### Skip HMR for JSX files with hooks [#480](vitejs/vite-plugin-react#480)

This removes the HMR warning for hooks with JSX.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 24, 2025
| datasource | package              | from  | to    |
| ---------- | -------------------- | ----- | ----- |
| npm        | @vitejs/plugin-react | 4.4.1 | 4.5.0 |


## [v4.5.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#450-2025-05-23)

##### Add `filter` for rolldown-vite [#470](vitejs/vite-plugin-react#470)

Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.

##### Skip HMR for JSX files with hooks [#480](vitejs/vite-plugin-react#480)

This removes the HMR warning for hooks with JSX.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 25, 2025
| datasource | package              | from  | to    |
| ---------- | -------------------- | ----- | ----- |
| npm        | @vitejs/plugin-react | 4.4.1 | 4.5.0 |


## [v4.5.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#450-2025-05-23)

##### Add `filter` for rolldown-vite [#470](vitejs/vite-plugin-react#470)

Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.

##### Skip HMR for JSX files with hooks [#480](vitejs/vite-plugin-react#480)

This removes the HMR warning for hooks with JSX.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants