Open grmartin opened 1 year ago
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.
This has been merged, instead they get the default template language and its less intimidating:
This is great, thanks @grmartin! I love an issue report that comes with a fix. :)
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