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 3 commits
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 @@ -1315,6 +1315,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 @@ -1439,7 +1444,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
20 changes: 20 additions & 0 deletions test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,26 @@ createNextDescribe(
}
})

it('should allow dynamic routes to access cookies', async () => {
for (const slug of ['books', 'frameworks']) {
for (let i = 0; i < 2; i++) {
let $ = await next.render$(
`/force-dynamic-prerender/${slug}`,
{},
{ headers: { cookie: 'session=value' } }
)

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

$ = await next.render$(`/force-dynamic-prerender/${slug}`)

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

it('should not error with generateStaticParams and dynamic data', async () => {
const res = await next.fetch('/gen-params-dynamic/one')
const html = await res.text()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { cookies } from 'next/headers'

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

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

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