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

clients(viewer): add support for flow reports #13260

Merged
merged 23 commits into from
Nov 24, 2021
Merged

clients(viewer): add support for flow reports #13260

merged 23 commits into from
Nov 24, 2021

Conversation

adamraine
Copy link
Member

@adamraine adamraine commented Oct 25, 2021

This is not a huge priority for v9 or CDS, but we should land soon so people can easily share flow reports via gist and such.

Quick gist example:
https://lighthouse-git-flow-viewer-googlechrome.vercel.app/gh-pages/viewer/?gist=a2b3f815f1a0f4a0cf69e5b6f50326be

#11313

@google-cla google-cla bot added the cla: yes label Oct 25, 2021
package.json Outdated Show resolved Hide resolved
@connorjclark connorjclark self-requested a review November 1, 2021 21:42
@connorjclark connorjclark self-assigned this Nov 1, 2021
@@ -43,7 +43,7 @@ <h1 class="viewer-placeholder__heading">Lighthouse Report Viewer</h1>

<input id="hidden-file-input" type="file" hidden accept="application/json">

<script src="src/bundled.js"></script>
Copy link
Member Author

Choose a reason for hiding this comment

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

Just spent the better part of an afternoon/evening on this. bundled.js is created as an ESM but we weren't loading it with type="module":

const {output} = await bundle.generate({format: 'esm'});

It wasn't a problem before because bundle.js didn't use any static import/export statements. That changed when we added the flow renderer to the bundle.

The flow renderer imports shated/localization/format.js, which is also used in the dynamically imported i18n-module.js. So now format.js is used in the initially loaded code and the dynamically loaded i18n bundle.

This creates a new main-xxxx.js bundle that is imported in bundle.js and the i18n bundle. At this point the browser gets mad because because bundle.js is using a static import even though the script tag didn't have type="module".

Is there a reason type="module" was not added originally? If so, we might get around this by loading the flow assets dynamically.

Copy link
Collaborator

Choose a reason for hiding this comment

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

background: #10148 (comment)

tldr: adding type=module should be fine

my main concern previously was that concating multiple esm bundles would not work, and so I thought best to not mark the script element as a module so we did not accidentally rely on that. however on second thought I do think concat'ing multiple es module bundles (which we don't do now...) would be fine because imports are simply hoisted. 2 months ago I hadn't realized that, thinking they would error.

nice to know that rollup with extract these out into a separate file and load it. maybe we should add a link preload element for it though? concerned about the delayed loading here. Is there a way to enumerate all the static imports from the main bundle and emit link elements for it inside build-gh-pages-app.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a way to enumerate all the static imports from the main bundle and emit link elements for it inside build-gh-pages-app.js?

I think so looks like each output chunk has a convenient isDynamicEntry flag.

@@ -16,7 +16,7 @@
<link rel="stylesheet" href="styles/bundled.css">
<link rel="canonical" href="https://googlechrome.github.io/lighthouse/viewer/">
</head>
<body class="lh-vars">
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need this? lh-vars is added by to the root element by the report renderer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Removal is fine.

_renderFlowResult(json, root) {
renderFlowReport(json, root);
// Install as global for easier debugging.
window.__LIGHTHOUSE_FLOW_JSON__ = json;
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 same global is used in the standalone report. Should we just reuse __LIGHTHOUSE_JSON__ in the viewer? Otherwise the console could be printing a mix of __LIGHTHOUSE_JSON__ and __LIGHTHOUSE_FLOW_JSON__.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Keeping them separated is my preference

@adamraine adamraine changed the title viewer: add support for flow reports clients(viewer): add support for flow reports Nov 22, 2021
@adamraine adamraine marked this pull request as ready for review November 22, 2021 21:14
@adamraine adamraine requested a review from a team as a code owner November 22, 2021 21:14
Co-authored-by: Connor Clark <cjamcl@google.com>
build/gh-pages-app.js Outdated Show resolved Hide resolved
@connorjclark
Copy link
Collaborator

Excellent work! 🎉 🌮

@adamraine adamraine merged commit d1bd86a into master Nov 24, 2021
@adamraine adamraine deleted the flow-viewer branch November 24, 2021 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants