mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
docs: add note on installing server-only in data security guide (#92445)
## What? Improve alignment between the following documentation sections to ensure clearer and more consistent guidance: - Data Security: https://nextjs.org/docs/app/guides/data-security#preventing-client-side-execution-of-server-only-code - Preventing Environment Poisoning: https://nextjs.org/docs/app/getting-started/server-and-client-components#preventing-environment-poisoning **Related**: https://github.com/vercel/next.js/discussions/91180 ## Why? The current documentation presents overlapping concepts with slight inconsistencies, which can lead to confusion for readers. ## Changes - Align explanations across both sections - Improve overall consistency in guidance Docs only change. @icyJoseph --------- Co-authored-by: Joseph <[email protected]> Co-authored-by: Joseph <[email protected]>
This commit is contained in:
co-authored by
Joseph
Joseph
parent
ed396cadae
commit
1d8e326d1b
@@ -239,6 +239,16 @@ This prevents the tainted objects or values from being passed to the client. How
|
||||
|
||||
To prevent server-only code from being executed on the client, you can mark a module with the [`server-only`](https://www.npmjs.com/package/server-only) package:
|
||||
|
||||
```ts filename="lib/data.ts"
|
||||
import 'server-only'
|
||||
|
||||
//...
|
||||
```
|
||||
|
||||
This ensures that proprietary code or internal business logic stays on the server by causing a build error if the module is imported in the client environment.
|
||||
|
||||
Next.js handles `server-only` imports internally. The contents of these packages from NPM are not used. However, if your linting rules flag extraneous dependencies, you may install them to avoid issues.
|
||||
|
||||
```bash package="npm"
|
||||
npm install server-only
|
||||
```
|
||||
@@ -255,13 +265,7 @@ pnpm add server-only
|
||||
bun add server-only
|
||||
```
|
||||
|
||||
```ts filename="lib/data.ts"
|
||||
import 'server-only'
|
||||
|
||||
//...
|
||||
```
|
||||
|
||||
This ensures that proprietary code or internal business logic stays on the server by causing a build error if the module is imported in the client environment.
|
||||
Read more about `server-only` in the [preventing environment poisoning](/docs/app/getting-started/server-and-client-components#preventing-environment-poisoning) section.
|
||||
|
||||
## Mutating Data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user