Skip to content

Commit

Permalink
Trigger touchActive and mouseDown on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice10 committed Mar 28, 2023
1 parent 7834b85 commit b65163a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-impalas-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

Only apply touch-active styling on flush
26 changes: 20 additions & 6 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class Replayer {

private mousePos: mouseMovePos | null = null;
private touchActive: boolean | null = null;
private lastMouseDownEvent: [Node, Event] | null = null;

// Keep the rootNode of the last hovered element. So when hovering a new element, we can remove the last hovered element's :hover style.
private lastHoveredRootNode: Document | ShadowRoot;
Expand Down Expand Up @@ -299,6 +300,20 @@ export class Replayer {
);
this.mousePos = null;
}

if (this.touchActive === true) {
this.mouse.classList.add('touch-active');
} else if (this.touchActive === false) {
this.mouse.classList.remove('touch-active');
}
this.touchActive = null;

if (this.lastMouseDownEvent) {
const [target, event] = this.lastMouseDownEvent;
target.dispatchEvent(event);
}
this.lastMouseDownEvent = null;

if (this.lastSelectionData) {
this.applySelection(this.lastSelectionData);
this.lastSelectionData = null;
Expand Down Expand Up @@ -614,12 +629,6 @@ export class Replayer {
const castFn = this.getCastFn(event, true);
castFn();
}
if (this.touchActive === true) {
this.mouse.classList.add('touch-active');
} else if (this.touchActive === false) {
this.mouse.classList.remove('touch-active');
}
this.touchActive = null;
};

private getCastFn = (event: eventWithTime, isSync = false) => {
Expand Down Expand Up @@ -1145,6 +1154,11 @@ export class Replayer {
} else if (d.type === MouseInteractions.TouchEnd) {
this.touchActive = false;
}
if (d.type === MouseInteractions.MouseDown) {
this.lastMouseDownEvent = [target, event];
} else if (d.type === MouseInteractions.MouseUp) {
this.lastMouseDownEvent = null;
}
this.mousePos = {
x: d.x,
y: d.y,
Expand Down

0 comments on commit b65163a

Please sign in to comment.