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

Intl.DateTimeFormat not polyfilled correctly and always flag crashes Firefox #1012

Closed
nickrttn opened this issue Mar 10, 2021 · 11 comments · Fixed by #1013
Closed

Intl.DateTimeFormat not polyfilled correctly and always flag crashes Firefox #1012

nickrttn opened this issue Mar 10, 2021 · 11 comments · Fixed by #1013
Labels
bug Something isn't working library Relates to an Origami library

Comments

@nickrttn
Copy link

Bug report

The Intl.DateTimeFormat polyfill doesn't correctly detect support for formatRange in Firefox (86). That browser doesn't support formatRange and formatRangeToParts but also doesn't receive the polyfill by default.

If the always flag is passed to force the polyfill Firefox will report an error Uncaught TypeError: Setter must be a function coming from the polyfill script.

Expected behaviour

  • formatRange and formatRangeToParts to be polyfilled when requesting the polyfill for a browser that has parts of Intl.DateTimeFormat.
  • always flag not to cause an error

Steps to reproduce

  • Request the Intl.DateTimeFormat polyfill and the en locale (with/without |always) in Firefox

Environment

  • Firefox 86
  • MBP, macOS Big Sur

Screenshot 2021-03-10 at 11 17 54

@JakeChampion JakeChampion transferred this issue from polyfillpolyfill/polyfill-service Mar 10, 2021
@github-actions github-actions bot added the library Relates to an Origami library label Mar 10, 2021
@JakeChampion
Copy link
Owner

@nickrttn Thank you for the issue, I've transferred it to the polyfill-library repository as that is the place where the polyfills are implemented for polyfill.io

@longlho, have you seen this Intl error for Firefox 86 before?

We currently only target Firefox version below 51: https://github.com/Financial-Times/polyfill-library/blob/493d2d606ef21de644f2b0c62d671d83877175bd/polyfills/Intl/DateTimeFormat/config.toml#L37

I see MDN states some DateTimeFormat features are only available in Firefox 84. MDN hasn't got a version defined for formatRange yet -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#browser_compatibility

Does anyone know which version of Firefox added support for the feature?

@JakeChampion JakeChampion added the bug Something isn't working label Mar 10, 2021
@romainmenke
Copy link
Collaborator

@JakeChampion MDN is correct. Firefox doesn't have support for formatRange

var date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0));
var date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0));

var fmt1 = new Intl.DateTimeFormat("en", {
		year: '2-digit',
		month: 'numeric',
		day: 'numeric',
		hour: 'numeric',
		minute: 'numeric'
});

console.log(!!fmt1.formatRange(date1, date2)) // Uncaught TypeError: fmt1.formatRange is not a function

JakeChampion added a commit that referenced this issue Mar 10, 2021
Firefox does not support `Intl.DateTimeFormat.prototype.formatRange`

Resolves #1012
@JakeChampion
Copy link
Owner

Thank you for confirming @romainmenke 🙌

I've raised a pull-request to serve this polyfill to all Firefox versions -- #1013

@romainmenke
Copy link
Collaborator

I think the same issue also exists for other browsers.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange#browser_compatibility

ran some tests and seeing the same results for Blink,Webkit,Gecko as stated by MDN

@JakeChampion
Copy link
Owner

ran some tests and seeing the same results for Blink,Webkit,Gecko as stated by MDN

MDN lists Blink (Chrome and Edge but not Samsung Browser) as supporting formatRange. Did your tests show Chrome and Edge as not supporting Intl.DateTimeFormat.formatRange?

@romainmenke
Copy link
Collaborator

romainmenke commented Mar 10, 2021

Chrome supports it, but from 76
So this should work : 4ca7ff2#diff-77edc5e4fe23dd90eb39468935b117d0add719ecfc03b83473a1980568198b9eR39

Origami ✨ automation moved this from incoming to complete Mar 10, 2021
JakeChampion added a commit that referenced this issue Mar 10, 2021
Firefox does not support `Intl.DateTimeFormat.prototype.formatRange`

Resolves #1012
@longlho
Copy link
Contributor

longlho commented Mar 10, 2021

@JakeChampion do you still need me to look at anything?

@JakeChampion
Copy link
Owner

@JakeChampion do you still need me to look at anything?

I don't think so, @romainmenke helped solve this 😄

@nickrttn
Copy link
Author

Thanks for the quick action on this issue folks!

The polyfill is now correctly being served. The Intl.DateTimeFormat polyfill does still break with the |always flag. It also happens in Chrome and likely other browsers as well. Should I create a new issue for that?

@JakeChampion
Copy link
Owner

Thanks for the quick action on this issue folks!

The polyfill is now correctly being served. The Intl.DateTimeFormat polyfill does still break with the |always flag. It also happens in Chrome and likely other browsers as well. Should I create a new issue for that?

We haven't released this change onto npm or onto polyfill.io yet

@nickrttn
Copy link
Author

🤦 my bad :) I'll keep an eye on your releases

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2021
@robertboulton robertboulton removed this from Done in Origami ✨ Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working library Relates to an Origami library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants