From 204f2dd483394f325a801b72043500fdcd1a8bd9 Mon Sep 17 00:00:00 2001 From: Camille Barneaud <1693643+gadcam@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:25:43 +0200 Subject: [PATCH 1/4] Fix missing `await` of `params` when metadata is used --- .../src/build/webpack/loaders/next-metadata-image-loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts b/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts index 9ea90f598ab10..3845b92cb3086 100644 --- a/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts +++ b/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts @@ -172,7 +172,7 @@ async function nextMetadataImageLoader( const imageData = ${JSON.stringify(imageData)} const imageUrl = fillMetadataSegment(${JSON.stringify( pathnamePrefix - )}, props.params, ${JSON.stringify(pageSegment)}) + )}, await props.params, ${JSON.stringify(pageSegment)}) return [{ ...imageData, From f9535de365937fc744b4a12ec7bfcbab04a50921 Mon Sep 17 00:00:00 2001 From: Camille Barneaud <1693643+gadcam@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:36:18 +0100 Subject: [PATCH 2/4] Annotate generated function as `async` --- .../src/build/webpack/loaders/next-metadata-image-loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts b/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts index 3845b92cb3086..1f12339357d0c 100644 --- a/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts +++ b/packages/next/src/build/webpack/loaders/next-metadata-image-loader.ts @@ -168,7 +168,7 @@ async function nextMetadataImageLoader( return `\ import { fillMetadataSegment } from 'next/dist/lib/metadata/get-metadata-route' - export default (props) => { + export default async (props) => { const imageData = ${JSON.stringify(imageData)} const imageUrl = fillMetadataSegment(${JSON.stringify( pathnamePrefix From bb268be5a141965b7048b7f2dd8a3fcdc3b20530 Mon Sep 17 00:00:00 2001 From: Camille Barneaud <1693643+gadcam@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:48:21 +0100 Subject: [PATCH 3/4] Await callsite of generated metadata module --- packages/next/src/build/webpack/loaders/metadata/discover.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/loaders/metadata/discover.ts b/packages/next/src/build/webpack/loaders/metadata/discover.ts index 74d0403ed6d2d..26653cfea1092 100644 --- a/packages/next/src/build/webpack/loaders/metadata/discover.ts +++ b/packages/next/src/build/webpack/loaders/metadata/discover.ts @@ -114,7 +114,7 @@ export async function createStaticMetadataFromRoute( // WEBPACK_RESOURCE_QUERIES.metadata query here only for filtering out applying to image loader )}!${filepath}?${WEBPACK_RESOURCE_QUERIES.metadata}` - const imageModule = `(async (props) => (await import(/* webpackMode: "eager" */ ${JSON.stringify( + const imageModule = `(async (props) => await (await import(/* webpackMode: "eager" */ ${JSON.stringify( imageModuleImportSource )})).default(props))` hasStaticMetadataFiles = true From 51a2d8e7b2179e1e683d683ce570f7cbd0f3cd96 Mon Sep 17 00:00:00 2001 From: Camille Barneaud <1693643+gadcam@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:23:13 +0100 Subject: [PATCH 4/4] Revert unnecessary `await` --- packages/next/src/build/webpack/loaders/metadata/discover.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/loaders/metadata/discover.ts b/packages/next/src/build/webpack/loaders/metadata/discover.ts index 26653cfea1092..74d0403ed6d2d 100644 --- a/packages/next/src/build/webpack/loaders/metadata/discover.ts +++ b/packages/next/src/build/webpack/loaders/metadata/discover.ts @@ -114,7 +114,7 @@ export async function createStaticMetadataFromRoute( // WEBPACK_RESOURCE_QUERIES.metadata query here only for filtering out applying to image loader )}!${filepath}?${WEBPACK_RESOURCE_QUERIES.metadata}` - const imageModule = `(async (props) => await (await import(/* webpackMode: "eager" */ ${JSON.stringify( + const imageModule = `(async (props) => (await import(/* webpackMode: "eager" */ ${JSON.stringify( imageModuleImportSource )})).default(props))` hasStaticMetadataFiles = true