I'm using the oninitialclientrender from Gatsby the Gatsby API and @TheWeeezel's method from Show overlay only once on page entrance (not route change). HowTo? to use a React component as a loading screen for my site. The issue is that there is a noticable delay on the initial loading of the svg's styling needed for positioning and fills. I've tried inline styling instead of loading the styling using a css file, but it still causes the same delay. Here is my code from my custom html.js file.
<div
id="___loader"
key={`loader`}
style={{
background: "#0F2027",
height: "100%",
width: "100%",
margin: "0",
padding: "0",
}}
>
<LoadingAssets></LoadingAssets>
</div>
Here is the code from my gatsby-browser.js file too.
exports.onInitialClientRender = () => {
console.log("loaded")
setTimeout(() => {
document.getElementById("___loader").style.opacity = "0"
console.log("loader changed.")
}, 1000)
setTimeout(() => {
document.getElementById("___loader").style.display = "none"
console.log("loader removed")
}, 2000)
setTimeout(() => {
document.getElementById("___gatsby").style.display = "block"
}, 2000)
setTimeout(() => {
document.getElementById("___gatsby").style.opacity = 1
}, 3000)
}
How could I optimize this better so that the delay isn't noticeable on the svg styling?