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

Rewrites with has condition throws fromEntries error in older browsers #25207

Closed
jamsinclair opened this issue May 18, 2021 · 1 comment · Fixed by #25208
Closed

Rewrites with has condition throws fromEntries error in older browsers #25207

jamsinclair opened this issue May 18, 2021 · 1 comment · Fixed by #25208
Labels
bug Issue was opened via the bug report template.

Comments

@jamsinclair
Copy link
Contributor

What version of Next.js are you using?

10.2.0

What version of Node.js are you using?

14.16.0

What browser are you using?

Safari 11.1.2

What operating system are you using?

iOS

How are you deploying your application?

next start

Describe the Bug

We've recently added some rewrites to our app that use the has rewrite condition.

Since deploying we've seen an uptick in the following errors on users with non-major browsers (e.g. iOS Safari 11.1.2):

Object.fromEntries is not a function. (In 'Object.fromEntries(document.cookie.split("; ").map((function(e){var t=e.split("="),r=n(t);return[r[0],r.slice(1).join("=")]})))', 'Object.fromEntries' is undefined)

This correlates back to

cookies: Object.fromEntries(
document.cookie.split('; ').map((item) => {
const [key, ...value] = item.split('=')
return [key, value.join('=')]

Looks like last year the team decided not to include the fromEntries polyfill #15772 (comment)

Expected Behavior

Next.js browser bundled code does not use newer methods that aren't polyfilled

To Reproduce

Setup your next.config.js with a rewrite that uses the has condition and visit the page with a browser that does not support fromEntries.

module.exports = {
   async rewrites() {
        return [{
             source: '/foo',
             has: {
                type: 'query',
                key: 'test',
             },
             destination: '/bar'
        }]
   }
}

In the above example, you would visit <nextjs host>/foo?test

@jamsinclair jamsinclair added the bug Issue was opened via the bug report template. label May 18, 2021
@kodiakhq kodiakhq bot closed this as completed in #25208 May 18, 2021
kodiakhq bot pushed a commit that referenced this issue May 18, 2021
…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`.
jamsinclair added a commit to jamsinclair/next.js that referenced this issue May 20, 2021
flybayer pushed a commit to blitz-js/next.js that referenced this issue Jun 1, 2021
…tes.ts` (vercel#25208)

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added

Fixes vercel#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 vercel#25207, looks like last year the team decided not to include the `fromEntries` polyfill vercel#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`.
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants