Skip to content

Commit e90c5b5

Browse files
committed
Merge branch 'main' into fix-inline-async
2 parents b002c6d + 88585db commit e90c5b5

File tree

23 files changed

+434
-143
lines changed

23 files changed

+434
-143
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Preview Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, labeled]
9+
10+
permissions: {}
11+
12+
jobs:
13+
preview:
14+
if: >
15+
github.repository == 'vitejs/vite-plugin-react' &&
16+
(github.event_name == 'push' ||
17+
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview')))
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
25+
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: lts/*
29+
cache: pnpm
30+
31+
- name: Install dependencies
32+
run: pnpm install
33+
34+
- name: Build
35+
run: pnpm build
36+
37+
- name: Publish
38+
run: pnpm dlx [email protected] publish --pnpm --compact './packages/*' './packages/plugin-react-swc/dist'

packages/common/refresh-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export const runtimePublicPath = '/@react-refresh'
22

33
const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/
4-
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/
4+
const refreshContentRE = /\$RefreshReg\$\(/
55

66
// NOTE: this is exposed publicly via plugin-react
77
export const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(
88
1,
9-
)}"
9+
)}";
1010
injectIntoGlobalHook(window);
1111
window.$RefreshReg$ = () => {};
1212
window.$RefreshSig$ = () => (type) => type;`

packages/plugin-react-oxc/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
## Unreleased
44

5+
### Add explicit semicolon in preambleCode [#485](https://github.com/vitejs/vite-plugin-react/pull/485)
6+
7+
This fixes an edge case when using HTML minifiers that strips line breaks aggressively.
8+
9+
## 0.2.0 (2025-05-23)
10+
11+
### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470)
12+
13+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
14+
15+
### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480)
16+
17+
This removes the HMR warning for hooks with JSX.
18+
519
## 0.1.1 (2025-04-10)
620

721
## 0.1.0 (2025-04-09)

packages/plugin-react-oxc/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react-oxc",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"license": "MIT",
55
"author": "Evan You",
66
"contributors": [
@@ -46,5 +46,8 @@
4646
"@vitejs/react-common": "workspace:*",
4747
"unbuild": "^3.5.0",
4848
"vite": "catalog:rolldown-vite"
49+
},
50+
"dependencies": {
51+
"@rolldown/pluginutils": "1.0.0-beta.9"
4952
}
5053
}

packages/plugin-react-oxc/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
runtimePublicPath,
1010
silenceUseClientWarning,
1111
} from '@vitejs/react-common'
12+
import { exactRegex } from '@rolldown/pluginutils'
1213

1314
const _dirname = dirname(fileURLToPath(import.meta.url))
1415

@@ -149,12 +150,3 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
149150

150151
return [viteConfig, viteRefreshRuntime, viteRefreshWrapper]
151152
}
152-
153-
function exactRegex(input: string): RegExp {
154-
return new RegExp(`^${escapeRegex(input)}$`)
155-
}
156-
157-
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
158-
function escapeRegex(str: string): string {
159-
return str.replace(escapeRegexRE, '\\$&')
160-
}

packages/plugin-react-swc/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Unreleased
44

5+
### Add explicit semicolon in preambleCode [#485](https://github.com/vitejs/vite-plugin-react/pull/485)
6+
7+
This fixes an edge case when using HTML minifiers that strips line breaks aggressively.
8+
9+
## 3.10.0 (2025-05-23)
10+
11+
### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470)
12+
13+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
14+
15+
### Skip HMR preamble in Vitest browser mode [#478](https://github.com/vitejs/vite-plugin-react/pull/478)
16+
17+
This was causing annoying `Sourcemap for "/@react-refresh" points to missing source files` and is unnecessary in test mode.
18+
19+
### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480)
20+
21+
This removes the HMR warning for hooks with JSX.
22+
523
## 3.9.0 (2025-04-15)
624

725
### Make compatible with rolldown-vite

packages/plugin-react-swc/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react-swc",
3-
"version": "3.9.0",
3+
"version": "3.10.0",
44
"license": "MIT",
55
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
66
"description": "Speed up your Vite dev server with SWC",
@@ -29,6 +29,7 @@
2929
},
3030
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc#readme",
3131
"dependencies": {
32+
"@rolldown/pluginutils": "1.0.0-beta.9",
3233
"@swc/core": "^1.11.22"
3334
},
3435
"peerDependencies": {

packages/plugin-react-swc/src/index.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
runtimePublicPath,
1919
silenceUseClientWarning,
2020
} from '@vitejs/react-common'
21+
import { exactRegex } from '@rolldown/pluginutils'
2122

2223
/* eslint-disable no-restricted-globals */
2324
const _dirname =
@@ -96,14 +97,23 @@ const react = (_options?: Options): PluginOption[] => {
9697
name: 'vite:react-swc:resolve-runtime',
9798
apply: 'serve',
9899
enforce: 'pre', // Run before Vite default resolve to avoid syscalls
99-
resolveId: (id) => (id === runtimePublicPath ? id : undefined),
100-
load: (id) =>
101-
id === runtimePublicPath
102-
? readFileSync(join(_dirname, 'refresh-runtime.js'), 'utf-8').replace(
103-
/__README_URL__/g,
104-
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc',
105-
)
106-
: undefined,
100+
resolveId: {
101+
filter: { id: exactRegex(runtimePublicPath) },
102+
handler: (id) => (id === runtimePublicPath ? id : undefined),
103+
},
104+
load: {
105+
filter: { id: exactRegex(runtimePublicPath) },
106+
handler: (id) =>
107+
id === runtimePublicPath
108+
? readFileSync(
109+
join(_dirname, 'refresh-runtime.js'),
110+
'utf-8',
111+
).replace(
112+
/__README_URL__/g,
113+
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc',
114+
)
115+
: undefined,
116+
},
107117
},
108118
{
109119
name: 'vite:react-swc',
@@ -132,13 +142,17 @@ const react = (_options?: Options): PluginOption[] => {
132142
)
133143
}
134144
},
135-
transformIndexHtml: (_, config) => [
136-
{
137-
tag: 'script',
138-
attrs: { type: 'module', async: 'true' },
139-
children: getPreambleCode(config.server!.config.base),
140-
},
141-
],
145+
transformIndexHtml: (_, config) => {
146+
if (!hmrDisabled) {
147+
return [
148+
{
149+
tag: 'script',
150+
attrs: { type: 'module', async: 'true' },
151+
children: getPreambleCode(config.server!.config.base),
152+
},
153+
]
154+
}
155+
},
142156
async transform(code, _id, transformOptions) {
143157
const id = _id.split('?')[0]
144158
const refresh = !transformOptions?.ssr && !hmrDisabled

packages/plugin-react/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
## Unreleased
44

5+
### Add explicit semicolon in preambleCode [#485](https://github.com/vitejs/vite-plugin-react/pull/485)
6+
7+
This fixes an edge case when using HTML minifiers that strips line breaks aggressively.
8+
9+
## 4.5.0 (2025-05-23)
10+
11+
### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470)
12+
13+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
14+
15+
### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480)
16+
17+
This removes the HMR warning for hooks with JSX.
18+
519
## 4.4.1 (2025-04-19)
620

721
Fix type issue when using `moduleResolution: "node"` in tsconfig [#462](https://github.com/vitejs/vite-plugin-react/pull/462)

packages/plugin-react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react",
3-
"version": "4.4.1",
3+
"version": "4.5.0",
44
"license": "MIT",
55
"author": "Evan You",
66
"description": "The default Vite plugin for React projects",
@@ -51,6 +51,7 @@
5151
"@babel/core": "^7.26.10",
5252
"@babel/plugin-transform-react-jsx-self": "^7.25.9",
5353
"@babel/plugin-transform-react-jsx-source": "^7.25.9",
54+
"@rolldown/pluginutils": "1.0.0-beta.9",
5455
"@types/babel__core": "^7.20.5",
5556
"react-refresh": "^0.17.0"
5657
},

0 commit comments

Comments
 (0)