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

Using activationStart if available #73

Merged
merged 12 commits into from
May 20, 2023
Merged

Using activationStart if available #73

merged 12 commits into from
May 20, 2023

Conversation

Jonathan1600
Copy link
Collaborator

No description provided.

Copy link
Member

@ajhyndman ajhyndman left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this @Jonathan1600!

I think I have a couple ideas where to go next. Left a comment below.

Copy link
Member

Choose a reason for hiding this comment

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

Reminder: We're using yarn instead of npm in this package. Please remove this file!

src/index.ts Outdated
@@ -12,6 +12,9 @@ export type {Metric, MetricSubscriber} from './visuallyCompleteCalculator';

let calculator: VisuallyCompleteCalculator;

// @ts-ignore
const startTime = performance?.getEntriesByType?.('navigation')[0]?.activationStart > 0 ? performance?.getEntriesByType?.('navigation')[0]?.activationStart : performance.now()
Copy link
Member

Choose a reason for hiding this comment

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

Okay, I think I spotted a couple issues here:

  1. This line of code is declared at the top level so it will be evaluated immediately when the module is loaded, instead of when start() is actually invoked. That means the value of performance.now() is probably not what you expect.

  2. You are intercepting the public start() method. In that case, the user is telling us that a navigation is starting right now, and we always will want to override any default start time values. I would suggest trying to intercept the default value of the start() method of the calculator class instead:

https://github.com/dropbox/ttvc/blob/main/src/visuallyCompleteCalculator.ts#L98

Comment on lines 107 to 109
if (activationStart > 0) {
start = activationStart;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this should probably check if activationStart > start. The reason being, if someone does an SPA navigation on a page that was prerendered, start should still be the manually supplied value, correct?

I think it would be nice if we can add one or two puppeteer test cases for this. We can pair on that sometime if you like.

jonathan calderon added 2 commits May 19, 2023 15:52
Copy link
Member

@ajhyndman ajhyndman left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@Jonathan1600 Jonathan1600 merged commit c8d0b5b into main May 20, 2023
@Jonathan1600 Jonathan1600 deleted the use-activationStart branch May 20, 2023 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants