[fix] StyleSheet.hairlineWidth guard against missing document.body

This commit is contained in:
Nicolas Gallagher
2018-01-04 13:41:49 -08:00
parent 87fdd6c73b
commit 6d9154196e
@@ -8,13 +8,16 @@ import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
const getHairlineWidth = () => { const getHairlineWidth = () => {
let hairlineWidth = 1; let hairlineWidth = 1;
if (canUseDOM && window.devicePixelRatio && window.devicePixelRatio >= 2) { if (canUseDOM && window.devicePixelRatio && window.devicePixelRatio >= 2) {
const node = document.createElement('div'); const body = document.body;
node.style.border = '.5px solid transparent'; if (body) {
document.body.appendChild(node); const node = document.createElement('div');
if (node.offsetHeight === 1) { node.style.border = '.5px solid transparent';
hairlineWidth = 0.5; body.appendChild(node);
if (node.offsetHeight === 1) {
hairlineWidth = 0.5;
}
body.removeChild(node);
} }
document.body.removeChild(node);
} }
return hairlineWidth; return hairlineWidth;
}; };