Check existence of the `window` object when setting window translations
What does this MR do and why?
Adds some additional checks for the window
object in app/assets/javascripts/locale/index.js
.
This prevents Uncaught ReferenceError: window is not defined
errors when the i18n
methods are imported into a Web worker context.
Screenshots or screen recordings
How to set up and validate locally
- Apply this patch
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js
index 367180714dfb..9df871cdcfbc 100644
--- a/app/assets/javascripts/lib/utils/text_utility.js
+++ b/app/assets/javascripts/lib/utils/text_utility.js
@@ -1,4 +1,5 @@
import { isString, memoize } from 'lodash';
+import { sprintf, __ } from '~/locale';
import { base64ToBuffer, bufferToBase64 } from '~/authentication/webauthn/util';
import {
TRUNCATE_WIDTH_DEFAULT_WIDTH,
@@ -525,3 +526,5 @@ export function base64DecodeUnicode(str) {
const decoder = new TextDecoder('utf8');
return decoder.decode(base64ToBuffer(str));
}
+
+export const SOME_I18N_STRING = sprintf(__('this is a %{testStr}'), { testStr: 'test' });
- Run the
user_toggles_whitespace_changes_spec
file
$ rspec ./spec/features/merge_request/user_toggles_whitespace_changes_spec.rb
- The test will fail with a
window
is undefined error message.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Ezekiel Kigbo