-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ed0004
Polyfill missing std lib fns for module browsers
Timer 6d082fb
Merge remote-tracking branch 'upstream/canary' into hotfix/missing-st…
Timer 19d1396
Sync package version
Timer 58fc1df
Update sizes
Timer 90ff848
Merge remote-tracking branch 'upstream/canary' into hotfix/missing-st…
Timer e5c0457
update version
Timer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@next/polyfill-module", | ||
"version": "9.5.4-canary.16", | ||
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", | ||
"main": "dist/polyfill-module.js", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "vercel/next.js", | ||
"directory": "packages/next-polyfill-module" | ||
}, | ||
"scripts": { | ||
"prepublish": "microbundle src/index.js -f iife --no-sourcemap --external none", | ||
"build": "microbundle watch src/index.js -f iife --no-sourcemap --external none" | ||
}, | ||
"devDependencies": { | ||
"microbundle": "0.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* eslint-disable no-extend-native */ | ||
|
||
// Contains polyfills for methods missing after browser version(s): | ||
// Edge 16, Firefox 60, Chrome 61, Safari 10.1 | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 61 | ||
* Chrome: 66 | ||
* Safari: 12 | ||
* | ||
* https://caniuse.com/mdn-javascript_builtins_string_trimstart | ||
* https://caniuse.com/mdn-javascript_builtins_string_trimend | ||
*/ | ||
if (!('trimStart' in String.prototype)) { | ||
String.prototype.trimStart = String.prototype.trimLeft | ||
} | ||
if (!('trimEnd' in String.prototype)) { | ||
String.prototype.trimEnd = String.prototype.trimRight | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 63 | ||
* Chrome: 70 | ||
* Safari: 12.1 | ||
* | ||
* https://caniuse.com/mdn-javascript_builtins_symbol_description | ||
*/ | ||
if (!('description' in Symbol.prototype)) { | ||
Object.defineProperty(Symbol.prototype, 'description', { | ||
get: function get() { | ||
return /\((.+)\)/.exec(this)[1] | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 62 | ||
* Chrome: 69 | ||
* Safari: 12 | ||
* | ||
* https://caniuse.com/array-flat | ||
*/ | ||
// Copied from https://gist.github.com/developit/50364079cf0390a73e745e513fa912d9 | ||
// Licensed Apache-2.0 | ||
if (!Array.prototype.flat) { | ||
Array.prototype.flat = function flat(d, c) { | ||
return ( | ||
(c = this.concat.apply([], this)), | ||
d > 1 && c.some(Array.isArray) ? c.flat(d - 1) : c | ||
) | ||
} | ||
Array.prototype.flatMap = function (c, a) { | ||
return this.map(c, a).flat() | ||
} | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: 18 | ||
* Firefox: 58 | ||
* Chrome: 63 | ||
* Safari: 11.1 | ||
* | ||
* https://caniuse.com/promise-finally | ||
*/ | ||
// Modified from https://gist.github.com/developit/e96097d9b657f2a2f3e588ffde433437 | ||
// Licensed Apache-2.0 | ||
if (!Promise.prototype.finally) { | ||
Promise.prototype.finally = function (callback) { | ||
if (typeof callback !== 'function') { | ||
return this.then(callback, callback) | ||
} | ||
|
||
var P = this.constructor || Promise | ||
return this.then( | ||
function (value) { | ||
return P.resolve(callback()).then(function () { | ||
return value | ||
}) | ||
}, | ||
function (err) { | ||
return P.resolve(callback()).then(function () { | ||
throw err | ||
}) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7545,11 +7545,6 @@ finalhandler@~1.1.2: | |
statuses "~1.5.0" | ||
unpipe "~1.0.0" | ||
|
||
[email protected]: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.1.0.tgz#2a17b16581d9477db16a703c7b79a898ac0b7d50" | ||
integrity sha512-J1LEcZ5VXe1l3sEO+S//WqL5wcJ/ep7QeKJA6HhNZrcEEFj0eyC8IW3DEZhxySI2bx3r85dwAXz+vYPGuHx5UA== | ||
|
||
[email protected], find-cache-dir@^3.0.0, find-cache-dir@^3.3.1: | ||
version "3.3.1" | ||
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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?
There was a problem hiding this comment.
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: