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): default config #12494

Merged
merged 11 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
3 changes: 3 additions & 0 deletions lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ Object {
Object {
"path": "full-page-screenshot",
},
Object {
"path": "script-treemap-data",
},
Object {
"path": "manual/pwa-cross-browser",
},
Expand Down
9 changes: 4 additions & 5 deletions lighthouse-core/audits/script-treemap-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,12 @@ class ScriptTreemapDataAudit extends Audit {
* @return {Promise<LH.Audit.Product>}
*/
static async audit(artifacts, context) {
const treemapData = await ScriptTreemapDataAudit.makeNodes(artifacts, context);
const nodes = await ScriptTreemapDataAudit.makeNodes(artifacts, context);

// TODO: when out of experimental should make a new detail type.
/** @type {LH.Audit.Details.DebugData} */
/** @type {LH.Audit.Details.TreemapData} */
const details = {
type: 'debugdata',
treemapData,
type: 'treemap-data',
nodes,
};

return {
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const defaultConfig = {
'valid-source-maps',
'preload-lcp-image',
'full-page-screenshot',
'script-treemap-data',
'manual/pwa-cross-browser',
'manual/pwa-page-transitions',
'manual/pwa-each-page-has-url',
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/config/experimental-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const config = {
audits: [
'autocomplete',
'large-javascript-libraries',
'script-treemap-data',
'csp-xss',
],
categories: {
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DetailsRenderer {
case 'screenshot':
case 'debugdata':
case 'full-page-screenshot':
case 'treemap-data':
return null;

default: {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/report/html/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ class ReportUIFeatures {
* @param {LH.Result} json
*/
static openTreemap(json) {
const treemapDebugData = /** @type {LH.Audit.Details.DebugData} */ (
const treemapData = /** @type {LH.Audit.Details.TreemapData} */ (
json.audits['script-treemap-data'].details);
if (!treemapDebugData) {
if (!treemapData) {
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('no script treemap data found');
}

Expand Down
54 changes: 54 additions & 0 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,42 @@
}
}
},
"script-treemap-data": {
"id": "script-treemap-data",
"title": "Script Treemap Data",
"description": "Used for treemap app",
"score": null,
"scoreDisplayMode": "informative",
"details": {
"type": "treemap-data",
"nodes": [
{
"name": "http://localhost:10200/dobetterweb/dbw_tester.html",
"resourceBytes": 5806
},
{
"name": "http://localhost:10200/dobetterweb/dbw_tester.js",
"resourceBytes": 48
},
{
"name": "http://localhost:10200/dobetterweb/empty_module.js?delay=500",
"resourceBytes": 60
},
{
"name": "http://localhost:10200/dobetterweb/fcp-delayer.js?delay=5000",
"resourceBytes": 60
},
{
"name": "http://localhost:10200/zone.js",
"resourceBytes": 30
},
{
"name": "http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js",
"resourceBytes": 63
}
]
}
},
"pwa-cross-browser": {
"id": "pwa-cross-browser",
"title": "Site works cross-browser",
Expand Down Expand Up @@ -6396,6 +6432,24 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:script-treemap-data",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:JSBundles",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:ModuleDuplication",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:pwa-cross-browser",
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-treemap/app/debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -12077,8 +12077,8 @@
"score": null,
"scoreDisplayMode": "informative",
"details": {
"type": "debugdata",
"treemapData": [
"type": "treemap-data",
"nodes": [
{
"name": "https://www.coursehero.com/",
"resourceBytes": 69863
Expand Down
9 changes: 3 additions & 6 deletions lighthouse-treemap/app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ class TreemapViewer {
* @param {HTMLElement} el
*/
constructor(options, el) {
const treemapDebugData = /** @type {LH.Audit.Details.DebugData} */ (
const scriptTreemapData = /** @type {LH.Audit.Details.TreemapData} */ (
options.lhr.audits['script-treemap-data'].details);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
if (!treemapDebugData || !treemapDebugData.treemapData) {
if (!scriptTreemapData || scriptTreemapData.type !== 'treemap-data') {
Copy link
Member

Choose a reason for hiding this comment

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

good call, and this check means the LH.Audit.Details.TreemapData cast above can be dropped too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That caused some weird error... Can you try it and see?

Copy link
Member

@brendankenny brendankenny May 18, 2021

Choose a reason for hiding this comment

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

That caused some weird error

ah, perfect, because finally I can see it :)

Looks like this was from my idea in #12483 (comment)

In theory LH.RawIcu<LH.FormattedIcu<Audit.Details>> should resolve to an identity transformation and leave Audit.Details alone. However when I suggested we add dom?: HTMLElement to LH.Audit.Details.TreemapData, that ends up unleashing the zalgo and really putting the test to LH.RawIcu<LH.FormattedIcu<>> actually being an identity transformation...and it breaks. If you add "noErrorTruncation": true to our tsconfig you end up with a very fun error message. I would post it here under <details> but it's 1.7MiB long, repeated a second time in the tsc output for good measure.

A selection from our Audit.Details monstrosity:

...
spellcheck: boolean;
title: string | IcuMessage;
translate: boolean;
click: IcuMessage | {};
readonly classList: { [x: number]: string | IcuMessage; readonly length: number; value: string | IcuMessage; toString: IcuMessage | {}; add: IcuMessage | {}; contains: IcuMessage | {}; item: IcuMessage | {}; remove: IcuMessage | {}; replace: IcuMessage | {}; supports: IcuMessage | {}; toggle: IcuMessage | {}; forEach: IcuMessage | {}; entries: IcuMessage | {}; keys: IcuMessage | {}; values: IcuMessage | {}; };
className: string | IcuMessage;
readonly clientHeight: number
strokeMiterlimit: string | IcuMessage;
onpointerup: IcuMessage | {} | null;
onsecuritypolicyviolation: IcuMessage | {} | null;
...

(in fairness, RawIcu/FormattedIcu were only ever meant to run on JSON-ish data, not anything with methods, among other things :)

I think the best solution is just to keep dom out of the audit details type (since it can never be in the LHR anyways) and have TreemapUtil.walk() return LH.Treemap.Node & {dom?: HTMLElement} so that's still typed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

wonder why we both had trouble seeing this locally initially... maybe the type calculation was too massive

throw new Error('missing script-treemap-data');
}

/** @type {LH.Treemap.Node[]} */
const scriptNodes = treemapDebugData.treemapData;

/** @type {{[group: string]: LH.Treemap.Node[]}} */
this.depthOneNodesByGroup = {
scripts: scriptNodes,
scripts: scriptTreemapData.nodes,
};

/**
Expand Down
6 changes: 6 additions & 0 deletions types/audit-details.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare global {
export type Details =
Details.CriticalRequestChain |
Details.DebugData |
Details.TreemapData |
Details.Filmstrip |
Details.List |
Details.Opportunity |
Expand Down Expand Up @@ -97,6 +98,11 @@ declare global {
[p: string]: any;
}

export interface TreemapData {
type: 'treemap-data';
nodes: LH.Treemap.Node[];
}

/** String enum of possible types of values found within table items. */
type ItemValueType = 'bytes' | 'code' | 'link' | 'ms' | 'multi' | 'node' | 'source-location' | 'numeric' | 'text' | 'thumbnail' | 'timespanMs' | 'url';

Expand Down