-
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
core(tracehouse): allow missing FCP #9174
Changes from 2 commits
b4bdbb0
f1b007c
f631271
01e1ceb
d7395ae
fc6c18c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
* 4. Return all those items in one handy bundle. | ||
*/ | ||
|
||
/** @typedef {Omit<LH.Artifacts.TraceTimes, 'firstContentfulPaint'> & {firstContentfulPaint?: number}} TraceTimesWithoutFCP */ | ||
/** @typedef {Omit<LH.Artifacts.TraceOfTab, 'firstContentfulPaintEvt'|'timings'|'timestamps'> & {timings: TraceTimesWithoutFCP, timestamps: TraceTimesWithoutFCP, firstContentfulPaintEvt?: LH.Artifacts.TraceOfTab['firstContentfulPaintEvt']}} TraceOfTabWithoutFCP */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these types seem kind of terrible for downstream users, but I guess we can iterate on it in the future :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh, yeah there will be lots of interesting problems to solve when we expose these types :) |
||
|
||
const log = require('lighthouse-logger'); | ||
|
||
const ACCEPTABLE_NAVIGATION_URL_REGEX = /^(chrome|https?):/; | ||
|
@@ -351,9 +354,11 @@ class TraceProcessor { | |
* Finds key trace events, identifies main process/thread, and returns timings of trace events | ||
* in milliseconds since navigation start in addition to the standard microsecond monotonic timestamps. | ||
* @param {LH.Trace} trace | ||
* @return {LH.Artifacts.TraceOfTab} | ||
* @param {{throwOnNoFCP?: boolean}} options | ||
* @return {TraceOfTabWithoutFCP} | ||
*/ | ||
static computeTraceOfTab(trace) { | ||
static computeTraceOfTab(trace, options = {}) { | ||
const {throwOnNoFCP = false} = options; | ||
// Parse the trace for our key events and sort them by timestamp. Note: sort | ||
// *must* be stable to keep events correctly nested. | ||
const keyEvents = this._filteredStableSort(trace.traceEvents, e => { | ||
|
@@ -380,7 +385,7 @@ class TraceProcessor { | |
const firstContentfulPaint = frameEvents.find( | ||
e => e.name === 'firstContentfulPaint' && e.ts > navigationStart.ts | ||
); | ||
if (!firstContentfulPaint) throw this.createNoFirstContentfulPaintError(); | ||
if (!firstContentfulPaint && throwOnNoFCP) throw this.createNoFirstContentfulPaintError(); | ||
|
||
// fMP will follow at/after the FP | ||
let firstMeaningfulPaint = frameEvents.find( | ||
|
@@ -424,27 +429,26 @@ class TraceProcessor { | |
|
||
/** @param {{ts: number}=} event */ | ||
const getTimestamp = (event) => event && event.ts; | ||
/** @type {LH.Artifacts.TraceTimes} */ | ||
/** @type {TraceTimesWithoutFCP} */ | ||
const timestamps = { | ||
navigationStart: navigationStart.ts, | ||
firstPaint: getTimestamp(firstPaint), | ||
firstContentfulPaint: firstContentfulPaint.ts, | ||
firstContentfulPaint: getTimestamp(firstContentfulPaint), | ||
firstMeaningfulPaint: getTimestamp(firstMeaningfulPaint), | ||
traceEnd: fakeEndOfTraceEvt.ts, | ||
load: getTimestamp(load), | ||
domContentLoaded: getTimestamp(domContentLoaded), | ||
}; | ||
|
||
|
||
/** @param {number} ts */ | ||
const getTiming = (ts) => (ts - navigationStart.ts) / 1000; | ||
/** @param {number=} ts */ | ||
const maybeGetTiming = (ts) => ts === undefined ? undefined : getTiming(ts); | ||
/** @type {LH.Artifacts.TraceTimes} */ | ||
/** @type {TraceTimesWithoutFCP} */ | ||
const timings = { | ||
navigationStart: 0, | ||
firstPaint: maybeGetTiming(timestamps.firstPaint), | ||
firstContentfulPaint: getTiming(timestamps.firstContentfulPaint), | ||
firstContentfulPaint: maybeGetTiming(timestamps.firstContentfulPaint), | ||
firstMeaningfulPaint: maybeGetTiming(timestamps.firstMeaningfulPaint), | ||
traceEnd: getTiming(timestamps.traceEnd), | ||
load: maybeGetTiming(timestamps.load), | ||
|
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.
I really don't like this, but I was blanking on a way to do this without casting and/or manually reconstructing the entire object.
any ideas @brendankenny ?
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.
what if we didn't throw in
trace-processor.js
at all and only throwNO_FCP
out here if it's not on the return value?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.
doesn't that involve manually reconstructing every object that has fcp?
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.
yeah, I can't think of a way around it, tsc won't track the validations on all three existence checks into the return value :/
It would allow simplifying
trace-processor.js
(no argument, no fcp check in there, etc), though, and it would keep the fcp checks and cast in the same place in this file.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.
yeah, ended up not being so bad I guess. done!