File tree 1 file changed +12
-2
lines changed
src/librustdoc/html/static/js
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,18 @@ function switchTheme(newThemeName, saveTheme) {
131
131
const newHref = getVar ( "root-path" ) + newThemeName +
132
132
getVar ( "resource-suffix" ) + ".css" ;
133
133
if ( ! window . currentTheme ) {
134
- document . write ( `<link rel="stylesheet" id="themeStyle" href="${ newHref } ">` ) ;
135
- window . currentTheme = document . getElementById ( "themeStyle" ) ;
134
+ // If we're in the middle of loading, document.write blocks
135
+ // rendering, but if we are done, it would blank the page.
136
+ if ( document . readyState === "loading" ) {
137
+ document . write ( `<link rel="stylesheet" id="themeStyle" href="${ newHref } ">` ) ;
138
+ window . currentTheme = document . getElementById ( "themeStyle" ) ;
139
+ } else {
140
+ window . currentTheme = document . createElement ( "link" ) ;
141
+ window . currentTheme . rel = "stylesheet" ;
142
+ window . currentTheme . id = "themeStyle" ;
143
+ window . currentTheme . href = newHref ;
144
+ document . documentElement . appendChild ( window . currentTheme ) ;
145
+ }
136
146
} else if ( newHref !== window . currentTheme . href ) {
137
147
window . currentTheme . href = newHref ;
138
148
}
You can’t perform that action at this time.
0 commit comments