File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -282,6 +282,9 @@ private async void UpdateTheme()
282282 await LayoutService . ToggleDarkMode ( ) ;
283283 string theme = LayoutService . IsDarkMode ? "vs-dark" : "default" ;
284284 this . JsRuntime . InvokeVoid ( Try . Editor . SetTheme , theme ) ;
285+ // LayoutService calls StateHasChanged, we need the updated <style> tags for updateIframeTheme to work
286+ await Task . Yield ( ) ;
287+ await JsRuntime . InvokeVoidAsync ( "updateIframeTheme" ) ;
285288 }
286289 }
287290}
Original file line number Diff line number Diff line change 6161 < script src ="_content/MudBlazor/MudBlazor.min.js?v=#{CACHE_TOKEN}# "> </ script >
6262 < script src ="editor/main.js?v=#{CACHE_TOKEN}# "> </ script >
6363 < script type ="text/javascript ">
64- window . addEventListener ( 'storage' , ( e ) => {
65- if ( e . key == "userPreferences" ) {
66- const mudblazorTheme = parent . document . getElementsByTagName ( 'style' ) [ 4 ] ;
67- const iFrameTheme = document . getElementsByTagName ( 'style' ) [ 3 ] ;
68- iFrameTheme . innerHTML = mudblazorTheme . innerHTML ;
64+ function updateIframeTheme ( ) {
65+ const mudblazorTheme = parent . document . querySelector ( '.mud-theme-provider' ) || parent . document . getElementsByTagName ( 'style' ) [ 3 ] ;
66+
67+ if ( mudblazorTheme ) {
68+ // Find the iframe
69+ const userPageIframe = parent . document . getElementById ( 'user-page-window' ) ;
70+
71+ if ( userPageIframe && userPageIframe . contentDocument ) {
72+ const iframeDoc = userPageIframe . contentDocument ;
73+ const iFrameTheme = iframeDoc . querySelector ( '.mud-theme-provider' ) || iframeDoc . getElementsByTagName ( 'style' ) [ 2 ] ;
74+
75+ if ( iFrameTheme ) {
76+ iFrameTheme . innerHTML = mudblazorTheme . innerHTML ;
77+ }
78+ }
79+ } else {
80+ console . error ( 'Could not find the parent theme element.' ) ;
6981 }
70- } ) ;
82+ }
7183 </ script >
7284</ body >
7385
You can’t perform that action at this time.
0 commit comments