-
Notifications
You must be signed in to change notification settings - Fork 25.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
LOCALE_ID is being set before APP_INITIALIZER finish execution - [ng serve only] #34701
Comments
The problem is indeed that we are setting the locale (for ivy) before the application initialisers run.
I think this analysis is actually incorrect. I think we can just move the code... |
This PR (#31465) effectively fixed it for non-ivy because the getting of angular/packages/core/test/application_ref_spec.ts Lines 346 to 359 in 86e1e6c
|
Before ivy it was possible to configure a mutable service value in an application initializer (by providing an `APP_INITIALIZER`) that could be read in the provider of `LOCALE_ID`. This is a common scenario if you wanted to load the locale id asynchronously from an HTTP request for instance. When using the ivy, the runtime needs to be told what the current locale is, which is done by calling the `setLocaleId()` function with the value injected by the `LOCALE_ID` token. Previously this was being done before the application initializers were run, which meant that the `LOCALE_ID` provider was being executed before the app initializers had a chance to get a new value for it. Now this initalization of the locale for the ivy runtime is done after the application initializers have been run. Closes angular#34701
Before ivy it was possible to configure a mutable service value in an application initializer (by providing an `APP_INITIALIZER`) that could be read in the provider of `LOCALE_ID`. This is a common scenario if you wanted to load the locale id asynchronously from an HTTP request for instance. When using the ivy, the runtime needs to be told what the current locale is, which is done by calling the `setLocaleId()` function with the value injected by the `LOCALE_ID` token. Previously this was being done before the application initializers were run, which meant that the `LOCALE_ID` provider was being executed before the app initializers had a chance to get a new value for it. Now this initalization of the locale for the ivy runtime is done after the application initializers have been run. Closes angular#34701
Before ivy it was possible to configure a mutable service value in an application initializer (by providing an `APP_INITIALIZER`) that could be read in the provider of `LOCALE_ID`. This is a common scenario if you wanted to load the locale id asynchronously from an HTTP request for instance. When using the ivy, the runtime needs to be told what the current locale is, which is done by calling the `setLocaleId()` function with the value injected by the `LOCALE_ID` token. Previously this was being done before the application initializers were run, which meant that the `LOCALE_ID` provider was being executed before the app initializers had a chance to get a new value for it. Now this initalization of the locale for the ivy runtime is done after the application initializers have been run. Closes #34701 PR Close #34830
I can confirm it is working now on 9.0.0-rc.10. Thank you! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command (mark with an
x
)Is this a regression?
Yes. It is a breaking change.
Description
LOCALE_ID is being set before APP_INITIALIZER function finish execution.
Interestingly, this behavior can be observed only with ng serve. Both repositories will work fine on stackblitz.
🔬 Minimal Reproduction
Here is the reproduction repo:
https://stackblitz.com/github/TomaszCz/angular-ivy-LOCALID
and the same repo after ng update @angular/core @angular/cli --next
https://stackblitz.com/github/TomaszCz/angular-ivy-LOCALID/tree/angular9
clone and run ng serve the updated one will not work - the locale value will be undefined.
🔥 Exception or Error
After update:
Before the update:
🌍 Your Environment
Before update:
After update:
I see similar closed issue
#31465
and the fix 08c449d
#31983
The text was updated successfully, but these errors were encountered: