You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/react-server-components.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,9 +235,19 @@ export function ServerComponent() {
235
235
236
236
### `.server`/`.client` Modules
237
237
238
-
To avoid confusion with React's `"use server"` and `"use client"` directives, support for [`.server` modules][server-modules] and [`.client` modules][client-modules] is no longer built-in.
238
+
To avoid confusion with RSC's `"use server"` and `"use client"` directives, support for [`.server` modules][server-modules] and [`.client` modules][client-modules] is no longer built-in when using RSC Framework Mode.
239
239
240
-
If you need either of these features, we recommend using the [`vite-env-only` plugin][vite-env-only] directly. For example, to ensure `.server` modules aren't accidentally included in the client build:
240
+
As an alternative solution that doesn't rely on file naming conventions, we recommend using the ["server-only"][server-only-package] and ["client-only"][client-only-package] packages. These are commonly referred to as "poison pills" because they will break the build if they're included outside of the designated environment.
241
+
242
+
For example, to ensure a module is never accidentally included in the client build, simply import the `server-only` package as a side effect.
243
+
244
+
```ts filename=app/utils/db.ts
245
+
import"server-only";
246
+
247
+
// Rest of the module...
248
+
```
249
+
250
+
If you'd like to quickly migrate existing code that relies on the `.server` and `.client` file naming conventions, we recommend using the [`vite-env-only` plugin][vite-env-only] directly. For example, to ensure `.server` modules aren't accidentally included in the client build:
0 commit comments