Skip to content

Commit

Permalink
fix: replace usage of fromEntries in browser bundled `resolve-rewri…
Browse files Browse the repository at this point in the history
…tes.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`.
  • Loading branch information
jamsinclair committed May 18, 2021
1 parent ac7c8f3 commit fa5d41b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/next/next-server/lib/router/utils/resolve-rewrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string>>((acc, item) => {
const [key, ...value] = item.split('=')
return [key, value.join('=')]
})
),
acc[key] = value.join('=')
return acc
}, {}),
} as any,
rewrite.has,
parsedAs.query
Expand Down

0 comments on commit fa5d41b

Please sign in to comment.