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

fix(next-core): throw on invalid metadata handler #62829

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ async fn dynamic_text_route_source(path: Vc<FileSystemPath>) -> Result<Vc<Box<dy

let content_type = get_content_type(path).await?;

// refer https://github.com/vercel/next.js/blob/7b2b9823432fb1fa28ae0ac3878801d638d93311/packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts#L84
// for the original template.
let code = formatdoc! {
r#"
import {{ NextResponse }} from 'next/server'
Expand All @@ -154,6 +156,10 @@ async fn dynamic_text_route_source(path: Vc<FileSystemPath>) -> Result<Vc<Box<dy
const cacheControl = {cache_control}
const fileType = {file_type}

if (typeof handler !== 'function') {{
throw new Error('Default export is missing in {resource_path}')
}}

export async function GET() {{
const data = await handler()
const content = resolveRouteData(data, fileType)
Expand Down
Loading