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

Missing polyfills and transforms for older browsers #15756

Closed
kripod opened this issue Jul 31, 2020 · 3 comments · Fixed by #15772
Closed

Missing polyfills and transforms for older browsers #15756

kripod opened this issue Jul 31, 2020 · 3 comments · Fixed by #15772
Labels
good first issue Easy to fix issues, good for newcomers
Milestone

Comments

@kripod
Copy link
Contributor

kripod commented Jul 31, 2020

Bug report

Describe the bug

While browsing the polyfills applied by Next.js 9.5.1, I encountered a lot of features which aren't polyfilled:

ES2015

  • Number.{parseFloat,parseInt}
  • Math.{acosh,asinh,atanh,cbrt,clz32,cosh,expm1,fround,hypot,imul,log10p,log1p,log2,sign,sinh,tanh,trunc}

ES2019

  • Object.fromEntries

ES2020

  • String.prototype.matchAll

ES2021

  • String.prototype.replaceAll
  • Promise.any + AggregateError
  • WeakRef

This may cause unnoticed issues in various browsers.

Missing Babel transforms

Expected behavior

The features above should be supported to avoid browser compatibility issues.

Warnings for non-polyfilled features

There are some features which cannot be polyfilled (or it's hard to do so). For those, an ESLint config or console warnings should be made:

  • Proxy
  • Atomics
  • SharedArrayBuffer
  • RegExp lookbehind assertions: (?<= ) and (?<! )
  • BigInt
@eddyw
Copy link

eddyw commented Aug 1, 2020

I raised a similar issue a while ago #10966

Bottom line is that NextJS ships with just enough polyfills to get it running >=IE11 but you need to add polyfills for other features that you'll use in your app.

@kripod
Copy link
Contributor Author

kripod commented Aug 1, 2020

@eddyw Thanks for the feedback! I've just opened a new PR to fix most of the outlined issues with no significant bundle size changes.

@Timer Timer added good first issue Easy to fix issues, good for newcomers kind: story labels Aug 2, 2020
@kodiakhq kodiakhq bot closed this as completed in #15772 Aug 4, 2020
kodiakhq bot pushed a commit that referenced this issue Aug 4, 2020
…ES2019 for browser compatibility (#15772)

These changes aim to resolve most of the concerns raised in #15756. It adds missing polyfills for legacy browsers up until ES2019:

- Number.{parseFloat,parseInt}
- ~Math.{acosh,asinh,atanh,cbrt,clz32,cosh,expm1,fround,hypot,imul,log10p,log1p,log2,sign,sinh,tanh,trunc}~ _[Removed as these are [not widely used](https://github.com/vercel/next.js/pull/15772#discussion_r463957931)]_
  - While these may seem to weigh a lot, they barely add 1 kB to the resulting bundle:
    <img width="492" alt="gzip: 32 kB vs. 30.9 kB, Brotli: 28.8 kB vs. 27.8 kB" src="https://user-images.githubusercontent.com/14854048/89100961-1376e600-d3fc-11ea-90fd-3e6632b70220.png">
- ~Object.fromEntries~ _[Removed as [it's rarely used in user code](https://github.com/vercel/next.js/pull/15772#discussion_r463984612)]_

Also, the following features are now supported with build-time transforms:

- ~`globalThis` (gets transformed into `window` in browser environments)~ _[Removed as it [could break existing applications](https://github.com/vercel/next.js/pull/15772#discussion_r463956269)]_
- `export * as ns from 'module'`

The suggested TypeScript library version has been set to ES2018, so the features below become unavailable in type-checked files (they're not evenly supported by module-compatible browsers, either):

- Object.fromEntries
- String.prototype.matchAll
- String.prototype.replaceAll
- Promise.any + AggregateError
- WeakRef

As for the `import.meta` support, [webpack v5 seems to fix that](webpack/webpack#11075), so it should eventually become an issue of the past.

---

Fixes #15756
@Timer Timer added this to the iteration 6 milestone Aug 4, 2020
@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 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
4 participants