Skip to content

Commit 0e7eb5f

Browse files
committed
docs
1 parent c79a8cd commit 0e7eb5f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/plugin-react/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,16 @@ react({ reactRefreshHost: 'http://localhost:3000' })
102102

103103
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
104104

105-
## Middleware mode
105+
## `@vitejs/plugin-react/preamble`
106106

107-
In [middleware mode](https://vite.dev/config/server-options.html#server-middlewaremode), you should make sure your entry `index.html` file is transformed by Vite. Here's an example for an Express server:
107+
For SSR application, which doesn't make use of [`transformIndexHtml` API](https://vite.dev/guide/api-javascript.html#vitedevserver), the package provides `@vitejs/plugin-react/preamble` to intiialize HMR runtime from client entrypoint, for example:
108+
109+
```js
110+
// [entry.client.js]
111+
import '@vitejs/plugin-react/preamble'
112+
```
113+
114+
Alternatively, you can manually call `transformIndexHtml` during SSR, which sets up equivalent intiialization code. Here's an example for an Express server:
108115

109116
```js
110117
app.get('/', async (req, res, next) => {
@@ -121,7 +128,7 @@ app.get('/', async (req, res, next) => {
121128
})
122129
```
123130

124-
Otherwise, you'll probably get this error:
131+
Otherwise, you'll get a following error:
125132

126133
```
127134
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.

0 commit comments

Comments
 (0)