Skip to content

Commit 44968ea

Browse files
author
Steve Hobbs
authored
Guard references to window on module load (#2057)
* Guard references to window on module load * Rebuild * Reverse logic of window check in header.jsx
1 parent 067fa60 commit 44968ea

File tree

8 files changed

+69
-46
lines changed

8 files changed

+69
-46
lines changed

build/lock.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* lock v11.31.0
33
*
44
* Author: Auth0 <support@auth0.com> (http://auth0.com)
5-
* Date: 15/10/2021, 16:04:30
5+
* Date: 22/10/2021, 13:23:25
66
* License: MIT
77
*
88
*//******/ (function(modules) { // webpackBootstrap
@@ -7468,10 +7468,12 @@ function registerLanguageDictionary(language, dictionary) {
74687468
languageDictionaries[language] = __WEBPACK_IMPORTED_MODULE_1_immutable___default.a.fromJS(dictionary);
74697469
}
74707470

7471-
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_8__utils_cdn_utils__["b" /* preload */])({
7472-
method: 'registerLanguageDictionary',
7473-
cb: registerLanguageDictionary
7474-
});
7471+
if (typeof window !== 'undefined') {
7472+
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_8__utils_cdn_utils__["b" /* preload */])({
7473+
method: 'registerLanguageDictionary',
7474+
cb: registerLanguageDictionary
7475+
});
7476+
}
74757477

74767478
/***/ }),
74777479
/* 13 */
@@ -14744,7 +14746,7 @@ QuickAuthPane.propTypes = {
1474414746
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_auth0_js__ = __webpack_require__(101);
1474514747

1474614748

14747-
if (!window.Auth0) {
14749+
if (typeof window !== 'undefined' && !window.Auth0) {
1474814750
window.Auth0 = {};
1474914751
}
1475014752

@@ -20345,7 +20347,7 @@ var EscKeyDownHandler = function () {
2034520347
return EscKeyDownHandler;
2034620348
}();
2034720349

20348-
var IPHONE = window.navigator && !!window.navigator.userAgent.match(/iPhone/i);
20350+
var IPHONE = typeof window !== 'undefined' && window.navigator && !!window.navigator.userAgent.match(/iPhone/i);
2034920351

2035020352
var Container = function (_React$Component) {
2035120353
_inherits(Container, _React$Component);
@@ -20617,7 +20619,7 @@ Container.propTypes = {
2061720619
};
2061820620

2061920621
// NOTE: detecting the file protocol is important for things like electron.
20620-
var isFileProtocol = window.window && window.location && window.location.protocol === 'file:';
20622+
var isFileProtocol = typeof window !== 'undefined' && window.window && window.location && window.location.protocol === 'file:';
2062120623

2062220624
var defaultProps = Container.defaultProps = {
2062320625
autofocus: false,
@@ -25691,16 +25693,18 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
2569125693

2569225694

2569325695

25694-
if (typeof window.define == 'function' && window.define.amd) {
25695-
window.define('auth0Lock', function () {
25696-
return __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
25697-
});
25698-
window.define('auth0LockPasswordless', function () {
25699-
return __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
25700-
});
25701-
} else if (window.window) {
25702-
window.Auth0Lock = __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
25703-
window.Auth0LockPasswordless = __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
25696+
if (typeof window !== 'undefined') {
25697+
if (typeof window.define == 'function' && window.define.amd) {
25698+
window.define('auth0Lock', function () {
25699+
return __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
25700+
});
25701+
window.define('auth0LockPasswordless', function () {
25702+
return __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
25703+
});
25704+
} else if (window.window) {
25705+
window.Auth0Lock = __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
25706+
window.Auth0LockPasswordless = __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
25707+
}
2570425708
}
2570525709

2570625710
/***/ }),
@@ -30299,13 +30303,16 @@ WelcomeMessage.propTypes = {
3029930303
};
3030030304

3030130305
var cssBlurSupport = function () {
30302-
// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
30303-
var isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
30304-
if (typeof window.document === 'undefined' || isEdge) return false;
30306+
if (typeof window !== 'undefined') {
30307+
// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
30308+
var isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
30309+
if (typeof window.document === 'undefined' || isEdge) return false;
3030530310

30306-
var el = window.document.createElement('div');
30307-
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';
30308-
return !!el.style.length && (window.document.documentMode === undefined || window.document.documentMode > 9);
30311+
var el = window.document.createElement('div');
30312+
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';
30313+
30314+
return !!el.style.length && (window.document.documentMode === undefined || window.document.documentMode > 9);
30315+
}
3030930316
}();
3031030317

3031130318
var Background = function (_React$Component4) {

build/lock.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lock.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/browser.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
import Auth0Lock from './index';
1111
import Auth0LockPasswordless from './passwordless';
1212

13-
if (typeof window.define == 'function' && window.define.amd) {
14-
window.define('auth0Lock', function() {
15-
return Auth0Lock;
16-
});
17-
window.define('auth0LockPasswordless', function() {
18-
return Auth0LockPasswordless;
19-
});
20-
} else if (window.window) {
21-
window.Auth0Lock = Auth0Lock;
22-
window.Auth0LockPasswordless = Auth0LockPasswordless;
13+
if (typeof window !== 'undefined') {
14+
if (typeof window.define == 'function' && window.define.amd) {
15+
window.define('auth0Lock', function () {
16+
return Auth0Lock;
17+
});
18+
window.define('auth0LockPasswordless', function () {
19+
return Auth0LockPasswordless;
20+
});
21+
} else if (window.window) {
22+
window.Auth0Lock = Auth0Lock;
23+
window.Auth0LockPasswordless = Auth0LockPasswordless;
24+
}
2325
}

src/i18n.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function registerLanguageDictionary(language, dictionary) {
9191
languageDictionaries[language] = Immutable.fromJS(dictionary);
9292
}
9393

94-
preload({
95-
method: 'registerLanguageDictionary',
96-
cb: registerLanguageDictionary
97-
});
94+
if (typeof window !== 'undefined') {
95+
preload({
96+
method: 'registerLanguageDictionary',
97+
cb: registerLanguageDictionary
98+
});
99+
}

src/ui/box/container.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class EscKeyDownHandler {
5858
}
5959
}
6060

61-
const IPHONE = window.navigator && !!window.navigator.userAgent.match(/iPhone/i);
61+
const IPHONE =
62+
typeof window !== 'undefined' &&
63+
window.navigator &&
64+
!!window.navigator.userAgent.match(/iPhone/i);
6265

6366
export default class Container extends React.Component {
6467
constructor(props) {
@@ -288,7 +291,11 @@ Container.propTypes = {
288291
};
289292

290293
// NOTE: detecting the file protocol is important for things like electron.
291-
const isFileProtocol = window.window && window.location && window.location.protocol === 'file:';
294+
const isFileProtocol =
295+
typeof window !== 'undefined' &&
296+
window.window &&
297+
window.location &&
298+
window.location.protocol === 'file:';
292299

293300
export const defaultProps = (Container.defaultProps = {
294301
autofocus: false,

src/ui/box/header.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ WelcomeMessage.propTypes = {
7878
name: PropTypes.string
7979
};
8080

81-
const cssBlurSupport = (function() {
81+
const cssBlurSupport = (function () {
82+
if (typeof window === 'undefined') {
83+
return;
84+
}
85+
8286
// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
8387
const isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
8488
if (typeof window.document === 'undefined' || isEdge) return false;
8589

8690
const el = window.document.createElement('div');
8791
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';
92+
8893
return (
8994
!!el.style.length &&
9095
(window.document.documentMode === undefined || window.document.documentMode > 9)

src/utils/cdn_utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Auth0 from 'auth0-js';
22

3-
if (!window.Auth0) {
3+
if (typeof window !== 'undefined' && !window.Auth0) {
44
window.Auth0 = {};
55
}
66

@@ -11,7 +11,7 @@ export function load(attrs) {
1111

1212
if (!cbs[method]) {
1313
cbs[method] = [];
14-
window.Auth0[method] = function(...args) {
14+
window.Auth0[method] = function (...args) {
1515
cbs[method] = cbs[method].filter(x => {
1616
if (x.check(...args)) {
1717
setTimeout(() => x.cb(null, ...args), 0);

0 commit comments

Comments
 (0)