question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't load Intl polyfill in route hook

See original GitHub issue

Our Ember apps support iOS 9 webviews and Mobile Safari, which require the Intl API to be polyfilled. We don’t want to burden other users with the API and locale data polyfill, so we need to load it conditionally based on feature detection.

We’d like to load these conditional polyfills in our application route hooks, to take advantage of their handling of async behaviour. Unfortunately, this isn’t currently possible, as the app will crash out due to missing Intl before any routes are instantiated.

The issue is that ember-intl’s instance initializer eagerly-inits the intl service, which inits some formatters, which crash out due to a dependency on the Intl API.

I also raised this issue in the #topic-i18n channel of Ember Discord in early April 2019.

Since this crash occurs in an instance initializer, which don’t support async operations, our workaround options are limited.

Presently, we’ve had to place our conditional polyfill logic in an application initializer, and use application.deferReadiness() and application.advanceReadiness to ensure the polyfill is loaded before ember-intl runs its own instance initializer.

Ideally, we’d like 1 of 2 solutions to become possible:

  • placing our conditional polyfill logic in our application route hook
    • this would mean ember-intl’s instance initializer and intl service, would need to avoid calling Intl
    • could the formatter instantiation be done lazily, perhaps?
  • adding conditional polyfill logic to ember-intl, so the intl service can polyfill itself before using Intl

I’d be open to contributing the latter - if we had a plan of attack I could pitch to my employers, we could schedule time for me to work on it.

Could a solution complement the work in https://github.com/ember-intl/experimental-polyfill, by adding autoPolyfill.strategy = FEATURE_DETECT?

Issue Template

  • I am on the latest ember-intl version
  • I have searched the issues of this repo and believe that this is not a duplicate

Environment

  • Ember Version: 3.5.0
  • Ember CLI Version: 3.5.1
  • Ember Intl Version: 2.33.4
  • Browser(s): iOS 9.3 webviews or Mobile Safari
  • Node Version: 10.15.0

We are on ember-intl@2.33.4, but the issue exists on current master as well: https://github.com/ember-intl/ember-intl/blob/master/addon/initializer.js

Steps to Reproduce

  1. create an Ember app with ember-intl
  2. add logic in your application route hook to conditionally load the Intl polyfill, based on feature detection
  3. load your app in a browser that doesn’t support the JS Intl API, such as an iOS 9 simulator

The app will crash out with ReferenceError: Can't find variable: Intl.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timiyaycommented, Apr 10, 2019

No worries. Feel free to shout out when you’ve got a direction in mind, and I can figure out how to contribute.

This issue is solved for my use case - I’ll leave it to you whether you want to close it, or keep it open to track the lazy API work.

1reaction
jasonmitcommented, Apr 10, 2019

I would not integrate with that addon. That’s experimental, I plan to finalize that work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid hook call. Hooks can only be called inside of the body ...
I had this issue when I used npm link to install my local library, which I've built using cra . I found the...
Read more >
extract-intl script can't parse LocaleToggle/messages.js #1221
npm run generate language > react-boilerplate@3.3.0 generate D:\Projects\react-boilerplate > plop --plopfile internals/generators/index.js "language" ?
Read more >
FAQ - next-intl
This library offers a hooks-only API for message consumption. The reason for this is that the same API can be used for attributes...
Read more >
Invalid Hook Call Warning - React
There are three common reasons you might be seeing it: You might have mismatching versions of React and React DOM. You might be...
Read more >
React Intl: Internationalize your React apps - LogRocket Blog
With the React Intl library, learn how to internationalize any React project to seamlessly change language and currency within web apps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found