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

Polyfill missing std lib fns for module browsers #17083

Merged
merged 6 commits into from
Sep 14, 2020

Conversation

Timer
Copy link
Member

@Timer Timer commented Sep 14, 2020

This pull request creates a new @next/polyfill-module that fills in the missing gaps between various nomodule browsers.

It supports:

  • String#trimStart / String#trimEnd
  • Symbol#description
  • Array#flat / Array#flatMap
  • Promise#finally (previously polyfilled, now relocated)

Fixes #11173

@ijjk

This comment has been minimized.

@Timer Timer marked this pull request as ready for review September 14, 2020 18:23
@Timer Timer merged commit 49a59b1 into vercel:canary Sep 14, 2020
@Timer Timer deleted the hotfix/missing-std-lib branch September 14, 2020 19:25
HitoriSensei pushed a commit to HitoriSensei/next.js that referenced this pull request Sep 26, 2020
Comment on lines +32 to +38
if (!('description' in Symbol.prototype)) {
Object.defineProperty(Symbol.prototype, 'description', {
get: function get() {
return /\((.+)\)/.exec(this)[1]
},
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijjk This polyfill doesn't work properly on Edge 44 (#18213) and Safari 11 (#17825). We can't upgrade to 9.5.4 to fix the security alert and also 10.0 today... Does Next.js need this polyfill internally? If not, could we remove it for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you send a PR to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can open a PR to fix the issue on Edge 44 with a small change

Object.defineProperty(Symbol.prototype, 'description', {
  get: function get() {
    const result = /\((.+)\)/.exec(this)[1];
    return result ? result[1] : undefined;
  },
})

However, this still doesn't handle the other issue with Safari 11 (#17825). Core-js es.symbol.description polyfill seems to be more complete (handling all browser) but I'm not sure if we want to bring all that code into Next.js. I would suggest that we remove this problematic polyfill from Next.js. Whoever needs it can polyfill it manually.

@Timer WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core-js does not polyfill symbol.description, it polyfills Symbols themselves (in their entirety). This works:

if (!('description' in Symbol.prototype)) {
  Object.defineProperty(Symbol.prototype, 'description', {
    get: function get() {
      return /\((.+)\)/.exec(this.toString())[1]
    },
  })
}

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft Edge 16-18 missing "flat" polyfill
4 participants