From aadff2d56960df0e3827bb7ba5eff53f93cde1a2 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Fri, 5 Jan 2018 15:57:40 +0800 Subject: [PATCH] Fix ssr --- site/theme/template/Home/util.jsx | 64 ++++++++++++++++--------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/site/theme/template/Home/util.jsx b/site/theme/template/Home/util.jsx index 2f8ac1def2..ba883cada3 100644 --- a/site/theme/template/Home/util.jsx +++ b/site/theme/template/Home/util.jsx @@ -22,35 +22,37 @@ export default function svgBgToParallax(children, i = 0) { return svgChildren; } -// 图处预加载; -const div = document.createElement('div'); -div.style.display = 'none'; -document.body.appendChild(div); -[ - 'https://gw.alipayobjects.com/zos/rmsportal/DJWUmdpxcQakQHwhPjzf.png', - 'https://gw.alipayobjects.com/zos/rmsportal/DEaRdiYbAyVNRelJpwXx.png', - 'https://gw.alipayobjects.com/zos/rmsportal/cCmuVrmQIJYlrhFjiPDZ.png', - 'https://gw.alipayobjects.com/zos/rmsportal/TOElddMOrCWlgZvWTJna.png', - 'https://gw.alipayobjects.com/zos/rmsportal/FpKOqFadwoFFIZFExjaf.png', - 'https://gw.alipayobjects.com/zos/rmsportal/IauKICnGjGnotJBEyCRK.png', +if (typeof window !== 'undefined') { + // 图处预加载; + const div = document.createElement('div'); + div.style.display = 'none'; + document.body.appendChild(div); + [ + 'https://gw.alipayobjects.com/zos/rmsportal/DJWUmdpxcQakQHwhPjzf.png', + 'https://gw.alipayobjects.com/zos/rmsportal/DEaRdiYbAyVNRelJpwXx.png', + 'https://gw.alipayobjects.com/zos/rmsportal/cCmuVrmQIJYlrhFjiPDZ.png', + 'https://gw.alipayobjects.com/zos/rmsportal/TOElddMOrCWlgZvWTJna.png', + 'https://gw.alipayobjects.com/zos/rmsportal/FpKOqFadwoFFIZFExjaf.png', + 'https://gw.alipayobjects.com/zos/rmsportal/IauKICnGjGnotJBEyCRK.png', - 'https://gw.alipayobjects.com/zos/rmsportal/URIeCOKLMAbRXaeXoNqN.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/qXncdwwUTTgUFnsbCNCE.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/YFXXZocxAgjReehpPNbX.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/VPuetGsvJuYBwoDkZWFW.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/eYNnmGagLWdrkdMHVUuA.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/EPaPtDVGnJhyqyBAUZMl.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/GobRAKexhfTSJdLFzDFY.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/slVtnOCcgeAcLEPwtewY.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/UtBesTOkoZsBUxPqfDlZ.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/VrADJaRPMnFjmtmIhObV.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/MnLEmwjipfhzPUmBJnJE.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/dyNuxLOZtvjoHSVisbhQ.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/qggKjIGNFlVmMpwDUXPU.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/dgjVqwkJvptQEtlfctvk.svg', - 'https://gw.alipayobjects.com/zos/rmsportal/vUxYuDdsbBBcMDxSGmwc.svg', -].forEach((src) => { - const img = new Image(); - img.src = src; - div.appendChild(img); -}); + 'https://gw.alipayobjects.com/zos/rmsportal/URIeCOKLMAbRXaeXoNqN.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/qXncdwwUTTgUFnsbCNCE.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/YFXXZocxAgjReehpPNbX.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/VPuetGsvJuYBwoDkZWFW.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/eYNnmGagLWdrkdMHVUuA.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/EPaPtDVGnJhyqyBAUZMl.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/GobRAKexhfTSJdLFzDFY.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/slVtnOCcgeAcLEPwtewY.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/UtBesTOkoZsBUxPqfDlZ.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/VrADJaRPMnFjmtmIhObV.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/MnLEmwjipfhzPUmBJnJE.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/dyNuxLOZtvjoHSVisbhQ.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/qggKjIGNFlVmMpwDUXPU.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/dgjVqwkJvptQEtlfctvk.svg', + 'https://gw.alipayobjects.com/zos/rmsportal/vUxYuDdsbBBcMDxSGmwc.svg', + ].forEach((src) => { + const img = new Image(); + img.src = src; + div.appendChild(img); + }); +}