From 5f31d090982f6bf347124061a5f2d5eeebc46549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Sat, 3 Jul 2021 22:09:04 +0800 Subject: [PATCH] fix: preload removeChild error --- src/preload/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/preload/index.js b/src/preload/index.js index 1fc395a..af51596 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -21,6 +21,9 @@ function loadingBootstrap() { const loadingStyle = document.createElement('style'); const loadingBox = document.createElement('div'); + loadingStyle.id = 'preload-loading-style'; + loadingBox.id = 'preload-loading-box'; + loadingStyle.textContent += ` /* https://projects.lukehaas.me/css-loaders/ */ .loading-box { height: 100vh; width: 100vw; position: fixed; left: 0; top: 0; display: flex; align-items: center; background-color: #242424; z-index: 9; } @@ -104,8 +107,12 @@ function loadingBootstrap() { }; const removeLoading = () => { - document.head.removeChild(loadingStyle); - document.body.removeChild(loadingBox); + const _loadingStyle = document.getElementById('preload-loading-style'); + const _loadingBox = document.getElementById('preload-loading-box'); + + // Ensure the remove child exists. + _loadingStyle && document.head.removeChild(_loadingStyle); + _loadingBox && document.body.removeChild(_loadingBox); }; return { loadingStyle, loadingBox, removeLoading, appendLoading }