Merge pull request #6524 from matrix-org/palid/feature-css/hmr

Add data-mx-theme to theme css for hot-reload
This commit is contained in:
Dariusz Niemczyk 2021-08-04 15:35:15 +02:00 committed by GitHub
commit c848b8f486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,15 +171,10 @@ export async function setTheme(theme) {
// look for the stylesheet elements. // look for the stylesheet elements.
// styleElements is a map from style name to HTMLLinkElement. // styleElements is a map from style name to HTMLLinkElement.
const styleElements = Object.create(null); const styleElements = Object.create(null);
let a; const themes = Array.from(document.querySelectorAll('[data-mx-theme]'));
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) { themes.forEach(theme => {
const href = a.getAttribute("href"); styleElements[theme.attributes['data-mx-theme'].value.toLowerCase()] = theme;
// shouldn't we be using the 'title' tag rather than the href? });
const match = href && href.match(/^bundles\/.*\/theme-(.*)\.css$/);
if (match) {
styleElements[match[1]] = a;
}
}
if (!(stylesheetName in styleElements)) { if (!(stylesheetName in styleElements)) {
throw new Error("Unknown theme " + stylesheetName); throw new Error("Unknown theme " + stylesheetName);