Repository navigation
fix(images): address PR review feedback for profiles, pseudo specificity, and large subtrees #206
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,10 @@ const CSS_IMAGE_VALUE_REGEX = | |
| /(?:url|-webkit-image-set|image-set|cross-fade)\s*\(/i; | ||
| const HIDE_IMAGES_STYLE_ID = "arap-hide-images-style"; | ||
| const HIDE_IMAGES_PSEUDO_CSS = [ | ||
| "[data-arap-hide-before-bg]::before { background-image: none !important; }", | ||
| "[data-arap-hide-after-bg]::after { background-image: none !important; }", | ||
| "[data-arap-hide-before-content]::before { visibility: hidden !important; }", | ||
| "[data-arap-hide-after-content]::after { visibility: hidden !important; }", | ||
| "[data-arap-hide-before-bg]:not(#arap-s1):not(#arap-s2):not(#arap-s3)::before { background-image: none !important; }", | ||
| "[data-arap-hide-after-bg]:not(#arap-s1):not(#arap-s2):not(#arap-s3)::after { background-image: none !important; }", | ||
| "[data-arap-hide-before-content]:not(#arap-s1):not(#arap-s2):not(#arap-s3)::before { visibility: hidden !important; }", | ||
| "[data-arap-hide-after-content]:not(#arap-s1):not(#arap-s2):not(#arap-s3)::after { visibility: hidden !important; }", | ||
| ].join("\n"); | ||
| type StyleableElement = HTMLElement | SVGElement; | ||
| export const MAX_HOST_ELEMENTS = 8000; | ||
|
|
@@ -2575,8 +2575,10 @@ export function useBuiltinEffects( | |
| let refreshTimer: ReturnType<typeof setTimeout> | null = null; | ||
| let incrementalTimer: ReturnType<typeof setTimeout> | null = null; | ||
| let mediaTimer: ReturnType<typeof setTimeout> | null = null; | ||
| let largeClassTimer: ReturnType<typeof setTimeout> | null = null; | ||
| let pendingAddedNodes: HTMLElement[] = []; | ||
| const pendingMediaNodes = new Set<StyleableElement>(); | ||
| const pendingLargeClassRoots = new Set<Element>(); | ||
|
|
||
| const flushIncremental = () => { | ||
| if (pendingAddedNodes.length === 0) return; | ||
|
|
@@ -2594,6 +2596,30 @@ export function useBuiltinEffects( | |
| observer.takeRecords(); | ||
| }; | ||
|
|
||
| const flushLargeClassSubtrees = () => { | ||
| if (pendingLargeClassRoots.size === 0) return; | ||
| const roots = Array.from(pendingLargeClassRoots); | ||
| pendingLargeClassRoots.clear(); | ||
| const collected: StyleableElement[] = []; | ||
| for (const root of roots) { | ||
| if (!document.contains(root)) continue; | ||
| if (isStyleableElement(root) && !root.matches(EXCLUDED)) { | ||
| collected.push(root); | ||
| } | ||
| for (const desc of Array.from(root.querySelectorAll("*"))) { | ||
| if (collected.length >= MAX_HOST_ELEMENTS) break; | ||
|
Comment on lines
+2609
to
+2610
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a class change occurs on a subtree with more than 200 descendants, Useful? React with 👍 / 👎. |
||
| if (isStyleableElement(desc) && !desc.matches(EXCLUDED)) { | ||
| collected.push(desc); | ||
| } | ||
| } | ||
| if (collected.length >= MAX_HOST_ELEMENTS) break; | ||
| } | ||
| if (collected.length > 0) { | ||
| activeSession.applyMediaIncremental?.(collected); | ||
| observer.takeRecords(); | ||
| } | ||
| }; | ||
|
|
||
| const scheduleFullRefresh = (delay = 25) => { | ||
| if (refreshTimer) clearTimeout(refreshTimer); | ||
| refreshTimer = setTimeout(() => { | ||
|
|
@@ -2608,6 +2634,7 @@ export function useBuiltinEffects( | |
| let hasRootAttributeChange = false; | ||
| const added: HTMLElement[] = []; | ||
| const mediaNodes: StyleableElement[] = []; | ||
| const largeClassRoots: Element[] = []; | ||
|
|
||
| for (const record of records) { | ||
| if (record.type === "attributes") { | ||
|
|
@@ -2640,14 +2667,16 @@ export function useBuiltinEffects( | |
| ) | ||
| ) { | ||
| if (attrName === "class" && values.hideImages) { | ||
| mediaNodes.push(record.target); | ||
| const descendants = record.target.querySelectorAll("*"); | ||
| if (descendants.length <= 200) { | ||
| mediaNodes.push(record.target); | ||
| for (const desc of Array.from(descendants)) { | ||
| if (isStyleableElement(desc) && !desc.matches(EXCLUDED)) { | ||
| mediaNodes.push(desc); | ||
| } | ||
| } | ||
| } else { | ||
| largeClassRoots.push(record.target); | ||
| } | ||
| } else if ( | ||
| record.target.matches( | ||
|
|
@@ -2699,6 +2728,14 @@ export function useBuiltinEffects( | |
| if (mediaTimer) clearTimeout(mediaTimer); | ||
| mediaTimer = setTimeout(flushMediaIncremental, 16); | ||
| } | ||
|
|
||
| if (largeClassRoots.length > 0) { | ||
| for (const root of largeClassRoots) { | ||
| pendingLargeClassRoots.add(root); | ||
| } | ||
| if (largeClassTimer) clearTimeout(largeClassTimer); | ||
| largeClassTimer = setTimeout(flushLargeClassSubtrees, 50); | ||
| } | ||
| }); | ||
|
|
||
| const attributeFilter = ["class", "data-theme", "dir", "lang"]; | ||
|
|
@@ -2786,6 +2823,7 @@ export function useBuiltinEffects( | |
| if (refreshTimer) clearTimeout(refreshTimer); | ||
| if (incrementalTimer) clearTimeout(incrementalTimer); | ||
| if (mediaTimer) clearTimeout(mediaTimer); | ||
| if (largeClassTimer) clearTimeout(largeClassTimer); | ||
| observer.disconnect(); | ||
| for (const cleanup of fontCleanups) cleanup(); | ||
| window.removeEventListener("resize", resize); | ||
|
|
||
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.
When a host element with a pseudo image has the ID
arap-s1,arap-s2, orarap-s3, each:not()term excludes it, so the hide rule does not match even though the plugin marked the pseudo for hiding. Use a specificity bump that cannot exclude an element with one of these IDs.Useful? React with 👍 / 👎.