Skip to content

feat: add support for rolldown-vite #451

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
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/plugin-react-swc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default defineConfig({
})
```

### Make compatible with rolldown-vite

This plugin is now compatible with rolldown-powered version of Vite.

## 3.9.0-beta.2 (2025-04-09)

## 3.9.0-beta.0 (2025-04-09)
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-react-swc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const react = (_options?: Options): PluginOption[] => {
apply: 'serve',
config: () => ({
esbuild: false,
// NOTE: oxc option only exists in rolldown-vite
oxc: false,
optimizeDeps: {
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
esbuildOptions: { jsx: 'automatic' },
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export default defineConfig({
})
```

### Make compatible with rolldown-vite

This plugin is now compatible with rolldown-powered version of Vite.
Note that currently the `__source` property value position might be incorrect. This will be fixed in the near future.

## 4.4.0-beta.1 (2025-04-09)

## 4.4.0-beta.0 (2025-04-09)
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
])
}

if (opts.jsxRuntime === 'classic' && isJSX) {
if (
opts.jsxRuntime === 'classic' &&
isJSX &&
// OXC injects self and source so these plugins are not needed for rolldown-vite
Copy link
Member

Choose a reason for hiding this comment

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

Why is that? Does OXC run before Babel with rolldown-vite?
Technically it works without in default Vite but the source info is off which makes info in React devtools wrong (and breaks https://github.com/ArnaudBarre/vite-plugin-react-click-to-component)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oxc runs after this plugin and injects source and self. Oxc rejects an JSX with self and source with Duplicate __self prop found. error.

Copy link
Member Author

Choose a reason for hiding this comment

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

In babel, the error only happens with automatic runtime. It looks like Oxc should align the behavior to that.
Would it be fine to add this change for now to unblock the error and revert it later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, probably we should set development: false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, it seems it still errors with development: false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Made an issue: oxc-project/oxc#10391

Copy link
Member

Choose a reason for hiding this comment

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

Ok I see. Yeah we can merge this as this is just a small DX issue

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- this.meta.rolldownVersion only exists in rolldown-vite
!this.meta.rolldownVersion
) {
if (!isProduction) {
// These development plugins are only needed for the classic runtime.
plugins.push(
Expand Down
Loading