From d5e8bc935b8f3ed4a5de749fa1a8a28f14571800 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Thu, 29 Apr 2021 02:38:29 +0800 Subject: [PATCH] use exec instead of matchAll --- packages/next/client/image.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/next/client/image.tsx b/packages/next/client/image.tsx index 8f8957740e655..4028e8787f6b2 100644 --- a/packages/next/client/image.tsx +++ b/packages/next/client/image.tsx @@ -94,9 +94,11 @@ function getWidths( ): { widths: number[]; kind: 'w' | 'x' } { if (sizes && (layout === 'fill' || layout === 'responsive')) { // Find all the "vw" percent sizes used in the sizes prop - const percentSizes = [...sizes.matchAll(/(^|\s)(1?\d?\d)vw/g)].map((m) => - parseInt(m[2]) - ) + const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g + const percentSizes = [] + for (let match; (match = viewportWidthRe.exec(sizes)); match) { + percentSizes.push(parseInt(match[2])) + } if (percentSizes.length) { const smallestRatio = Math.min(...percentSizes) * 0.01 return {