Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit 2068bcd

Browse files
authored
Merge pull request #28 from firefox-devtools/performance
Implement async rendering
2 parents 70e33f0 + 0e12588 commit 2068bcd

File tree

6 files changed

+119
-154
lines changed

6 files changed

+119
-154
lines changed

extension/experiments/inspectedNode/api-client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
return this._invoke("getNodesInSubtree");
4949
},
5050

51-
async getStyle() {
52-
return this._invoke("getStyle");
51+
async getStyle(actorID, skipPseudo) {
52+
return this._invoke("getStyle", [actorID, skipPseudo]);
5353
},
5454

5555
async getStylesInSubtree() {
5656
return this._invoke("getStylesInSubtree");
5757
},
5858

59-
async _invoke(method) {
59+
async _invoke(method, parameters) {
6060
return new Promise(resolve => {
6161
const timestamp = Date.now();
6262

@@ -71,6 +71,7 @@
7171
port.postMessage({
7272
namespace: "browser.experiments.inspectedNode",
7373
method,
74+
parameters,
7475
timestamp,
7576
});
7677
});

extension/experiments/inspectedNode/api-server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ browser.runtime.onConnect.addListener(port => {
1414
port.postMessage({ method: "onChange" });
1515
}
1616

17-
const onMessage = async ({ namespace, method, timestamp }) => {
17+
const onMessage = async ({ namespace, method, parameters = [], timestamp }) => {
1818
if (namespace !== "browser.experiments.inspectedNode") {
1919
return;
2020
}
@@ -25,7 +25,8 @@ browser.runtime.onConnect.addListener(port => {
2525
break;
2626
}
2727
default: {
28-
const result = await browser.experiments.inspectedNode[method](clientId);
28+
const result =
29+
await browser.experiments.inspectedNode[method](clientId, ...parameters);
2930
port.postMessage({ method, timestamp, result });
3031
break;
3132
}

extension/experiments/inspectedNode/api.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,31 @@ this.inspectedNode = class extends ExtensionAPI {
5151
};
5252

5353
const _getSubtreeNodes = async (node) => {
54-
if (!node.hasChildren) {
55-
return [];
56-
}
57-
58-
const nodes = [];
59-
60-
// At first, get the children cache in nodeFront.
61-
let children = await node.treeChildren();
62-
63-
if (children.length === 0) {
64-
// Otherwise, get via the walker.
65-
await node.walkerFront.children(node);
66-
children = await node.treeChildren();
67-
}
68-
69-
// We see element type only
70-
children = children.filter(node => node.nodeType === ELEMENT_NODE);
71-
72-
for (const child of children) {
73-
nodes.push(child);
74-
nodes.push(...(await _getSubtreeNodes(child)));
75-
}
76-
77-
return nodes;
54+
const result = await node.walkerFront.querySelectorAll(node, "*");
55+
return await result.items();
7856
}
7957

8058
const _getAppliedStyle = async (inspector, node, option) => {
8159
const styles =
8260
await inspector.pageStyle.getApplied(node, option);
8361

8462
return styles.map(({ rule }) => {
85-
const { actorID: ruleId } = rule;
8663
let { declarations } = rule;
8764
declarations = declarations.filter(d => !d.commentOffsets);
88-
return declarations.length
89-
? { ruleId, declarations, node: _getNodeInfo(node) }
90-
: null;
91-
}).filter(rule => !!rule);
65+
return declarations.length ? declarations : null;
66+
}).filter(declarations => !!declarations);
9267
};
9368

94-
const _getStyle = async (clientId) => {
69+
const _getStyle = async (clientId, actorID, skipPseudo) => {
9570
await _setupClientIfNeeded(clientId);
9671

9772
const { inspector } = _clients.get(clientId);
9873
if (!inspector.selection.isConnected()) {
9974
return [];
10075
}
10176

102-
const node = inspector.selection.nodeFront;
103-
return _getAppliedStyle(inspector, node, { skipPseudo: true });
77+
const node = await inspector.walker.conn.getFrontByID(actorID);
78+
return _getAppliedStyle(inspector, node, { skipPseudo });
10479
};
10580

10681
const _getStylesInSubtree = async (clientId) => {
@@ -120,6 +95,7 @@ this.inspectedNode = class extends ExtensionAPI {
12095

12196
const _getNodeInfo = node => {
12297
const {
98+
actorID,
12399
id,
124100
className,
125101
attributes,
@@ -129,6 +105,7 @@ this.inspectedNode = class extends ExtensionAPI {
129105
} = node;
130106

131107
return {
108+
actorID,
132109
id,
133110
className: className.trim(),
134111
attributes,
@@ -185,8 +162,8 @@ this.inspectedNode = class extends ExtensionAPI {
185162
return _getNodesInSubtree(clientId);
186163
},
187164

188-
async getStyle(clientId) {
189-
return _getStyle(clientId);
165+
async getStyle(clientId, actorID, skipPseudo) {
166+
return _getStyle(clientId, actorID, skipPseudo);
190167
},
191168

192169
async getStylesInSubtree(clientId) {

extension/experiments/inspectedNode/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
{
3232
"type": "string",
3333
"name": "clientId"
34+
},
35+
{
36+
"type": "string",
37+
"name": "actorID"
38+
},
39+
{
40+
"type": "boolean",
41+
"name": "skipPseudo"
3442
}
3543
],
3644
"async": true

extension/sidebar-pane.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@
165165
display: block;
166166
}
167167

168-
#subtree.processing ul {
169-
display: none;
170-
}
171-
172168
#subtree aside label {
173169
display: flex;
174170
align-items: center;

0 commit comments

Comments
 (0)