Skip to content

Commit 0c07cae

Browse files
committed
tweak
1 parent 07a85d9 commit 0c07cae

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

packages/plugin-rsc/README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ See also [Vite documentation](https://vite.dev/guide/api-hmr.html#intellisense-f
506506
507507
You can use `server-only` import to prevent accidentally importing server-only code on client, which can expose sensitive server code to public static assets.
508508
509-
For example, with the following codes:
509+
For example, the plugin will show an error `'server-only' cannot be imported in client build` for the following codes:
510510
511511
- server-utils.js
512512
@@ -527,17 +527,11 @@ export async function getData() {
527527
528528
```tsx
529529
'use client'
530-
import { getData } from './server-utils.js' //This will fail at build time
530+
import { getData } from './server-utils.js' //'server-only' cannot be imported in client build
531531
...
532532
```
533533
534-
the plugin will show an error:
535-
536-
```sh
537-
'server-only' cannot be imported in client build (importer: '/xxx/client.js', ...)
538-
```
539-
540-
Similarly, `client-only` import can ensure browser-specific code isn't accidentally imported in server environment. For example,
534+
Similarly, `client-only` import can ensure browser-specific code isn't accidentally imported in server environment. For example, the plugin will show an error `'client-only' cannot be imported in server build` for the following codes:
541535
542536
- client-utils.js
543537
@@ -553,20 +547,14 @@ export function getStorage(key) {
553547
- server.js
554548
555549
```tsx
556-
import { getStorage } from './client-utils.js' //This will fail at build time
550+
import { getStorage } from './client-utils.js' //'client-only' cannot be imported in server build
557551

558552
export function ServerComponent() {
559553
const data = getStorage("settings")
560554
...
561555
}
562556
```
563557
564-
the plugin will show an error:
565-
566-
```sh
567-
'client-only' cannot be imported in server build (importer: 'xxx/server.js', ...)
568-
```
569-
570558
Note that while there are official npm packages [`server-only`](https://www.npmjs.com/package/server-only) and [`client-only`](https://www.npmjs.com/package/client-only) created by React team, they don't need to be installed. The plugin internally overrides these imports and surfaces their runtime errors as build-time errors.
571559
572560
This build-time validation is enabled by default and can be disabled by setting `validateImports: false` in the plugin options.

0 commit comments

Comments
 (0)