-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply CSSRule insertion/deltetion on Flush event #529
Apply CSSRule insertion/deltetion on Flush event #529
Conversation
Restore skip duration Use virtualStyleRulesMap to re-populate stylesheet on Flush event Clear virtualStyleRulesMap after flush applied
efce46f
to
b3aff90
Compare
LGTM @Mark-Fenng PTAL |
A great way to fix the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really loving this, great work @VladimirMilenko!
I found a couple spots where we could make the tests a little more readable
const rules = Array.from(replayer.iframe.contentDocument.head.children) | ||
.filter(x=>x.nodeName === 'STYLE') | ||
.reduce((acc, node) => { | ||
acc.push(...node.sheet.rules); | ||
return acc; | ||
}, []); | ||
|
||
rules.some(x=>x.selectorText === ".css-1fbxx79") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we could simplify this a little
const rules = Array.from(replayer.iframe.contentDocument.head.children) | |
.filter(x=>x.nodeName === 'STYLE') | |
.reduce((acc, node) => { | |
acc.push(...node.sheet.rules); | |
return acc; | |
}, []); | |
rules.some(x=>x.selectorText === ".css-1fbxx79") | |
const rules = [...replayer.iframe.contentDocument.styleSheets].map((sheet)=> sheet.rules); | |
rules.some(x=>x.selectorText === ".css-1fbxx79") |
const rules = Array.from(replayer.iframe.contentDocument.head.children) | ||
.filter(x=>x.nodeName === 'STYLE') | ||
.reduce((acc, node) => { | ||
acc.push(...node.sheet.rules); | ||
return acc; | ||
}, []); | ||
|
||
rules.some(x=>x.selectorText === ".css-1fbxx79") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for here
const rules = Array.from(replayer.iframe.contentDocument.head.children) | |
.filter(x=>x.nodeName === 'STYLE') | |
.reduce((acc, node) => { | |
acc.push(...node.sheet.rules); | |
return acc; | |
}, []); | |
rules.some(x=>x.selectorText === ".css-1fbxx79") | |
const rules = [...replayer.iframe.contentDocument.styleSheets].map((sheet)=> sheet.rules); | |
rules.some(x=>x.selectorText === ".css-1fbxx79") |
As far as I can remember it is necessary the first time the |
It looks like constructible stylesheets ( We might be able to get it working by using this polyfill: https://github.com/calebdwilliams/construct-style-sheets |
@VladimirMilenko feel free to close this PR. I ended up incorporating most of it in #618 which fixes this issue. |
Currently, during the node replacement, the
sheet
property is being automatically assigned to null.In order to support virtual sheet mutation, we need to store that sheet in another structure.
We also cannot reuse the existing reference to sheet, as the value at this reference would be removed at the
replaceChild
call.To avoid that, we will create:
This rule array map would keep the latest CSSRule array for each node during the virtual processing of events and would ensure, that at the Flush event,
style
node has exact same array of css rules, as the one in memory.I've also added a test which is able to check, whether the stylesheet rule exists in the sheet after insertion.
Fixes #525