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

Starting a new TTVC measurement will now cancel out the previous measurement, if it is still active #85

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

kierrrrra
Copy link
Collaborator

What is this

While working on tighter integration of TTVC measurements of "soft" navigations, I have ran into an issue. While it is admittedly an edge case it still warrants a fix: when a soft navigation occurs before the measurement has had a chance to complete, the interrupted navigation will not be reported entirely correctly.

The diagram below might help understand the issue:
ttvc-cancellation-on-soft-navigation

In this situation:

  1. Measurement cancellation will be reported much later compared to when it actually occurred, making integration of TTVC into a host application more confusing
  2. Duration of the measurement cancellation will also be incorrect

Along the way, I have also addressed a few edge case scenarios:

  1. I have introduced a NEW_MEASUREMENT cancellation reason, which is slightly distinct from NEW_NAVIGATION. NEW_NAVIGATION might mean a navigation to an entirely different site; While NEW_MEASUREMENT refers to a new measurement on an existing site.
  2. Manual cancellation was not reporting a correct duration, and potentially a wrong navigation type, which will be fixed now

Testing

  • I added a new e2e test case, spa6, to test for this scenario.
  • Alternatively, run yarn:express and hit the http://localhost:3000/test/spa6# test case. Wait for a hard navigation to complete. Click one of the links, and immediately click another link. You will see that a cancellation of the first soft navigation TTVC measurement will occur before the second soft navigation.

*/
export const cancel = (eventType?: string) => calculator?.cancel(eventType);
export const cancel = (e?: Event) => calculator?.cancel(e);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know that this is changing the API, so will be a breaking change.

expect(entries[1].detail.navigationType).toBe('script');

// We expect the interrupted measurement to be ended before the start of the new measurement
expect(errors[0].end).toBeLessThanOrEqual(entries[1].start + FUDGE);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the crux of the fix, really

Copy link
Collaborator

@hongrich hongrich left a comment

Choose a reason for hiding this comment

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

Fantastic work 👏

@kierrrrra kierrrrra merged commit 44255a0 into main Apr 15, 2024
4 checks passed
@kierrrrra kierrrrra deleted the kada/cancellation-on-spa-navigation branch April 15, 2024 12:42
@kierrrrra kierrrrra mentioned this pull request Apr 15, 2024
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