Skip to content

Commit b5159dc

Browse files
committed
Merge remote-tracking branch 'origin/docs/update-react-router-rsc-references' into docs/update-react-router-rsc-references
2 parents b85e7c6 + aefa2db commit b5159dc

File tree

15 files changed

+169
-8
lines changed

15 files changed

+169
-8
lines changed

packages/common/refresh-runtime.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ function isLikelyComponentType(type) {
545545
}
546546
}
547547

548+
function isCompoundComponent(type) {
549+
if (!isPlainObject(type)) return false
550+
for (const key in type) {
551+
if (!isLikelyComponentType(type[key])) return false
552+
}
553+
return true
554+
}
555+
556+
function isPlainObject(obj) {
557+
return (
558+
Object.prototype.toString.call(obj) === '[object Object]' &&
559+
(obj.constructor === Object || obj.constructor === undefined)
560+
)
561+
}
562+
548563
/**
549564
* Plugin utils
550565
*/
@@ -565,6 +580,13 @@ export function registerExportsForReactRefresh(filename, moduleExports) {
565580
// The register function has an identity check to not register twice the same component,
566581
// so this is safe to not used the same key here.
567582
register(exportValue, filename + ' export ' + key)
583+
} else if (isCompoundComponent(exportValue)) {
584+
for (const subKey in exportValue) {
585+
register(
586+
exportValue[subKey],
587+
filename + ' export ' + key + '-' + subKey,
588+
)
589+
}
568590
}
569591
}
570592
}
@@ -618,6 +640,7 @@ export function validateRefreshBoundaryAndEnqueueUpdate(
618640
(key, value) => {
619641
hasExports = true
620642
if (isLikelyComponentType(value)) return true
643+
if (isCompoundComponent(value)) return true
621644
return prevExports[key] === nextExports[key]
622645
},
623646
)

packages/plugin-react-oxc/CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,28 @@
22

33
## Unreleased
44

5-
### Return `Plugin[]` instead of `PluginOption[]`
5+
## 0.3.0 (2025-07-18)
6+
7+
### Add HMR support for compound components ([#518](https://github.com/vitejs/vite-plugin-react/pull/518))
8+
9+
HMR now works for compound components like this:
10+
11+
```tsx
12+
const Root = () => <div>Accordion Root</div>
13+
const Item = () => <div>Accordion Item</div>
14+
15+
export const Accordion = { Root, Item }
16+
```
17+
18+
### Return `Plugin[]` instead of `PluginOption[]` ([#537](https://github.com/vitejs/vite-plugin-react/pull/537))
19+
20+
The return type has changed from `react(): PluginOption[]` to more specialized type `react(): Plugin[]`. This allows for type-safe manipulation of plugins, for example:
21+
22+
```tsx
23+
// previously this causes type errors
24+
react()
25+
.map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
26+
```
627

728
## 0.2.3 (2025-06-16)
829

packages/plugin-react-oxc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react-oxc",
3-
"version": "0.2.3",
3+
"version": "0.3.0",
44
"license": "MIT",
55
"author": "Evan You",
66
"contributors": [

packages/plugin-react-swc/CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,28 @@
22

33
## Unreleased
44

5-
### Return `Plugin[]` instead of `PluginOption[]`
5+
## 3.11.0 (2025-07-18)
6+
7+
### Add HMR support for compound components ([#518](https://github.com/vitejs/vite-plugin-react/pull/518))
8+
9+
HMR now works for compound components like this:
10+
11+
```tsx
12+
const Root = () => <div>Accordion Root</div>
13+
const Item = () => <div>Accordion Item</div>
14+
15+
export const Accordion = { Root, Item }
16+
```
17+
18+
### Return `Plugin[]` instead of `PluginOption[]` ([#537](https://github.com/vitejs/vite-plugin-react/pull/537))
19+
20+
The return type has changed from `react(): PluginOption[]` to more specialized type `react(): Plugin[]`. This allows for type-safe manipulation of plugins, for example:
21+
22+
```tsx
23+
// previously this causes type errors
24+
react()
25+
.map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
26+
```
627

728
## 3.10.2 (2025-06-10)
829

packages/plugin-react-swc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react-swc",
3-
"version": "3.10.2",
3+
"version": "3.11.0",
44
"license": "MIT",
55
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
66
"description": "Speed up your Vite dev server with SWC",

packages/plugin-react/CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
## Unreleased
44

5-
### Return `Plugin[]` instead of `PluginOption[]`
5+
## 4.7.0 (2025-07-18)
6+
7+
### Add HMR support for compound components ([#518](https://github.com/vitejs/vite-plugin-react/pull/518))
8+
9+
HMR now works for compound components like this:
10+
11+
```tsx
12+
const Root = () => <div>Accordion Root</div>
13+
const Item = () => <div>Accordion Item</div>
14+
15+
export const Accordion = { Root, Item }
16+
```
17+
18+
### Return `Plugin[]` instead of `PluginOption[]` ([#537](https://github.com/vitejs/vite-plugin-react/pull/537))
619

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

packages/plugin-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vitejs/plugin-react",
3-
"version": "4.6.0",
3+
"version": "4.7.0",
44
"license": "MIT",
55
"author": "Evan You",
66
"description": "The default Vite plugin for React projects",

packages/plugin-rsc/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ export default defineConfig({
419419
})
420420
```
421421

422-
## Higher level API
422+
## High level API
423+
424+
> [!NOTE]
425+
> High level API is deprecated. Please write on your own `@vitejs/plugin-rsc/{rsc,ssr,browser}` integration.
423426

424427
This is a wrapper of `react-server-dom` API and helper API to setup a minimal RSC app without writing own framework code like [`./examples/starter/src/framework`](./examples/starter/src/framework/). See [`./examples/basic`](./examples/basic/) for how this API is used.
425428

packages/plugin-rsc/src/browser.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function initialize(): void {
1010
load: async (id) => {
1111
if (!import.meta.env.__vite_rsc_build__) {
1212
// @ts-ignore
13-
return __vite_rsc_raw_import__(import.meta.env.BASE_URL + id.slice(1))
13+
return __vite_rsc_raw_import__(
14+
withTrailingSlash(import.meta.env.BASE_URL) + id.slice(1),
15+
)
1416
} else {
1517
const import_ = clientReferences.default[id]
1618
if (!import_) {
@@ -21,3 +23,12 @@ function initialize(): void {
2123
},
2224
})
2325
}
26+
27+
// Vite normalizes `config.base` to have trailing slash, but not for `import.meta.env.BASE_URL`.
28+
// https://github.com/vitejs/vite/blob/27a192fc95036dbdb6e615a4201b858eb64aa075/packages/vite/src/shared/utils.ts#L48-L53
29+
function withTrailingSlash(path: string): string {
30+
if (path[path.length - 1] !== '/') {
31+
return `${path}/`
32+
}
33+
return path
34+
}

packages/plugin-rsc/src/extra/browser.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
} from '../browser'
1212
import type { RscPayload } from './rsc'
1313

14+
/**
15+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
16+
*/
1417
export async function hydrate(): Promise<void> {
1518
const callServer: CallServerCallback = async (id, args) => {
1619
const url = new URL(window.location.href)
@@ -71,6 +74,9 @@ export async function hydrate(): Promise<void> {
7174
}
7275
}
7376

77+
/**
78+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
79+
*/
7480
export async function fetchRSC(
7581
request: string | URL | Request,
7682
): Promise<RscPayload['root']> {

0 commit comments

Comments
 (0)