From fa5d41b34695b6774d2574b4a451c7ae6a6698b4 Mon Sep 17 00:00:00 2001 From: Jamie <5964236+jamsinclair@users.noreply.github.com> Date: Wed, 19 May 2021 05:18:57 +0900 Subject: [PATCH] fix: replace usage of `fromEntries` in browser bundled `resolve-rewrites.ts` (#25208) ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added Fixes #25207 Currently rewritten routes that use a `has` condition throw an `Object.fromEntries is not a function` error in older browsers. ## Documentation / Examples - [x] Make sure the linting passes ## Solution As mentioned in issue #25207, looks like last year the team decided not to include the `fromEntries` polyfill https://github.com/vercel/next.js/pull/15772#discussion_r463957221. As such, we should avoid using non-polyfilled methods in core next.js code bundled in the browser. This PR's changes should result in the same object being returned, without using `fromEntries`. --- .../next-server/lib/router/utils/resolve-rewrites.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/next/next-server/lib/router/utils/resolve-rewrites.ts b/packages/next/next-server/lib/router/utils/resolve-rewrites.ts index 647055525ad48..c2bef108c98d1 100644 --- a/packages/next/next-server/lib/router/utils/resolve-rewrites.ts +++ b/packages/next/next-server/lib/router/utils/resolve-rewrites.ts @@ -43,12 +43,13 @@ export default function resolveRewrites( headers: { host: document.location.hostname, }, - cookies: Object.fromEntries( - document.cookie.split('; ').map((item) => { + cookies: document.cookie + .split('; ') + .reduce>((acc, item) => { const [key, ...value] = item.split('=') - return [key, value.join('=')] - }) - ), + acc[key] = value.join('=') + return acc + }, {}), } as any, rewrite.has, parsedAs.query