From 5e55c3c340c7f6bb25aebb161e554db3cbfcef90 Mon Sep 17 00:00:00 2001 From: Oleg Zuev Date: Wed, 9 Nov 2022 19:58:25 +0300 Subject: [PATCH] Remove useless async declaration and replace regexp to plain string in AMP postProcessor (#42495) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/next/server/post-process.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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)