Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl ReactServerComponentValidator {
"revalidateTag",
// "unstable_cache", // useless in client, but doesn't technically error
"cacheLife",
"unstable_cacheTag",
"cacheTag",
// "unstable_noStore" // no-op in client, but allowed for legacy reasons
],
),
Expand Down
12 changes: 6 additions & 6 deletions docs/01-app/03-api-reference/04-functions/cacheTag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default nextConfig
The `cacheTag` function takes one or more string values.

```tsx filename="app/data.ts" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

export async function getData() {
'use cache'
Expand All @@ -54,7 +54,7 @@ export async function getData() {
```

```jsx filename="app/data.js" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

export async function getData() {
'use cache'
Expand Down Expand Up @@ -104,7 +104,7 @@ cacheTag('tag-one', 'tag-two')
Tag your cached data by calling `cacheTag` within a cached function or component:

```tsx filename="app/components/bookings.tsx" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

interface BookingsProps {
type: string
Expand All @@ -124,7 +124,7 @@ export async function Bookings({ type = 'haircut' }: BookingsProps) {
```

```jsx filename="app/components/bookings.js" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

export async function Bookings({ type = 'haircut' }) {
'use cache'
Expand All @@ -144,7 +144,7 @@ export async function Bookings({ type = 'haircut' }) {
You can use the data returned from an async function to tag the cache entry.

```tsx filename="app/components/bookings.tsx" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

interface BookingsProps {
type: string
Expand All @@ -162,7 +162,7 @@ export async function Bookings({ type = 'haircut' }: BookingsProps) {
```

```jsx filename="app/components/bookings.js" switcher
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

export async function Bookings({ type = 'haircut' }) {
async function getBookingsData() {
Expand Down
2 changes: 1 addition & 1 deletion errors/next-prerender-missing-suspense.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function Page() {
After:

```jsx filename="app/page.js"
import { unstable_cacheTag as cacheTag, cacheLife } from 'next/cache'
import { cacheTag, cacheLife } from 'next/cache'

async function getRecentArticles() {
"use cache"
Expand Down
2 changes: 1 addition & 1 deletion packages/next/cache.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export {

export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'

export { cacheTag as unstable_cacheTag } from 'next/dist/server/use-cache/cache-tag'
export { cacheTag } from 'next/dist/server/use-cache/cache-tag'

/**
* Cache this `"use cache"` for a timespan defined by the `"default"` profile.
Expand Down
4 changes: 2 additions & 2 deletions packages/next/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cacheExports = {
require('next/dist/server/web/spec-extension/unstable-no-store')
.unstable_noStore,
cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife,
unstable_cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
}

// https://nodejs.org/api/esm.html#commonjs-namespaces
Expand All @@ -30,5 +30,5 @@ exports.revalidateTag = cacheExports.revalidateTag
exports.updateTag = cacheExports.updateTag
exports.unstable_noStore = cacheExports.unstable_noStore
exports.cacheLife = cacheExports.cacheLife
exports.unstable_cacheTag = cacheExports.unstable_cacheTag
exports.cacheTag = cacheExports.cacheTag
exports.refresh = cacheExports.refresh
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ declare module 'next/cache' {

${overloads}

export { cacheTag as unstable_cacheTag } from 'next/dist/server/use-cache/cache-tag'
export { cacheTag } from 'next/dist/server/use-cache/cache-tag'
}
`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use client'
import { cacheTag } from 'next/cache'

console.log({ cacheTag })

export default function Page() {
return null
}

This file was deleted.

32 changes: 15 additions & 17 deletions test/development/acceptance-app/rsc-build-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,21 @@ describe('Error overlay - RSC build errors', () => {
})

describe("importing 'next/cache' APIs in a client component", () => {
test.each([
'revalidatePath',
'revalidateTag',
'cacheLife',
'unstable_cacheTag',
])('%s is not allowed', async (api) => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
)
const { session } = sandbox
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs "${api}". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.`
)
})
test.each(['revalidatePath', 'revalidateTag', 'cacheLife', 'cacheTag'])(
'%s is not allowed',
async (api) => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
)
const { session } = sandbox
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs "${api}". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.`
)
}
)

test.each([
'unstable_cache', // useless in client, but doesn't technically error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
'revalidatePath',
'revalidateTag',
'cacheLife',
'unstable_cacheTag',
'cacheTag',
'revalidatePath',
'revalidateTag',
])('%s is not allowed', async (api) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { revalidateTag, cacheLife, unstable_cacheTag } from 'next/cache'
import { revalidateTag, cacheLife, cacheTag } from 'next/cache'
import { fetchData } from '../api/data'
// import { Suspense } from 'react'
// import { cookies, headers } from 'next/headers'
Expand All @@ -19,7 +19,7 @@ async function reload() {
async function Component() {
'use cache'
cacheLife({ revalidate: 30 })
unstable_cacheTag('hello')
cacheTag('hello')
return <InnerComponent>{await fetchData()}</InnerComponent>
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use cache'

import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'
import { Suspense } from 'react'

const TEST_DATA_SERVICE_URL = process.env.TEST_DATA_SERVICE_URL
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/app-dir/use-cache-custom-handler/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Suspense } from 'react'
import {
cacheLife,
unstable_cacheTag as cacheTag,
revalidatePath,
updateTag,
} from 'next/cache'
import { cacheLife, cacheTag, revalidatePath, updateTag } from 'next/cache'
import { redirect } from 'next/navigation'
import { connection } from 'next/server'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'
import Link from 'next/link'
import { connection } from 'next/server'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { revalidatePath, unstable_cacheTag, updateTag } from 'next/cache'
import { revalidatePath, cacheTag, updateTag } from 'next/cache'
import { Form } from './form'
import { connection } from 'next/server'

Expand All @@ -10,7 +10,7 @@ async function fetchCachedValue() {

async function getCachedValue() {
'use cache'
unstable_cacheTag('revalidate-and-use')
cacheTag('revalidate-and-use')
return Math.random()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unstable_cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

async function getCachedRandom() {
'use cache'
unstable_cacheTag('api')
cacheTag('api')

return Math.random()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'
import { RevalidateButtons } from './buttons'

async function getCachedWithTag({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { updateTag, unstable_cacheTag as cacheTag } from 'next/cache'
import { updateTag, cacheTag } from 'next/cache'

async function refresh() {
'use server'
Expand Down
4 changes: 2 additions & 2 deletions test/production/app-dir/resume-data-cache/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { Suspense } from 'react'
import { connection } from 'next/server'

import { unstable_cacheTag } from 'next/cache'
import { cacheTag } from 'next/cache'

async function getRandomNumber() {
'use cache'
unstable_cacheTag('test')
cacheTag('test')
return Math.random()
}

Expand Down
4 changes: 2 additions & 2 deletions test/rspack-dev-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component revalidateTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_cache is allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component cacheLife is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_cacheTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component cacheTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_noStore is allowed",
"Error overlay - RSC build errors next/root-params importing 'next/root-params' in a client component",
"Error overlay - RSC build errors next/root-params importing 'next/root-params' in a client component in a way that bypasses import analysis",
Expand Down Expand Up @@ -464,7 +464,7 @@
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages revalidateTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_cache is allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages cacheLife is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_cacheTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages cacheTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_noStore is allowed",
"Error Overlay for server components compiler errors in pages importing 'next/headers' in pages",
"Error Overlay for server components compiler errors in pages importing 'next/root-params' in pages",
Expand Down
4 changes: 2 additions & 2 deletions test/turbopack-dev-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component revalidateTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_cache is allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component cacheLife is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_cacheTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component cacheTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component revalidatePath is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component revalidateTag is not allowed",
"Error overlay - RSC build errors importing 'next/cache' APIs in a client component unstable_noStore is allowed",
Expand Down Expand Up @@ -2274,7 +2274,7 @@
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages revalidateTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_cache is allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages cacheLife is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_cacheTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages cacheTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages revalidatePath is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages revalidateTag is not allowed",
"Error Overlay for server components compiler errors in pages importing 'next/cache' APIs in pages unstable_noStore is allowed",
Expand Down
Loading