-
Notifications
You must be signed in to change notification settings - Fork 46
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
ErrorPage fails on getLocale() because i18n isn't initialized. #590
Labels
bug
Report of or fix for something that isn't working as intended
Comments
After toying with this this morning, we have a fix: diff --git a/src/index.jsx b/src/index.jsx
index e7be0ea5..87927526 100755
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -20,7 +20,7 @@ import ReactDOM from 'react-dom';
import { Route, Switch } from 'react-router-dom';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
-import { logError } from '@edx/frontend-platform/logging';
+import { getLoggingService, logError } from '@edx/frontend-platform/logging';
import Header, { messages as headerMessages } from '@edx/frontend-component-header';
import Footer, { messages as footerMessages } from '@edx/frontend-component-footer';
@@ -31,6 +31,8 @@ import {
import configureStore from './data/configureStore';
import './index.scss';
+import { configure as configureI18n } from '@edx/frontend-platform/i18n/lib';
+import { getLocale } from '@edx/frontend-platform/i18n';
const tempHttpClient = axios.create();
tempHttpClient.defaults.withCredentials = true;
@@ -85,6 +87,15 @@ subscribe(APP_READY, () => {
});
subscribe(APP_INIT_ERROR, (error) => {
+ try {
+ getLocale('en');
+ } catch (e) {
+ configureI18n({
+ messages: {},
+ config: getConfig(),
+ loggingService: getLoggingService(),
+ });
+ }
ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));
}); I will shortly have this in frontend-app-payment, once I and my team approve it. |
arbrandes
added
the
bug
Report of or fix for something that isn't working as intended
label
May 31, 2023
This is great, thanks @grmartin! I love an issue report that comes with a fix. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
Some (maybe all?) MFEs have issues with ErrorPages and i18n.
The ErrorPage is invoked before either the Locale is set or Intl is initialized as a whole.
This should likely later be remediated in any MFEs that have this issue.
Repro Steps
lms+redis+ecommerce
)npm ci && npm start
Technical/Additional Details
Specific Error:
getLocale called before configuring i18n. Call configure with messages first.
Stack Trace:
Code Ptr (ErrorPage initialization point): https://github.com/openedx/frontend-template-application/blob/master/src/index.jsx#L28
Community Example (learner MFE): https://discuss.openedx.org/t/when-attempting-to-enter-a-courses-home-on-learning-mfe-error-getlocale-called-before-configuring-i18n/9756/1
The text was updated successfully, but these errors were encountered: