How to get rid of flickering with global variants?

Has anyone solved the “flicker” with Plasmic Global Theme Variants & Next.js?

We’re detecting dark/light mode from the client, and changing the ThemeContextsProvider state based on the user’s preference.

However, the browser briefly flickers, and we haven’t found a solution to tell the Plasmic ThemeContextsProvider to run the javascript and change the state before the HTML is painted.

Any thoughts on an approach?

flicker.gif