I am currently implementing dark mode in my next.js application that works by fetching a localstorage value then setting the data-theme in the body tag equal to something.
In react I put a script tag in the App.js however now when I put this script in the layout.js file it works on routes that don't require a api call server side, but on routes that require a server side api call it flickers before the response is given and then goes to the set mode, is there a way to fix this or like push the script with priority or something? apologies I'm relatively new to next and tried to quote the docs.
TLDR: Is there a way to push <script> rendering infront of server side api calls so my dark mode doesnt flicker something better then strategy="beforeInteractive"?