-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Adding a polyfill for ES6 Array.from() #4014
Comments
This isn't a fix, but for context it looks like you're running into #3780. |
@m-allanson yup, looks like that's the problem. It sounds like ES6 transpilling/minification is being looked at for gatsby 2 but in the meantime is polyfilling still my best bet, and if so where's the best place to do it? |
@lloydh I think just adding Feel free to drop another note here if that doesn't work out. |
Thanks but I get the same result from This is /* globals window */
import { hydrate } from "emotion"
exports.onClientEntry = () => {
if (
typeof window !== `undefined` &&
typeof window.__EMOTION_CRITICAL_CSS_IDS__ !== `undefined`
) {
hydrate(window.__EMOTION_CRITICAL_CSS_IDS__)
}
} Polyfills need to be ahead of this. |
I solved my polyfill problem by creating Adding this as the first plugin in |
Nice @lloydh! Would love to see your plugin added to the list of Community Plugins! |
@fk that was the first place I looked so I'm happy if it can save other users from headaches! Honestly I still don't know if this is the most idiomatic way of polyfilling gatsby but |
I don't recommend bloating your codebase with the entire core-js. If all you need is One way of doing that would be from exports.onClientEntry = () => {
require('core-js/fn/array/from');
}; |
@grgur thanks for the recommendation but using the The problem is that I agree about selectively importing features to polyfill but a better goal is having this all taken care of at build based on the browser targets. |
FWIW, Gatsby v2 will take advantage of Babel 7's new auto-polyfilling which will handle problems like this more elegantly https://github.com/gatsbyjs/gatsby/blob/v2/docs/docs/browser-support.md#polyfills |
@KyleAMathews Somewhat of a hijack of this issue -- I don't want to add a new issue without some new information. Will it be possible to turn off auto-polyfilling for all browser code in 2.x? We use Financial Time's Polyfill.io to only serve polyfills to browsers that need them. It's a good performance strategy for smaller file sizes, less JS processing, and more native code usage. |
@robwierzbowski yeah, we could add that — though the new method might be faster for y'all. Especially if we can get two JS builds working — one targeted at newer browsers and one targeted at older browsers. |
In my experience serving minimal polyfill code per UA string is fastest, especially when serving a wide range of browser capabilities. No code to the browsers that don’t need it. Allowing a user to choose their polyfill strategy (useBuiltIns, runtime, or external) is probably the safest option for wide developer happiness, as each comes with their own considerations for perf, complexity, and stability. It’s my experience these can be real sticking points for a team. |
Thanks for responding so quickly! |
After updating to v2, imported 3rd-party modules i.e., |
@vai0 same issue, I use the |
@Dogtiti I ended up using this: https://www.gatsbyjs.org/packages/gatsby-plugin-polyfill-io/ |
@vai0 ok, thanks I'll try |
I need IE11 compatibility for a website but am getting errors from ES6
Array.from()
used by emotion'screateEmotion
constructor.Given gatsby supports the same browser targets as React I assumed the default config would handle this however I'm now trying to polyfill Array.from() specifically.
Looking for the correct way to polyfill gatsby I found 2177 and 3314 but not a clearly recommended approach.
I've tried importing
core-js
and polyfilling in anonClientEntry
hook within gatsby-browser.js but it seems thatcreateEmotion
might be executing before the polyfill.Help much appreciated.
Environment
Gatsby version: 1.9.192
Node.js version: 9.5.0
Operating System: OS X 10.13.3
The text was updated successfully, but these errors were encountered: