diff --git a/wwwroot/shell_theme.js b/wwwroot/shell_theme.js index 625ee6f..2b86ddb 100644 --- a/wwwroot/shell_theme.js +++ b/wwwroot/shell_theme.js @@ -122,6 +122,18 @@ initRouter(); } + // Bricks widgets render asynchronously after DOMContentLoaded. + // Retry updateThemeIcon until the button element exists. + (function retryThemeIcon() { + var btn = document.getElementById('theme_toggle_btn'); + if (btn) { + var theme = document.documentElement.getAttribute('data-theme') || 'dark'; + updateThemeIcon(theme); + } else { + setTimeout(retryThemeIcon, 200); + } + })(); + // Expose global functions for bricks bind access window.sageToggleTheme = toggleTheme; window.sageToggleSidebar = toggleSidebar;