File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { getWindow } from 'ssr-window' ;
1+ import { getWindow , getDocument } from 'ssr-window' ;
22import { getSupport } from './get-support.js' ;
33
44let deviceCalculated ;
@@ -154,7 +154,22 @@ function calcDevice({ userAgent } = {}) {
154154 return device ;
155155}
156156
157- function getDevice ( overrides = { } , reset ) {
157+ const IS_BROWSER = ( ( ) => {
158+ const document = getDocument ( ) ;
159+ try {
160+ // eslint-disable-next-line no-restricted-globals
161+ return Boolean (
162+ document &&
163+ document . body &&
164+ document . body . getBoundingClientRect &&
165+ document . body . getBoundingClientRect ( ) . width > 0 ,
166+ ) ;
167+ } catch ( e ) {
168+ return false ;
169+ }
170+ } ) ( ) ;
171+
172+ function getDevice ( overrides = { } , reset = IS_BROWSER ) {
158173 if ( ! deviceCalculated || reset ) {
159174 deviceCalculated = calcDevice ( overrides ) ;
160175 }
You can’t perform that action at this time.
0 commit comments