Skip to content
Merged
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
7 changes: 3 additions & 4 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import type {
incrementalData,
Handler,
Emitter,
metaEvent,
mutationData,
scrollData,
inputData,
Expand Down Expand Up @@ -403,7 +402,7 @@ export class Replayer {
(e) => e.type === EventType.FullSnapshot,
);
if (firstMeta) {
const { width, height } = firstMeta.data as metaEvent['data'];
const { width, height } = firstMeta.data ;
setTimeout(() => {
this.emitter.emit(ReplayerEvents.Resize, {
width,
Expand Down Expand Up @@ -2019,7 +2018,7 @@ export class Replayer {
const svp = styleValues[s] as styleValueWithPriority;
targetEl.style.setProperty(s, svp[0], svp[1]);
} else {
const svs = styleValues[s] as string;
const svs = styleValues[s] ;
targetEl.style.setProperty(s, svs);
}
}
Expand Down Expand Up @@ -2252,7 +2251,7 @@ export class Replayer {
const adoptStyleSheets = (targetHost: Node, styleIds: number[]) => {
const stylesToAdopt = styleIds
.map((styleId) => this.styleMirror.getStyle(styleId))
.filter((style) => style !== null) as CSSStyleSheet[];
.filter((style) => style !== null);
if (hasShadowRoot(targetHost))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(targetHost as HTMLElement).shadowRoot!.adoptedStyleSheets =
Expand Down
40 changes: 21 additions & 19 deletions packages/rrweb/src/replay/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,31 @@ export function createPlayerService(
}),
/* Highlight Code Start */
replaceEvents: assign((ctx, machineEvent) => {
if (machineEvent.type !== 'REPLACE_EVENTS') return ctx;

const { events: curEvents, timer, baselineTime } = ctx;
if (machineEvent.type === 'REPLACE_EVENTS') {
const { events: newEvents } = machineEvent.payload;
curEvents.length = 0;
const actions: actionWithDelay[] = [];
for (const event of newEvents) {
addDelay(event, baselineTime);
curEvents.push(event);
if (event.timestamp >= timer.timeOffset + baselineTime) {
const castFn = getCastFn(event, false);
actions.push({
doAction: () => {
castFn();
},
delay: event.delay!,
});
}
}
const { events: newEvents } = machineEvent.payload;

if (newEvents.length === 0) return ctx;

curEvents.length = 0;
const actions: actionWithDelay[] = [];
const timeThreshold = timer.timeOffset + baselineTime;

if (timer.isActive()) {
timer.replaceActions(actions);
for (const event of newEvents) {
addDelay(event, baselineTime);
curEvents.push(event);
if (event.timestamp >= timeThreshold) {
actions.push({
doAction: getCastFn(event, false),
delay: event.delay!,
});
}
}

if (timer.isActive()) {
timer.replaceActions(actions);
}
return { ...ctx, events: curEvents };
}),
/* Highlight Code End */
Expand Down
8 changes: 7 additions & 1 deletion packages/rrweb/src/replay/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ export class Timer {
}

public replaceActions(actions: actionWithDelay[]) {
const rafWasActive = this.raf === true;

this.actions.length = 0;
this.actions.splice(0, 0, ...actions);
this.actions = [...actions];

if (rafWasActive) {
this.raf = requestAnimationFrame(this.rafCheck.bind(this));
}
}
/* End Highlight Code */

Expand Down
Loading