diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 9b0766fddb..a93d1fc67a 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -528,6 +528,12 @@ export class Replayer { } public playSingleEvent(eventIndex: number) { + const handleFinish = () => { + this.service.send('END'); + this.emitter.off(ReplayerEvents.FlushEnd, handleFinish); + }; + this.emitter.on(ReplayerEvents.FlushEnd, handleFinish); + if (this.service.state.matches('paused')) { this.service.send({ type: 'PLAY_SINGLE_EVENT', diff --git a/packages/rrweb/src/replay/machine.ts b/packages/rrweb/src/replay/machine.ts index bd4543583f..74f1e668c7 100644 --- a/packages/rrweb/src/replay/machine.ts +++ b/packages/rrweb/src/replay/machine.ts @@ -150,7 +150,7 @@ export function createPlayerService( actions: ['recordTimeOffset', 'play'], }, PLAY_SINGLE_EVENT: { - target: 'paused', + target: 'playing', actions: ['playSingleEvent'], }, CAST_EVENT: { @@ -210,14 +210,13 @@ export function createPlayerService( const { singleEvent } = event.payload; - const neededEvents2 = discardPriorSnapshotsToEvent( + const neededEvents = discardPriorSnapshotsToEvent( ctx.events, singleEvent, ); - applyEventsSynchronously(neededEvents2); + applyEventsSynchronously(neededEvents); emitter.emit(ReplayerEvents.Flush); - // emitter.emit(ReplayerEvents.Finish); }, play(ctx) {