Skip to content
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

Marks app paths in dev as supporting dynamic html #46848

Merged
merged 14 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
opts.isBot = isBotRequest
}

// In development, we always want to generate dynamic HTML.
if (opts.dev && opts.supportsDynamicHTML === false) {
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
opts.supportsDynamicHTML = true
}

const defaultLocale = isSSG
? this.nextConfig.i18n?.defaultLocale
: query.__nextDefaultLocale
Expand Down Expand Up @@ -1441,7 +1446,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
let isRevalidate = false

const doRender: () => Promise<ResponseCacheEntry | null> = async () => {
const supportsDynamicHTML = !(isSSG || hasStaticPaths)
// In development, we always want to generate dynamic HTML.
const supportsDynamicHTML = opts.dev || !(isSSG || hasStaticPaths)

const match =
pathname !== '/_error' && !is404Page && !is500Page
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app/app/dynamic/[category]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { cookies } from 'next/headers'

const Page = async () => {
const result = cookies().get('session')?.value ? 'has cookie' : 'no cookie'
return <div id="cookie-result">{result}</div>
}

export const generateStaticParams = async () => {
return [{ category: 'frameworks' }]
}

export const dynamic = 'force-dynamic'
export const dynamicParams = true
export const revalidate = 60

export default Page
22 changes: 22 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,28 @@ createNextDescribe(
'{"category":"books","id":"hello-world"}'
)
})

it('should allow dynamic routes to access cookies', async () => {
wyattjoh marked this conversation as resolved.
Show resolved Hide resolved
for (const category of ['books', 'frameworks']) {
for (let i = 0; i < 2; i++) {
let $ = await next.render$(
`/dynamic/${category}`,
{},
{
headers: {
cookie: 'session=value',
},
}
)

expect($('#cookie-result').text()).toBe('has cookie')

$ = await next.render$(`/dynamic/${category}`)

expect($('#cookie-result').text()).toBe('no cookie')
}
}
})
})

describe('catch-all routes', () => {
Expand Down