8000
Skip to content

report: introduce the new report api, add dom.rootEl - #13277

Merged
devtools-bot merged 48 commits into
masterfrom
reportapi-impl
Nov 3, 2021
Merged

report: introduce the new report api, add dom.rootEl#13277
devtools-bot merged 48 commits into
masterfrom
reportapi-impl

Conversation

@paulirish
Copy link
Copy Markdown
Member

following #12772, this PR adds a nice and minimal API for rendering the report. since earlier discussion the report API proposal has even shrank. We no longer need the renderPartials() approach we previously discussed.

In this PR:

  • Add dom.rootEl as the root DOM element of this report. Critical to have this for our PSI-like case of multiple reports in the same document. You'll spot a bunch of changes from _document to rootEl in report-ui-features. All of those cases would otherwise be bugs.
  • Keep legacy reportRenderer.renderReport API, but deprecate it. It will still work, but it emits a console warning.
  • Introduce new renderReport(lhr, opts) API.
    • add omitTopbar and disableAutoDarkModeAndFireworks options.
    • onDetailsItemRendered, onSaveGist and getStandaloneReportHTML are not yet here, but those are next.

Comment thread report/renderer/api.js
*/
export function renderReport(lhr, opts = {}) {
const rootEl = document.createElement('main');
rootEl.classList.add('lh-root', 'lh-vars');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The standalone template HTML already includes these classes in a main tag. WDYT about making rootEl a normal div, and removing the classes from the template files?

Standalone renderer would still look for the main tag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

basically did the same kinda thing. just avoiding a double-main scenario. :)

const topbarDocumentFragment = this._renderReportTopbar(report);

reportFragment.appendChild(topbarDocumentFragment);
if (!this._opts.omitTopbar) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The topbar is removed separately in report.tsx. Can we replace that logic with this new option now?

Comment thread report/renderer/dom.js Outdated
}

/**
* ONLY use if `dom.rootEl` isn't sufficient for your needs. It is preferred for all scoping,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got a little confused on first read

Suggested change
* ONLY use if `dom.rootEl` isn't sufficient for your needs. It is preferred for all scoping,
* ONLY use if `dom.rootEl` isn't sufficient for your needs. `dom.rootEl` is preferred for all scoping,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thx

Comment thread viewer/app/index.html Outdated
<body>

<div class="drop_zone"></div>
<div class="renderer-container"></div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW my suggestion was to keep this as a main tag and have generated report contents as divs. Generating main in renderReport might create nested mains in the flow report.

<noscript>Lighthouse report requires JavaScript. Please enable.</noscript>

<main><!-- report populated here --></main>
<main class="flow-vars lh-root lh-vars"><!-- report populated here --></main>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Todo for me to add these programmatically in the flow report.

<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAEhklEQVR4AWJxL/BhIAesev1U5tcflpncgNrKIsqNIwzC9feMpDUzs70kOczMzMzJJcxwCTMzncPMnOwtzBwzMzPb0vRfeZPp0VhPS5I39V5fdiXV1/VD+9QC7OVn9BsyH1XIoEI1PfmJvLFowVV564+34DFUHudbmfDh4kVXh//7XwE+WjS/YfXZe3yr4j2rqj1AIhSB7hZ8ZtPZu/zw8cK523U4wE1/rvPfWrz4zs0m9ZdC9yUJAlASdBAgocRegfF/f3/h/PuaFsxMdwjAR0vm1+06eMMfIrhLqTWqdH4EumU2SPfMhigJAlRQbZrgrRsl9U+Y2DYDFCz3ILC9kiAiqSrMwbWT0nceEnR+9Kggc2zjOJCASDENkg0a5HfZZgDP81CM3CrQs2Z1+o7DJ6ePr8sK0AOCHv5Jjdt3evyYSaZ351VIStIxPRAUtrBYbxC6w+BZ0ivVSBKkIhJhemSyZpfB00EiPO2VjzYkxhcqXQqCWC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report</title>
<style>body {margin: 0}</style>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add this to the flow template as well, or maybe put in shared styles somehow?

@adamraine adamraine left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm looks like the report is rendering in the flow report

@adamraine adamraine left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, thanks for fixing those!

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.

5 participants

0