File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @jest -environment node
3+ */
4+
5+ import { isServer } from '../core/utils' ;
6+
7+ describe ( 'utils-node-env' , ( ) => {
8+ test ( 'isServer should work' , async ( ) => {
9+ expect ( isServer ) . toBe ( true ) ;
10+ } ) ;
11+ } ) ;
Original file line number Diff line number Diff line change @@ -17,10 +17,12 @@ export const isFunction = (fn: unknown): fn is Function =>
1717
1818export const isNil = ( val : unknown ) => val === null || val === undefined ;
1919
20+ export const isServer = typeof window === 'undefined' ;
21+
2022export const isDocumentVisibility = ( ) =>
21- window ?. document ?. visibilityState === 'visible' ;
23+ ! isServer && window ?. document ?. visibilityState === 'visible' ;
2224
23- export const isOnline = ( ) => window ?. navigator ?. onLine ?? true ;
25+ export const isOnline = ( ) => ( ! isServer && window ?. navigator ?. onLine ) ?? true ;
2426
2527export const unRefObject = < T extends RefObject > ( val : T ) => {
2628 const obj = { } ;
Original file line number Diff line number Diff line change 1- import { isDocumentVisibility } from './index' ;
1+ import { isDocumentVisibility , isServer } from './index' ;
22
33type EventFunc = ( ) => void ;
44type ListenersSet = Set < EventFunc > ;
@@ -40,7 +40,7 @@ const observer = (listeners: ListenersSet) => {
4040} ;
4141
4242/* istanbul ignore else */
43- if ( window ?. addEventListener ) {
43+ if ( ! isServer && window ?. addEventListener ) {
4444 window . addEventListener (
4545 'visibilitychange' ,
4646 ( ) => {
You can’t perform that action at this time.
0 commit comments