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

core(script-treemap-data): do not create nodes with blank names #12569

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions lighthouse-core/audits/script-treemap-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ScriptTreemapDataAudit extends Audit {
// Strip off the shared root.
const sourcePathSegments = source.replace(sourceRoot, '').split(/\/+/);
sourcePathSegments.forEach((sourcePathSegment, i) => {
if (sourcePathSegment.length === 0) return;

const isLeaf = i === sourcePathSegments.length - 1;

let child = node.children && node.children.find(child => child.name === sourcePathSegment);
Expand Down Expand Up @@ -124,6 +126,17 @@ class ScriptTreemapDataAudit extends Audit {
}
collapseAll(sourceRootNode);

// If sourceRootNode.name is falsy (no defined sourceRoot + no collapsed common prefix),
// collapse the sourceRootNode children into the scriptNode.
// Otherwise, we add another node.
if (!sourceRootNode.name) {
return {
...sourceRootNode,
name: src,
children: sourceRootNode.children,
};
}

// Script node should be just the script src.
const scriptNode = {...sourceRootNode};
scriptNode.name = src;
Expand Down
Loading