Unverified Commit 5f65a8eb authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[webpack] Ensure `dynamicParams` is respected in `opengraph-image.ts` (#99478)

https://github.com/vercel/next-js-mirror/pull/182Co-authored-by: 's avatarDavid Ilie <david@davidilie.com>
parent 86861b2d
......@@ -26,10 +26,7 @@ async function createReExportsCode(
)
// Re-export configs but avoid conflicted exports
const reExportNames = exportNames.filter(
(name) =>
name !== 'default' &&
name !== 'generateSitemaps' &&
name !== 'dynamicParams'
(name) => name !== 'default' && name !== 'generateSitemaps'
)
return reExportNames.length > 0
......
......@@ -224,6 +224,7 @@
"test/e2e/app-dir/not-found/css-precedence/index.test.ts",
"test/e2e/app-dir/not-found/group-route-root-not-found/index.test.ts",
"test/e2e/app-dir/not-found/group-route/index.test.ts",
"test/e2e/app-dir/nsec-105-opengraph-image-dynamicparams/index.test.ts",
"test/e2e/app-dir/parallel-route-not-found-params/parallel-route-not-found-params.test.ts",
"test/e2e/app-dir/parallel-routes-and-interception-from-root/parallel-routes-and-interception-from-root.test.ts",
"test/e2e/app-dir/parallel-routes-and-interception-nested-dynamic-routes/parallel-routes-and-interception-nested-dynamic-routes.test.ts",
......
import { getPost, publicPostParams } from '../../../posts'
export const dynamicParams = false
export function generateStaticParams() {
return publicPostParams()
}
export async function GET(_request, { params }) {
const { slug } = await params
const post = getPost(slug)
return new Response(`route:${post.status}:${post.title}`, {
headers: { 'content-type': 'text/plain' },
})
}
import { getPost, publicPostParams } from '../../posts'
export const dynamicParams = false
export function generateStaticParams() {
return publicPostParams()
}
export default async function OpengraphImage({ params }) {
const { slug } = await params
const post = getPost(slug)
return new Response(
`og:${post.status}:${post.title}:${post.internalSummary}`,
{
headers: { 'content-type': 'text/plain' },
}
)
}
import { notFound } from 'next/navigation'
import { getPost, publicPostParams } from '../../posts'
export function generateStaticParams() {
return publicPostParams()
}
export default async function PostPage({ params }) {
const { slug } = await params
const post = getPost(slug)
if (!post || post.status !== 'public') {
notFound()
}
return (
<main>
<p>{`page:${post.status}:${post.title}`}</p>
</main>
)
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('nsec-105-opengraph-image-dynamicparams', () => {
if (
process.env.__NEXT_CACHE_COMPONENTS === 'true' ||
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' ||
process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
) {
// The dynamicParams segment config is rejected at build time when cache
// components is enabled, and legacy PPR serves unlisted params with a
// 200 shell instead of a 404 for the page, so this scenario only exists
// in plain non-PPR production mode.
test.skip('only applicable without cache components / legacy PPR', () => {})
return
}
const { next } = nextTestSetup({
files: __dirname,
})
it('serves the listed slug on the page, route handler, and opengraph-image', async () => {
const pageRes = await next.fetch('/public-post')
expect(pageRes.status).toBe(200)
const dataRes = await next.fetch('/public-post/data')
expect(dataRes.status).toBe(200)
expect(await dataRes.text()).toBe('route:public:Public quarterly update')
const ogRes = await next.fetch('/public-post/opengraph-image')
expect(ogRes.status).toBe(200)
expect(await ogRes.text()).toBe(
'og:public:Public quarterly update:Public summary only'
)
})
it('returns 404 for an unlisted slug on the page and route handler', async () => {
const pageRes = await next.fetch('/acquisition-draft')
expect(pageRes.status).toBe(404)
const dataRes = await next.fetch('/acquisition-draft/data')
expect(dataRes.status).toBe(404)
})
it('returns 404 for an unlisted slug on opengraph-image when dynamicParams is false', async () => {
const ogRes = await next.fetch('/acquisition-draft/opengraph-image')
expect(ogRes.status).toBe(404)
})
})
const posts = {
'public-post': {
status: 'public',
title: 'Public quarterly update',
internalSummary: 'Public summary only',
},
'acquisition-draft': {
status: 'draft',
title: 'Draft acquisition plan',
internalSummary: 'Target: private roadmap and valuation notes',
},
}
export function getPost(slug) {
return posts[slug]
}
export function publicPostParams() {
return [{ slug: 'public-post' }]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment