Skip to content

Commit 636d470

Browse files
authoredJul 11, 2022
refactor(core): use has instead of get to test for existence in ExecEnv (#7763)
refactor(core): use has instead of get to test for existence
1 parent f21dadf commit 636d470

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
 

‎packages/docusaurus/src/client/exports/ExecutionEnvironment.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const canUseDOM = !!(
8+
const canUseDOM =
99
typeof window !== 'undefined' &&
10-
window.document &&
11-
window.document.createElement
12-
);
10+
'document' in window &&
11+
'createElement' in window.document;
1312

1413
const ExecutionEnvironment = {
1514
canUseDOM,
1615

16+
// window.attachEvent is IE-specific; it's very likely Docusaurus won't work
17+
// on IE anyway.
1718
canUseEventListeners:
18-
// @ts-expect-error: window.attachEvent is IE specific.
19-
// See https://github.com/Microsoft/TypeScript/issues/3953#issuecomment-123396830
20-
canUseDOM && !!(window.addEventListener || window.attachEvent),
19+
canUseDOM && ('addEventListener' in window || 'attachEvent' in window),
2120

2221
canUseIntersectionObserver: canUseDOM && 'IntersectionObserver' in window,
2322

24-
canUseViewport: canUseDOM && !!window.screen,
23+
canUseViewport: canUseDOM && 'screen' in window,
2524
};
2625

2726
export default ExecutionEnvironment;

0 commit comments

Comments
 (0)
Please sign in to comment.