Skip to content

Commit 2de42ee

Browse files
committed
[Cache Components] Remove unstable prefix from unstable_cacheTag
`cacheLife` is now stable and does not require an unstable prefix
1 parent a5064d7 commit 2de42ee

File tree

21 files changed

+58
-65
lines changed

21 files changed

+58
-65
lines changed

crates/next-custom-transforms/src/transforms/react_server_components.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ use regex::Regex;
1111
use rustc_hash::FxHashMap;
1212
use serde::Deserialize;
1313
use swc_core::{
14-
atoms::{atom, Atom},
14+
atoms::{Atom, atom},
1515
common::{
16+
DUMMY_SP, FileName, Span, Spanned,
1617
comments::{Comment, CommentKind, Comments},
1718
errors::HANDLER,
1819
util::take::Take,
19-
FileName, Span, Spanned, DUMMY_SP,
2020
},
2121
ecma::{
2222
ast::*,
23-
utils::{prepend_stmts, quote_ident, quote_str, ExprFactory},
23+
utils::{ExprFactory, prepend_stmts, quote_ident, quote_str},
2424
visit::{
25-
noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith,
26-
VisitWith,
25+
Visit, VisitMut, VisitMutWith, VisitWith, noop_visit_mut_type, noop_visit_type,
26+
visit_mut_pass,
2727
},
2828
},
2929
};
@@ -653,7 +653,7 @@ impl ReactServerComponentValidator {
653653
"revalidateTag",
654654
// "unstable_cache", // useless in client, but doesn't technically error
655655
"cacheLife",
656-
"unstable_cacheTag",
656+
"cacheTag",
657657
// "unstable_noStore" // no-op in client, but allowed for legacy reasons
658658
],
659659
),

docs/01-app/03-api-reference/04-functions/cacheTag.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default nextConfig
4343
The `cacheTag` function takes one or more string values.
4444

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

4848
export async function getData() {
4949
'use cache'
@@ -54,7 +54,7 @@ export async function getData() {
5454
```
5555

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

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

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

109109
interface BookingsProps {
110110
type: string
@@ -124,7 +124,7 @@ export async function Bookings({ type = 'haircut' }: BookingsProps) {
124124
```
125125

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

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

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

149149
interface BookingsProps {
150150
type: string
@@ -162,7 +162,7 @@ export async function Bookings({ type = 'haircut' }: BookingsProps) {
162162
```
163163

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

167167
export async function Bookings({ type = 'haircut' }) {
168168
async function getBookingsData() {

errors/next-prerender-missing-suspense.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default async function Page() {
3434
After:
3535

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

3939
async function getRecentArticles() {
4040
"use cache"

packages/next/cache.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export {
99

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

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

1414
/**
1515
* Cache this `"use cache"` for a timespan defined by the `"default"` profile.

packages/next/cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const cacheExports = {
1616
require('next/dist/server/web/spec-extension/unstable-no-store')
1717
.unstable_noStore,
1818
cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife,
19-
unstable_cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
19+
cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
2020
}
2121

2222
// https://nodejs.org/api/esm.html#commonjs-namespaces
@@ -30,5 +30,5 @@ exports.revalidateTag = cacheExports.revalidateTag
3030
exports.updateTag = cacheExports.updateTag
3131
exports.unstable_noStore = cacheExports.unstable_noStore
3232
exports.cacheLife = cacheExports.cacheLife
33-
exports.unstable_cacheTag = cacheExports.unstable_cacheTag
33+
exports.cacheTag = cacheExports.cacheTag
3434
exports.refresh = cacheExports.refresh

packages/next/src/build/webpack/plugins/next-types-plugin/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ declare module 'next/cache' {
538538
539539
${overloads}
540540
541-
export { cacheTag as unstable_cacheTag } from 'next/dist/server/use-cache/cache-tag'
541+
export { cacheTag } from 'next/dist/server/use-cache/cache-tag'
542542
}
543543
`
544544
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client'
2+
import { cacheTag } from 'next/cache'
3+
4+
console.log({ cacheTag })
5+
6+
export default function Page() {
7+
return null
8+
}

test/development/acceptance-app/fixtures/rsc-build-errors/app/server-with-errors/next-cache-in-client/unstable_cachetag/page.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/development/acceptance-app/rsc-build-errors.test.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,21 @@ describe('Error overlay - RSC build errors', () => {
279279
})
280280

281281
describe("importing 'next/cache' APIs in a client component", () => {
282-
test.each([
283-
'revalidatePath',
284-
'revalidateTag',
285-
'cacheLife',
286-
'unstable_cacheTag',
287-
])('%s is not allowed', async (api) => {
288-
await using sandbox = await createSandbox(
289-
next,
290-
undefined,
291-
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
292-
)
293-
const { session } = sandbox
294-
await session.assertHasRedbox()
295-
expect(await session.getRedboxSource()).toInclude(
296-
`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.`
297-
)
298-
})
282+
test.each(['revalidatePath', 'revalidateTag', 'cacheLife', 'cacheTag'])(
283+
'%s is not allowed',
284+
async (api) => {
285+
await using sandbox = await createSandbox(
286+
next,
287+
undefined,
288+
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
289+
)
290+
const { session } = sandbox
291+
await session.assertHasRedbox()
292+
expect(await session.getRedboxSource()).toInclude(
293+
`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.`
294+
)
295+
}
296+
)
299297

300298
test.each([
301299
'unstable_cache', // useless in client, but doesn't technically error

test/development/acceptance/server-component-compiler-errors-in-pages.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
385385
'revalidatePath',
386386
'revalidateTag',
387387
'cacheLife',
388-
'unstable_cacheTag',
388+
'cacheTag',
389389
'revalidatePath',
390390
'revalidateTag',
391391
])('%s is not allowed', async (api) => {

0 commit comments

Comments
 (0)