Use globalThis.window to avoid window reference errors

[Description of changes]

No AI.

It is possible to get a reference error on Window is not defined at all (not defined at all does NOT mean "undefined"). We can use globalThis.window to avoid the error since globalThis.window is the same as window in the browser so also works fine in the browser.

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#syntax

Optional chaining cannot be used on a non-declared root object, but can be used with a root object with value undefined.

undeclaredVar?.prop; // ReferenceError: undeclaredVar is not defined

Testing instructions

  • First step for someone to test the changes in this MR

Closes #3590553 (closed)

Edited by Harumi Jang

Merge request reports

Loading