Skip to content

Commit 507a26d

Browse files
committed
html: fix updating when new style is appended to live
1 parent 73e8f31 commit 507a26d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

fixtures/html/simple.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,33 @@ async function sleep(ms) {
3939
return new Promise((resolve) => setTimeout(resolve, ms));
4040
}
4141

42-
(async () => {
42+
async function run(fn) {
43+
try {
44+
await fn();
45+
} catch (err) {
46+
console.warn('Error in main function:', err);
47+
}
48+
}
49+
50+
run(async () => {
4351
await sleep(1000);
4452
const some = document.createElement('div');
4553
some.style.setProperty('width', '100px');
4654
some.style.setProperty('height', '100px');
4755
some.style.setProperty('background-color', 'red');
4856
document.body.appendChild(some);
4957

58+
// test append style
59+
await sleep(1000);
60+
const style = document.createElement('style');
61+
const cssSource = document.createTextNode(`
62+
body {
63+
background-color: lightgray;
64+
}
65+
`);
66+
style.appendChild(cssSource);
67+
document.head.appendChild(style);
68+
5069
await sleep(1000);
5170
const bar = document.createElement('div');
5271
bar.style.width = '100px';
@@ -68,4 +87,4 @@ async function sleep(ms) {
6887
// '<div style="width:100px;height:100px;background-color:blue;font-size:30px;color:#fff">'
6988
// + 'foobar'
7089
// + '</div>';
71-
})();
90+
});

src/client/html/html_style_element.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ namespace dom
3232

3333
// Update the sheet
3434
sheet_ = sheet;
35-
getOwnerDocumentChecked().styleSheets_.push_back(sheet);
35+
getOwnerDocumentChecked().appendStyleSheet(sheet);
3636
}
3737
}

0 commit comments

Comments
 (0)