-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Intl.DateTimeFormat#formatToParts() is not defined in older browsers — please manually polyfill it, example below #158
Comments
I'm given to understand that this is also the case for iOS devices running Safari 12 or earlier. |
Yeah you should be able to find a polyfill for |
This seems to be the most recent DateTimeFormat polyfill: https://formatjs.io/docs/polyfills/intl-datetimeformat/ |
Just in case anyone winds up here looking for a solution to the same problem I had, I created a fork using this polyfill which enables this package to work in older browsers. It can be found hereand installed with: |
@TracerBuilt you shouldn't need to fork the package to use a polyfill. May I ask why you did? In order to keep your installation of use-shopping-cart up-to-date, I would suggest just installing the polyfill and then importing it before using use-shopping-cart. If you only want it to polyfill when necessary, you can use dynamic imports, and once your polyfills are loaded you can then render your application. |
Ah! I'm a bit new to all this and it was the only way I could think of to inject code into a pre-existing project. Do you have any recommendations on where I could read up and learn how to do what you're talking about? |
I'll send you an example of how I've done it in the past in my projects. |
Here is a link to my project that utilizes an optional polyfill loading pattern: The idea is that you can create some asynchronous functions that see if a polyfill is needed for a feature and then will load each polyfill and assign them to their respective names on the Once all of the asynchronous functions have ended, you can then import your async function loadXyz() {
if (!window.xyz) {
window.xyz = (await import('xyz-polyfill')).default
}
}
async function loadAbc() { /* ... */ }
Promise.all([loadXyz(), loadAbc()])
.then(() => import('./App.js'))
.then(({ default: App }) => {
// render
ReactDOM.render(<App />, document.getElementById('root'));
}) |
Thank you so much. This is extremely helpful. |
In older browsers (I've tried IE 9.0, 10, and 11 as well as Firefox 52 and 56), attempting to load the cart produces:
TypeError: a.formatToParts is not a function
Thoughts on a potential polyfill?
The text was updated successfully, but these errors were encountered: