Skip to content

Commit fa5d41b

Browse files
authoredMay 18, 2021
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 #15772 (comment). 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`.
1 parent ac7c8f3 commit fa5d41b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎packages/next/next-server/lib/router/utils/resolve-rewrites.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ export default function resolveRewrites(
4343
headers: {
4444
host: document.location.hostname,
4545
},
46-
cookies: Object.fromEntries(
47-
document.cookie.split('; ').map((item) => {
46+
cookies: document.cookie
47+
.split('; ')
48+
.reduce<Record<string, string>>((acc, item) => {
4849
const [key, ...value] = item.split('=')
49-
return [key, value.join('=')]
50-
})
51-
),
50+
acc[key] = value.join('=')
51+
return acc
52+
}, {}),
5253
} as any,
5354
rewrite.has,
5455
parsedAs.query

0 commit comments

Comments
 (0)
Please sign in to comment.