new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Next.js · API reference · all subjects

directives & server functions

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Using cacheLife with use cache directive

To use a custom cache profile, import cacheLife from 'next/cache', then call cacheLife('profileName') inside a function marked with 'use cache'. Example: ```tsx import { cacheLife } from 'next/cache' export async function getCachedData() { 'use cache' cacheLife('blog') const res = await fetch('https://api.example.com/data') const data = await res.json() return data } ```

experimental_taintObjectReference prevents object crossing Server-Client boundary

The `experimental_taintObjectReference` function from React marks an object reference as tainted. It accepts a message string and an object as parameters. When a tainted object is passed across the Server-Client boundary, React throws an error. Individual fields of a tainted object can still be accessed and passed to Client Components.

experimental_taintUniqueValue prevents specific values crossing Server-Client boundary

The `experimental_taintUniqueValue` function from React taints a specific value within an object. It accepts a message string, the parent object, and the specific value to taint as parameters. Other properties of the parent object can still be accessed and passed to Client Components, but the tainted value will throw an error if passed to the client.

Tainting by reference: copying an object creates an untainted version

When an object is copied, the copy becomes an untainted version that loses all tainting guarantees. If sensitive data should remain protected, the copied object must also be tainted explicitly.

Tainted values must be tainted when derived from other tainted values

Data derived from a tainted value is not automatically tainted. If a new value is created from a tainted value (such as string concatenation), that derived value can be passed to the client unless it is also explicitly tainted.

Tainted values remain tainted for the lifetime of their reference

A value stays tainted as long as the lifetime reference is within scope. Once the reference goes out of scope, the tainting no longer applies.

example: taint object reference to prevent entire object passing to client

```ts import { experimental_taintObjectReference } from 'react' async function getUserDetails(id: string): Promise<UserDetails> { const user = await db.queryUserById(id) experimental_taintObjectReference( 'Do not use the entire user info object. Instead, select only the fields you need.', user ) return user } ``` This example shows how to taint an entire user object so it cannot be passed to Client Components, but individual fields can still be extracted and passed safely.

example: taint specific configuration value to prevent key exposure

```ts import { experimental_taintUniqueValue } from 'react' async function getSystemConfig(): Promise<SystemConfig> { const config = await configService.getConfigDetails() experimental_taintUniqueValue( 'Do not pass configuration tokens to the client', config, config.SERVICE_API_KEY ) return config } ``` This example shows how to taint a specific sensitive value (SERVICE_API_KEY) within a configuration object, allowing other properties to be safely passed to Client Components while protecting the key.

Give your agent this brain