-
Notifications
You must be signed in to change notification settings - Fork 885
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
Avoid layout re-flow for cosmetic filtering #4585
Conversation
1a65948
to
d7b7094
Compare
d7b7094
to
9c24069
Compare
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.
lgtm
.map(selector => | ||
allSelectorsToRules.get(selector) | ||
) | ||
.filter(i => i !== undefined) |
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.
what is this checking? I dont see why this could happen
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.
if allSelectorsToRules
is passed a selector it does not contain then it will give us an undefined
entry, which is going to mess with knowing the count to shift other indexes, as well as we'll have to check for it anyway before attempting to remove the undefined
index rule.
We may know this cannot happen, but this function does not, and if we pass undefined
to CSSStyleSheet.deleteRule()
then it's not going to delete the rule we intended and all our indexes will be off.
} | ||
continue | ||
} | ||
if (oldIdx !== i) { |
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.
similarly, whats going on here?
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.
A sanity check that any previous re-indexes have kept this item in-sync. Though since we expect the actual index
of an item in the Map
to match the lookup value of the Map's item, we probably may as well use a combination of Set
and array
. Either way we would be doing something like converting Set to Array to find an index, or using indexOf
for the lookup. So, this works for now and seems just as performant. Having said that, would love to optimize if you can think of a way.
9c24069
to
5ec0bd5
Compare
Just re-building macOS. Sure it's fine, but being double-safe |
…they are found to be 1st-party Fixes layout re-flow Co-authored-by: Pete Miller <[email protected]>
Since we do not have a chrome.tabs.removeCSS API, we need another method for restoring the page's original css `display` rule value. Adding and removing rule via a constructed CSSStyleSheet injected via document.adoptedStyleSheets serves this purpose.
5ec0bd5
to
36c8577
Compare
Updated to add missing milestone (both to this PR and the issue 👍) |
Resolves brave/brave-browser#8197
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
After-merge Checklist:
changes has landed on.