Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ sentryTest('captures multiple multi clicks', async ({ getLocalTestUrl, page, for
await page.locator('#mutationButtonImmediately').click({ clickCount: 4 });
await forceFlushReplay();

// Ensure we waited at least 1s, which is the threshold to create a new ui.click breadcrumb
await new Promise(resolve => setTimeout(resolve, 1001));
// The browser's 1s breadcrumb debounce timer must have fired before the next click creates a new ui.click
// breadcrumb, so leave some slack for timer delays on slow CI machines.
await new Promise(resolve => setTimeout(resolve, 1500));

await page.locator('#mutationButtonImmediately').click({ clickCount: 2 });
await forceFlushReplay();
Expand Down
8 changes: 4 additions & 4 deletions packages/replay-internal/src/coreHandlers/handleClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export class ClickDetector implements ReplayClickDetector {
const now = nowInSeconds();

this._clicks.forEach(click => {
if (!click.mutationAfter && this._lastMutation) {
if (click.mutationAfter === undefined && this._lastMutation) {
click.mutationAfter = click.timestamp <= this._lastMutation ? this._lastMutation - click.timestamp : undefined;
}
if (!click.scrollAfter && this._lastScroll) {
if (click.scrollAfter === undefined && this._lastScroll) {
Comment on lines +186 to +189

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: slightly more size-efficient:

Suggested change
if (click.mutationAfter === undefined && this._lastMutation) {
click.mutationAfter = click.timestamp <= this._lastMutation ? this._lastMutation - click.timestamp : undefined;
}
if (!click.scrollAfter && this._lastScroll) {
if (click.scrollAfter === undefined && this._lastScroll) {
if (click.mutationAfter == null && this._lastMutation) {
click.mutationAfter = click.timestamp <= this._lastMutation ? this._lastMutation - click.timestamp : undefined;
}
if (click.scrollAfter == null && this._lastScroll) {

click.scrollAfter = click.timestamp <= this._lastScroll ? this._lastScroll - click.timestamp : undefined;
}

Expand Down Expand Up @@ -215,8 +215,8 @@ export class ClickDetector implements ReplayClickDetector {
/** Generate matching breadcrumb(s) for the click. */
private _generateBreadcrumbs(click: Click): void {
const replay = this._replay;
const hadScroll = click.scrollAfter && click.scrollAfter <= this._scrollTimeout;
const hadMutation = click.mutationAfter && click.mutationAfter <= this._threshold;
const hadScroll = click.scrollAfter !== undefined && click.scrollAfter <= this._scrollTimeout;
const hadMutation = click.mutationAfter !== undefined && click.mutationAfter <= this._threshold;
Comment on lines +218 to +219

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const hadScroll = click.scrollAfter !== undefined && click.scrollAfter <= this._scrollTimeout;
const hadMutation = click.mutationAfter !== undefined && click.mutationAfter <= this._threshold;
const hadScroll = click.scrollAfter != null && click.scrollAfter <= this._scrollTimeout;
const hadMutation = click.mutationAfter != null && click.mutationAfter <= this._threshold;


const isSlowClick = !hadScroll && !hadMutation;
const { clickCount, clickBreadcrumb } = click;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,23 @@ describe('Unit | coreHandlers | handleClick', () => {
expect(mockAddBreadcrumbEvent).toHaveBeenCalledTimes(0);
});

test('it does not consider clicks with mutation in the same millisecond as slow click', async () => {
const breadcrumb: Breadcrumb = {
timestamp: BASE_TIMESTAMP / 1000,
data: {
nodeId: 1,
},
};
const node = document.createElement('button');
detector.handleClick(breadcrumb, node);

detector.registerMutation(BASE_TIMESTAMP);

vi.advanceTimersByTime(3_500);

expect(mockAddBreadcrumbEvent).toHaveBeenCalledTimes(0);
});

test('it considers clicks with mutation after threshold as slow click', async () => {
const breadcrumb: Breadcrumb = {
timestamp: BASE_TIMESTAMP / 1000,
Expand Down Expand Up @@ -453,6 +470,23 @@ describe('Unit | coreHandlers | handleClick', () => {
expect(mockAddBreadcrumbEvent).toHaveBeenCalledTimes(0);
});

test('it does not consider clicks with scroll in the same millisecond as slow click', async () => {
const breadcrumb: Breadcrumb = {
timestamp: BASE_TIMESTAMP / 1000,
data: {
nodeId: 1,
},
};
const node = document.createElement('button');
detector.handleClick(breadcrumb, node);

detector.registerScroll(BASE_TIMESTAMP);

vi.advanceTimersByTime(3_500);

expect(mockAddBreadcrumbEvent).toHaveBeenCalledTimes(0);
});

test('it considers clicks with scroll after threshold as slow click', async () => {
const breadcrumb: Breadcrumb = {
timestamp: BASE_TIMESTAMP / 1000,
Expand Down
Loading