Skip to content
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

Stop gathering element's CSS rules at the nearest HTML element #10608

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/devtools/client/inspector/rules/models/element-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,29 @@ export default class ElementStyle {

// Show relevant rules applied to parent elements.
while (parentNodeId) {
const nodeObject = await objectCache.readAsync(
const parentObject = await objectCache.readAsync(
this.replayClient,
this.pauseId,
parentNodeId,
"canOverflow"
);
const elem = nodeObject.preview?.node;
if (!elem) {
const parentNode = parentObject.preview?.node;
if (!parentNode) {
break;
}
const elemNodeWithId = { nodeId: parentNodeId, node: elem };
const parentNodeWithId = { nodeId: parentNodeId, node: parentNode };

if (elem.nodeType == Node.ELEMENT_NODE) {
if (elem.style) {
if (parentNode.nodeType == Node.ELEMENT_NODE) {
if (parentNode.style) {
const styleObject = await objectCache.readAsync(
this.replayClient,
this.pauseId,
elem.style!,
parentNode.style!,
"canOverflow"
);
const parentInline = new StyleFront(styleObject);
if (parentInline.properties.length > 0) {
this._maybeAddRule(parentInline, elemNodeWithId);
this._maybeAddRule(parentInline, parentNodeWithId);
}
}

Expand All @@ -153,12 +153,16 @@ export default class ElementStyle {

for (const { rule, pseudoElement } of parentApplied) {
if (!pseudoElement) {
this._maybeAddRule(rule, elemNodeWithId);
this._maybeAddRule(rule, parentNodeWithId);
}
}
}

parentNodeId = elem.parentNode;
if (parentObject.preview?.node?.nodeName === "HTML") {
break;
}
Comment on lines +161 to +163
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix, the rest is just renaming things.

At first, I started playing with comparing this against data received from:

const ownerDocumentRequest = this.replayClient.getDocument(this.pauseId).catch(() => null);

but then I realized I could access this more directly.


parentNodeId = parentNode.parentNode;
}

// Store a list of all pseudo-element types found in the matching rules.
Expand Down
Loading