-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into styfle/next-1688-mark-onloadingcomplete-as…
…-deprecated
- Loading branch information
Showing
12 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache' | ||
export { revalidatePath } from 'next/dist/server/web/spec-extension/revalidate-path' | ||
export { revalidateTag } from 'next/dist/server/web/spec-extension/revalidate-tag' | ||
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file is for modularized imports for next/server to get fully-treeshaking. | ||
export { unstable_noStore as default } from '../spec-extension/unstable-no-store' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/next/src/server/web/spec-extension/unstable-no-store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { staticGenerationAsyncStorage } from '../../../client/components/static-generation-async-storage.external' | ||
import { staticGenerationBailout } from '../../../client/components/static-generation-bailout' | ||
|
||
export function unstable_noStore() { | ||
const staticGenerationStore = staticGenerationAsyncStorage.getStore() | ||
|
||
if (staticGenerationStore?.isUnstableCacheCallback) { | ||
// if called within a next/cache call, we want to cache the result | ||
// and defer to the next/cache call to handle how to cache the result. | ||
return | ||
} | ||
|
||
staticGenerationBailout('unstable_noStore', { | ||
link: 'https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getUncachedRandomData } from '../no-store-fn' | ||
|
||
export default async function Page() { | ||
const uncachedData = await getUncachedRandomData() | ||
|
||
return ( | ||
<div> | ||
<p>random: {Math.random()}</p> | ||
<p id="uncached-data">uncachedData: {uncachedData.random}</p> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { unstable_noStore } from 'next/cache' | ||
|
||
export function getUncachedRandomData() { | ||
unstable_noStore() | ||
return { | ||
random: Math.random(), | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/app-static/app/no-store/revalidate-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use client' | ||
|
||
export function RevalidateButton({ onClick }) { | ||
return ( | ||
<form action={onClick}> | ||
<button type="submit">revalidate</button> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { revalidateTag, unstable_cache } from 'next/cache' | ||
import { getUncachedRandomData } from '../no-store-fn' | ||
import { RevalidateButton } from '../revalidate-button' | ||
|
||
export default async function Page() { | ||
async function revalidate() { | ||
'use server' | ||
await revalidateTag('no-store-fn') | ||
} | ||
|
||
const cachedData = await unstable_cache( | ||
async () => { | ||
return getUncachedRandomData() | ||
}, | ||
['random'], | ||
{ | ||
tags: ['no-store-fn'], | ||
} | ||
)() | ||
|
||
return ( | ||
<div> | ||
<p>random: {Math.random()}</p> | ||
<p id="data">cachedData: {cachedData.random}</p> | ||
<RevalidateButton onClick={revalidate} /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters