Skip to content

Commit 800b586

Browse files
committed
fix: disable cache for device-info on server
fixes #4252
1 parent c1ac6c7 commit 800b586

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/core/shared/get-device.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getWindow } from 'ssr-window';
1+
import { getWindow, getDocument } from 'ssr-window';
22
import { getSupport } from './get-support.js';
33

44
let 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
}

0 commit comments

Comments
 (0)