diff --git a/packages/next/server/post-process.ts b/packages/next/server/post-process.ts index 491c41e2b701acb..c64d406a08c07c5 100644 --- a/packages/next/server/post-process.ts +++ b/packages/next/server/post-process.ts @@ -22,6 +22,10 @@ type middlewareSignature = { condition: ((options: postProcessOptions) => boolean) | null } +type PostProcessorFunction = + | ((html: string) => Promise) + | ((html: string) => string) + const middlewareRegistry: Array = [] function registerPostProcessor( @@ -175,7 +179,7 @@ async function postProcessHTML( renderOpts: RenderOpts, { inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean } ) { - const postProcessors: Array<(html: string) => Promise> = [ + const postProcessors: Array = [ process.env.NEXT_RUNTIME !== 'edge' && inAmpMode ? async (html: string) => { const optimizeAmp = require('./optimize-amp') @@ -226,8 +230,8 @@ async function postProcessHTML( } : null, inAmpMode || hybridAmp - ? async (html: string) => { - return html.replace(/&amp=1/g, '&=1') + ? (html: string) => { + return html.replaceAll('&amp=1', '&=1') } : null, ].filter(nonNullable)