-
Notifications
You must be signed in to change notification settings - Fork 29.1k
allow root params access in private caches #82125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
...app-dir/app-root-params-getters/fixtures/use-cache-private/app/[lang]/[locale]/layout.tsx
This file contains hidden or 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 { ReactNode } from 'react' | ||
|
||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} | ||
|
||
export function generateStaticParams() { | ||
// the param values are not accessed in tests, | ||
// we just need a value here to avoid errors in PPR/cacheComponents | ||
// where we need to provide at least one set of values for root params | ||
return [{ lang: 'foo', locale: 'bar' }] | ||
} |
34 changes: 34 additions & 0 deletions
34
...-params-getters/fixtures/use-cache-private/app/[lang]/[locale]/use-cache-private/page.tsx
This file contains hidden or 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,34 @@ | ||
import { lang, locale } from 'next/root-params' | ||
import { connection } from 'next/server' | ||
import { Suspense } from 'react' | ||
|
||
export default async function Page() { | ||
return ( | ||
<Suspense fallback="Loading..."> | ||
<Runtime /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
async function Runtime() { | ||
await connection() | ||
|
||
const rootParams = await getCachedParams() | ||
const data = await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random' | ||
).then((res) => res.text()) | ||
|
||
return ( | ||
<p> | ||
<span id="param"> | ||
{rootParams.lang} {rootParams.locale} | ||
</span>{' '} | ||
<span id="random">{data}</span> | ||
</p> | ||
) | ||
} | ||
|
||
async function getCachedParams() { | ||
'use cache: private' | ||
return { lang: await lang(), locale: await locale() } | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/app-root-params-getters/fixtures/use-cache-private/next.config.ts
This file contains hidden or 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,10 @@ | ||
import type { NextConfig } from 'next' | ||
|
||
const nextConfig: NextConfig = { | ||
experimental: { | ||
useCache: true, | ||
rootParams: true, | ||
}, | ||
} | ||
|
||
export default nextConfig |
This file contains hidden or 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 |
---|---|---|
|
@@ -5,7 +5,6 @@ import { createSandbox } from 'development-sandbox' | |
describe('app-root-param-getters - cache - at runtime', () => { | ||
const { next, isNextDev, skipped } = nextTestSetup({ | ||
files: join(__dirname, 'fixtures', 'use-cache-runtime'), | ||
skipStart: true, | ||
// this test asserts on build failure logs, which aren't currently observable in `next.cliOutput`. | ||
skipDeployment: true, | ||
}) | ||
|
@@ -39,19 +38,6 @@ describe('app-root-param-getters - cache - at runtime', () => { | |
) | ||
}) | ||
} else { | ||
beforeAll(async () => { | ||
try { | ||
await next.start() | ||
} catch (err) { | ||
// if (isPPREnabled) { | ||
// throw err | ||
// } else { | ||
// // in PPR/cacheComponents, we expect the build to fail, | ||
// // so we swallow the error and let the tests assert on the logs | ||
// } | ||
} | ||
}) | ||
|
||
Comment on lines
-42
to
-54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accidental leftover, this wasn't failing the build anymore |
||
it('should error when using root params within a "use cache" - start', async () => { | ||
await next.render$('/en/us/use-cache') | ||
expect(next.cliOutput).toInclude( | ||
|
@@ -68,6 +54,30 @@ describe('app-root-param-getters - cache - at runtime', () => { | |
} | ||
}) | ||
|
||
describe('app-root-param-getters - private cache', () => { | ||
const { next, isNextDev } = nextTestSetup({ | ||
files: join(__dirname, 'fixtures', 'use-cache-private'), | ||
}) | ||
|
||
if (isNextDev) { | ||
it('should allow using root params within a "use cache: private" - dev', async () => { | ||
await using sandbox = await createSandbox( | ||
next, | ||
undefined, | ||
'/en/us/use-cache-private' | ||
) | ||
const { session, browser } = sandbox | ||
await session.assertNoRedbox() | ||
expect(await browser.elementById('param').text()).toBe('en us') | ||
}) | ||
} else { | ||
it('should allow using root params within a "use cache: private" - start', async () => { | ||
const browser = await next.browser('/en/us/use-cache-private') | ||
expect(await browser.elementById('param').text()).toBe('en us') | ||
}) | ||
} | ||
}) | ||
|
||
describe('app-root-param-getters - cache - at build', () => { | ||
const { next, isNextDev } = nextTestSetup({ | ||
files: join(__dirname, 'fixtures', 'use-cache-build'), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the important line, the others are just drive-by cleanup (
outerWorkUnitStore
is always defined here)