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

fix: reset fns when when stopping record #962

Merged
merged 1 commit into from
Sep 17, 2022
Merged
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
3 changes: 3 additions & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ function record<T = eventWithTime>(
}
return () => {
handlers.forEach((h) => h());
// reset init fns when stopping record
(wrappedEmit as unknown) = undefined;
(takeFullSnapshot as unknown) = undefined;
Comment on lines +522 to +523
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't reset the fns to their original state, this removes the functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't reset the fns to their original state, this removes the functions

These two fns(wrappedEmit and takeFullSnapshot ) are undefined when record is not invoked

image

In record.addCustomEvent and record.takeFullSnapshot:
Determine whether it is recording by judging whether wrappedEmit or takeFullSnapshot is falsy

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the below case:

import { record } from "rrweb"

// start record
const stopRecord = record({
  emit: xxx,
})

// stopRecord
stopRecord()

// still invoke 
record.addCustomEvent()
record.takeFullSnapshot()

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch @wfk007, thanks for finding this and clarifying!

};
} catch (error) {
// TODO: handle internal error
Expand Down