-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
NextJS 9.3 polyfills on IE11 break application #10966
Comments
Can you provide a full reproduction? It would help investigate the issue. |
Seems like the script is executed before the polyfills, but that should happen with what you had before too. Btw I accidentally had a look into that script and it seems to be incredible bloated, it ships a full version of React + ReactDOM. You should probably defer loading it to somewhere inside a |
@timneutkens I don't think that's the issue 🙈 import 'core-js/stable' // core-js@3 not @2
// Specialized Packages:
import 'promise-polyfill/src/polyfill'
import 'whatwg-fetch'
import 'url-polyfill'
import assign from 'object-assign'
Object.assign = assign This solved all issues. Including a Honestly, I don't fully understand the purpose of
It'll look for Regardless, would it be possible to have an option to disable default NextJS polyfills to allow the user add their own? A custom const originalEntry = config.entry
config.entry = async () => {
const entries = await originalEntry()
if (entries['static/runtime/polyfills.js']) {
entries['static/runtime/polyfills.js'] = [
require.resolve('core-js/stable'), // <<<<<<<< use stable core-js@3
entries['static/runtime/polyfills.js'], // <<<<<<<< cannot remove because NextJS crashes
]
}
return entries;
} However, this defeats the whole purpose of having |
@timneutkens I took some time to make a repo: https://github.com/eddyw/nextjs-9.3-ie11-bug
See it crash.
Works! |
Looking at what
Babel is only ran over application code, not node_modules, on top of that useBuiltIns causes the polyfills to be imported in the bundles that are sent to modern browsers, which increases bundle size tremendously. Hence why next-polyfill-nomodule only includes the polyfills needed to support IE11 and it only loads those polyfills in browsers that do not support esmodules.
No, it should just work out of the box and the initial issue you created should be fixed. |
@timneutkens alright, off work now. So I found out that this line causes issues: Replaced with: import 'whatwg-fetch/fetch' And fixes one issue. Another issue I found is again with This is the script: eddyw/nextjs-9.3-ie11-bug@788e8b2#diff-8ca0d40421065a36dbd988289e8a40f5 As you can see it's .. bigger than the one NextJS currently uses but includes more polyfills for IE11 that NextJS doesn't include. Generating the polyfills for IE11 (with core-js@3) is just a couple of lines of code (as linked above to my repo): const { targets } = require('core-js-compat')({
targets: 'IE 11',
filter: /^(es|web)\./,
}) My proposal is, could NextJS (optionally) generate polyfills for the specified targets ( NoteThe current code in my repo replaces the NextJS polyfills with the ones automatically generated by entries['static/runtime/polyfills.js'] = [POLYFILL_NOMODULE] And it works. Ref
|
Also updated to the core-js@3 features modules instead of importing the exact modules directly. Fixes vercel#10966
So we traced the failure down to that hubspot script overriding
Good catch on the RegExp one, updated it here: Typed arrays are not polyfilled by default as it seemed unlikely they'd be needed for the majority of applications, if you do need them you can load the polyfill only in the location that uses it. One of the reasons I created a custom list is that core-js-compat results in too many polyfills also, eg it includes these:
Which no one would use today as they're deprecated and discouraged: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/small |
@timneutkens : Is it recommended to remove all babel transpiling and plugins like next-transpile-modules with the new 9.3 version? Don't know if this is the correct place to ask, but we also ran into IE11 problems after upgrading today. Thanks for the enhanced performance! 💯 |
Depends on what you're doing exactly, would be best to post a GitHub Discussion instead. |
@timneutkens if you want to keep it minimal, then I think NextJS should go carefully through all polyfills generated by Here is another broken case that I managed to figure out why my app was breaking (Related to ImmerJS breaking):
import * as React from "react"
const Home = () => {
const [whatIsIt] = React.useState(() => {
try {
return Object.preventExtensions(10)
} catch (e) {
return e.message.toString()
}
})
return (
<div>
<div>It should return number: {whatIsIt}</div>
</div>
)
}
export default Home In Chrome, you'll get:
In IE11, you'll get:
🤷♀ Quote from MDN:
Using the complete set of polyfills for IE11 works. Or add:
To sum up, some IE11 built-ins still need to have polyfills. Same thing for Then, do I need to create a case for So, I'll insist on my proposal 😅 . Could the user specify OPTIONALLY the targets to for |
Note that the main goal of the change was to get rid of transform-runtime, which we did, and we added in a bunch of extra polyfills that were commonly needed. The main goal was not to support the exact es6 environment as in many cases eg the Math ones are never used and you should add the polyfill in the place where it's used to ensure it's only loaded when the code is needed. That is to say, I'm not opposed to adding in more polyfills if there's a real need fo them like the |
@timneutkens alright, I guess that makes sense 😅 I just assumed it meant that it'll provide a compatible environment out-of-the-box for IE11 (does it count Safari? 😅) based on what the blog post about 9.3 mentioned:
Maybe it'll be good to clarify, somewhere, what this actually .. means? 🤔 |
Just adding my 2¢ here: it's always going to be easiest to argue in favor of polyfilling the world. Even if all of core-js were to be included, that wouldn't fix IE11's DOM bugs or any number of other oddities. Essentially, the polyfilling threshold is always going to be arbitrary, and it's best to recognize that and treat it like the tradeoff that it is. Ideally, it would be great to have the baseline One other thing to note here: it may not be sufficient to just add these polyfills into the current polyfills chunk, since the bugs they fix may be present in browsers that support |
* Use core-js promise polyfill for nomodule browsers Also updated to the core-js@3 features modules instead of importing the exact modules directly. Fixes #10966 * Simplify reflect and regexp * Add ie11 test for bad Promise * Add test script for regexp and ie11 Co-authored-by: JJ Kasper <[email protected]> Co-authored-by: Joe Haddad <[email protected]>
@Timer @timneutkens I see PR was merged (and closes this issue). Not to open another thread but test/integration/production/public/regexp-test.js seems to have ... the hubspot script 🤔 . The Hubspot script had only issues with A quickly wrote a case where it failed before PR (I mentioned import * as React from "react";
const str1 = "table football";
const regex1 = new RegExp("foo", "y") // sticky
regex1.lastIndex = 6
const Home = () => {
const isSticky = regex1.sticky // Expected: true
const isMatch1 = regex1.test(str1) // Expected: true
const isMatch2 = regex1.test(str1) // Expected: false
return (
<div>
Works!!!
<div>isSticky: {isSticky.toString()}</div>
<div>isMatch1: {isMatch1.toString()}</div>
<div>isMatch2: {isMatch2.toString()}</div>
</div>
)
}
export default Home In IE11:
It's what I was suggesting. const { targets } = require('core-js-compat')({
targets: 'IE 11', // <<< browser baseline. Browserslist query
filter: /^(es|web)\./, // <<< filter only es and web polyfills
})
Object
.keys(targets)
.filter(moduleName => ...) // exclude deprecated, not needed such as es.string.fontcolor Then you end up with a more or less We want to minimize the number of // next.config.js
module.exports = {
browsers: '> 0.25%, not dead'
} And have |
* Use core-js promise polyfill for nomodule browsers Also updated to the core-js@3 features modules instead of importing the exact modules directly. Fixes vercel#10966 * Simplify reflect and regexp * Add ie11 test for bad Promise * Add test script for regexp and ie11 Co-authored-by: JJ Kasper <[email protected]> Co-authored-by: Joe Haddad <[email protected]>
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. |
Bug report
Describe the bug
On NextJS 9.2 I had setup to use
corejs@3
for Polyfills. Reading that NextJS 9.3 does auto-polyfill for IE11 when needed, I removed the custom babel config and it "works" sometimes.I started to get this error in IE11 in some pages:
To Reproduce
I found out that the global polyfills somehow break some libraries (that maybe come with their own polyfills, I don't know). Also, not sure if NextJS 9.3 uses
corejs@3
.One library that is broken (displays above error in screenshot) in NextJS 9.3 is Hubspot lib. Just add this:
Either in
Head
in_app.tsx
or anywhere else (any page with or without usingnext/head
)Expected behavior
It should use
corejs@3
?It shouldn't break existing libs added through scripts
Additional Information
This babel config worked in NextJS 9.2 without breaking:
System information
Maybe related
The text was updated successfully, but these errors were encountered: