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

Remove useless async declaration and replace regexp to plain string in AMP postProcessor #42495

Merged
merged 6 commits into from Nov 9, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/next/server/post-process.ts
Expand Up @@ -22,6 +22,10 @@ type middlewareSignature = {
condition: ((options: postProcessOptions) => boolean) | null
}

type PostProcessorFunction =
| ((html: string) => Promise<string>)
| ((html: string) => string)

const middlewareRegistry: Array<middlewareSignature> = []

function registerPostProcessor(
Expand Down Expand Up @@ -175,7 +179,7 @@ async function postProcessHTML(
renderOpts: RenderOpts,
{ inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean }
) {
const postProcessors: Array<(html: string) => Promise<string>> = [
const postProcessors: Array<PostProcessorFunction> = [
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode
? async (html: string) => {
const optimizeAmp = require('./optimize-amp')
Expand Down Expand Up @@ -226,8 +230,8 @@ async function postProcessHTML(
}
: null,
inAmpMode || hybridAmp
? async (html: string) => {
return html.replace(/&amp;amp=1/g, '&amp=1')
? (html: string) => {
return html.replaceAll('&amp;amp=1', '&amp=1')
}
: null,
].filter(nonNullable)
Expand Down