Skip to content

Commit 5d6323c

Browse files
committed
fix: Uncaught Error: document is not defined for SSR (#7926)
Fix error when window is set but document is undefined when running SSR. Modify test input data to show problem. Ignore lint error in testfile
1 parent 1457ded commit 5d6323c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/@react-aria/interactions/src/useFocusVisible.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function handleWindowBlur() {
123123
* Setup global event listeners to control when keyboard focus style should be visible.
124124
*/
125125
function setupGlobalFocusEvents(element?: HTMLElement | null) {
126-
if (typeof window === 'undefined' || hasSetupGlobalListeners.get(getOwnerWindow(element))) {
126+
if (typeof window === 'undefined' || typeof document === 'undefined' || hasSetupGlobalListeners.get(getOwnerWindow(element))) {
127127
return;
128128
}
129129

packages/dev/test-utils/src/ssrWorker.js

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ ignoreStyles.default(undefined, (module) => {
2121
module.exports = identityObjectProxy;
2222
});
2323

24+
// some environments may partially define window without document
25+
// removing this can break tests and/or checks that rely on detecting true browser environment
26+
// always check for both window AND window.document existence to more robustly
27+
// before assuming that the current environment is the browser
28+
// eslint-disable-next-line no-global-assign
29+
window = {};
30+
2431
require('@babel/register')({
2532
extensions: ['.js', '.ts', '.tsx']
2633
});

0 commit comments

Comments
 (0)