Skip to content

Commit 825fe24

Browse files
CroModderbip-dev
andauthored
[#44] Check if document object exists before using it (#45)
* Check if document object exists before using it. * Wrap whole code inside if block Co-authored-by: Paolo Bozac <[email protected]>
1 parent 7c1e7c7 commit 825fe24

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ function injectionCSSCodePlugin(cssToInject: string, styleId?: string): Plugin {
4848
if (id == cssInjectedByJsId) {
4949
const cssCode = JSON.stringify(cssToInject.trim());
5050

51-
return `try{var elementStyle = document.createElement('style');${
51+
return `try{if (typeof document !== 'undefined'){var elementStyle = document.createElement('style');${
5252
typeof styleId == 'string' && styleId.length > 0 ? `elementStyle.id = '${styleId}';` : ''
53-
}elementStyle.appendChild(document.createTextNode(${cssCode}));document.head.appendChild(elementStyle);}catch(e){console.error('vite-plugin-css-injected-by-js', e);}`;
53+
}elementStyle.appendChild(document.createTextNode(${cssCode}));document.head.appendChild(elementStyle);}}catch(e){console.error('vite-plugin-css-injected-by-js', e);}`;
5454
}
5555
},
5656
};

0 commit comments

Comments
 (0)