Skip to content

Commit 03eddcf

Browse files
authored
fix: prevent unsafe access to dom nodes in getDocumentDirection (#1788)
If a provider is in the head using mgt-loader the synchronous loading of mgt scripts causes LocaliztionHelper to attempt to access the body DOM node of the document before the browser has parsed the entire document causing body to be null. Using optional chaining avoids trying to call a method on a null object.
1 parent c46e418 commit 03eddcf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/mgt-element/src/utils/LocalizationHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class LocalizationHelper {
4646
* @memberof LocalizationHelper
4747
*/
4848
public static getDocumentDirection() {
49-
return document.body.getAttribute('dir') || document.documentElement.getAttribute('dir');
49+
return document.body?.getAttribute('dir') || document.documentElement?.getAttribute('dir');
5050
}
5151

5252
/**

0 commit comments

Comments
 (0)