-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
report(flow): embedded lighthouse report #12989
Conversation
flow-report/src/wrappers/report.tsx
Outdated
useLayoutEffect(() => { | ||
if (!currentLhr) return; | ||
|
||
dom.clearComponentCache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, style nodes are not added every time the LHR changes
lighthouse/report/renderer/dom.js
Lines 95 to 102 in 94f5bdf
let component = this._componentCache.get(componentName); | |
if (component) { | |
const cloned = /** @type {DocumentFragment} */ (component.cloneNode(true)); | |
// Prevent duplicate styles in the DOM. After a template has been stamped | |
// for the first time, remove the clone's styles so they're not re-added. | |
this.findAll('style', cloned).forEach(style => style.remove()); | |
return cloned; | |
} |
/** | ||
* The jest environment "jsdom" does not work when preact is combined with the report renderer. | ||
*/ | ||
export function setupJsDom() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default jsdom test environment was not cooperating with the report renderer. These changes basically setup our own environment for testing with JSDOM.
The only problem I've encountered is that findBy*
queries don't work, but we can just replace those with equivalent getBy*
ones.
flow-report/src/util.ts
Outdated
@@ -48,6 +48,21 @@ export function getScreenshot(reportResult: LH.ReportResult) { | |||
return fullPageScreenshot || null; | |||
} | |||
|
|||
export function convertChildAnchors(element: HTMLElement, index: number) { | |||
const links = element.querySelectorAll('a') as NodeListOf<HTMLAnchorElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flow-report.d.ts
can pull in the better typed querySelector and get this without the cast. report
does it here:
lighthouse/report/types/augment-dom.d.ts
Lines 12 to 13 in 38f6364
// Import to augment querySelector/querySelectorAll with stricter type checking. | |
import '../../types/query-selector'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made the type errors visible in VSCode, but the type cast is still necessary. Either way I think it's a helpful change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, I wonder if it's a js vs ts difference. Something to look into at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! coming together nicely 👍
export function useCurrentLhr(): {value: LH.Result, index: number}|null { | ||
const flowResult = useFlowResult(); | ||
const [indexString, setIndexString] = useState(getHashParam('index')); | ||
export function useHashParam(param: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Renders a lighthouse report in the flow report. I intentionally left
ReportUIFeatures
out for this PR.