Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix React.cache() in layout/page file (#43187)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
1 parent
2743413
commit fa5dcbd
Showing
8 changed files
with
201 additions
and
26 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
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/app/app/react-cache/client-component/page.js
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 @@ | ||
'use client' | ||
import { cache } from 'react' | ||
|
||
const getRandomMemoized = cache(() => Math.random()) | ||
|
||
export default function Page() { | ||
const val1 = getRandomMemoized() | ||
const val2 = getRandomMemoized() | ||
return ( | ||
<> | ||
<h1>React Cache Client Component</h1> | ||
<p id="value-1">{val1}</p> | ||
<p id="value-2">{val2}</p> | ||
</> | ||
) | ||
} |
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,17 @@ | ||
import Link from 'next/link' | ||
export default function Page() { | ||
return ( | ||
<> | ||
<p> | ||
<Link id="to-server-component" href="/react-cache/server-component"> | ||
To Server Component | ||
</Link> | ||
</p> | ||
<p> | ||
<Link id="to-client-component" href="/react-cache/client-component"> | ||
To Client Component | ||
</Link> | ||
</p> | ||
</> | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
test/e2e/app-dir/app/app/react-cache/server-component/page.js
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,15 @@ | ||
import { cache } from 'react' | ||
|
||
const getRandomMemoized = cache(() => Math.random()) | ||
|
||
export default function Page() { | ||
const val1 = getRandomMemoized() | ||
const val2 = getRandomMemoized() | ||
return ( | ||
<> | ||
<h1>React Cache Server Component</h1> | ||
<p id="value-1">{val1}</p> | ||
<p id="value-2">{val2}</p> | ||
</> | ||
) | ||
} |
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,17 @@ | ||
import Link from 'next/link' | ||
export default function Page() { | ||
return ( | ||
<> | ||
<p> | ||
<Link id="to-server-component" href="/react-fetch/server-component"> | ||
To Server Component | ||
</Link> | ||
</p> | ||
<p> | ||
<Link id="to-client-component" href="/react-fetch/client-component"> | ||
To Client Component | ||
</Link> | ||
</p> | ||
</> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/app/app/react-fetch/server-component/page.js
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,18 @@ | ||
async function getRandomMemoizedByFetch() { | ||
const res = await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random' | ||
) | ||
return res.text() | ||
} | ||
|
||
export default async function Page() { | ||
const val1 = await getRandomMemoizedByFetch() | ||
const val2 = await getRandomMemoizedByFetch() | ||
return ( | ||
<> | ||
<h1>React Fetch Server Component</h1> | ||
<p id="value-1">{val1}</p> | ||
<p id="value-2">{val2}</p> | ||
</> | ||
) | ||
} |
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