Files
next.js/test/e2e/app-dir/cache-components/cache-components.search.test.ts
Andrew ClarkandGitHub 683a318d79 Omit params to from client segments (#84883)
If a layout or page is marked with "use client", we do not need to pass
any runtime params from the server; the client can parse them from the
URL, or (in the case of a rewrite) from the x-next-rewritten-path and
x-next-rewritten-query headers. This means the client can treat the
segment as fully static, and no dynamic request is necessary upon
navigation.
2025-10-21 03:33:54 -04:00

65 lines
2.5 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('cache-components', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should partially prerender pages that await searchParams in a server component', async () => {
let $ = await next.render$('/search/server/await?sentinel=hello')
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#value').text()).toBe('hello')
expect($('#page').text()).toBe('at runtime')
} else {
expect($('#layout').text()).toBe('at buildtime')
expect($('main').text()).toContain('inner loading...')
expect($('main').text()).not.toContain('outer loading...')
expect($('#value').text()).toBe('hello')
expect($('#page').text()).toBe('at runtime')
}
})
it('should partially prerender pages that `use` searchParams in a server component', async () => {
let $ = await next.render$('/search/server/use?sentinel=hello')
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#value').text()).toBe('hello')
expect($('#page').text()).toBe('at runtime')
} else {
expect($('#layout').text()).toBe('at buildtime')
expect($('main').text()).toContain('inner loading...')
expect($('main').text()).not.toContain('outer loading...')
expect($('#value').text()).toBe('hello')
expect($('#page').text()).toBe('at runtime')
}
})
it('should partially prerender pages that `use` searchParams in a client component', async () => {
let $ = await next.render$('/search/client/use?sentinel=hello')
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#value').text()).toBe('hello')
expect($('#page').text()).toBe('at runtime')
} else {
expect($('#layout').text()).toBe('at buildtime')
expect($('main').text()).toContain('inner loading...')
expect($('main').text()).not.toContain('outer loading...')
// Since #85155, we intentionally omit search params from client segments
// if the page is otherwise static, and resume using a client fetch
// instead. So it's expected that the value is missing pre-hydration.
// There are separate tests that verify that it is eventually hydrated.
// TODO: Rewrite or update this test.
// expect($('#value').text()).toBe('hello')
// expect($('#page').text()).toBe('at runtime')
expect($('#value').text()).toBe('')
expect($('#page').text()).toBe('')
}
})
})