fix: wrappedEmit is not a function (#1034)

Co-authored-by: wangfukang <wangfukang@kuaishou.com>
This commit is contained in:
fukang wang
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 81b39384c8
commit 96ba547e72

View File

@@ -42,6 +42,7 @@ let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
let takeFullSnapshot!: (isCheckout?: boolean) => void; let takeFullSnapshot!: (isCheckout?: boolean) => void;
let canvasManager!: CanvasManager; let canvasManager!: CanvasManager;
let recording = false;
const mirror = createMirror(); const mirror = createMirror();
function record<T = eventWithTime>( function record<T = eventWithTime>(
@@ -535,6 +536,7 @@ function record<T = eventWithTime>(
const init = () => { const init = () => {
takeFullSnapshot(); takeFullSnapshot();
handlers.push(observe(document)); handlers.push(observe(document));
recording = true;
}; };
if ( if (
document.readyState === 'interactive' || document.readyState === 'interactive' ||
@@ -560,9 +562,7 @@ function record<T = eventWithTime>(
} }
return () => { return () => {
handlers.forEach((h) => h()); handlers.forEach((h) => h());
// reset init fns when stopping record recording = false;
(wrappedEmit as unknown) = undefined;
(takeFullSnapshot as unknown) = undefined;
}; };
} catch (error) { } catch (error) {
// TODO: handle internal error // TODO: handle internal error
@@ -571,7 +571,7 @@ function record<T = eventWithTime>(
} }
record.addCustomEvent = <T>(tag: string, payload: T) => { record.addCustomEvent = <T>(tag: string, payload: T) => {
if (!wrappedEmit) { if (!recording) {
throw new Error('please add custom event after start recording'); throw new Error('please add custom event after start recording');
} }
wrappedEmit( wrappedEmit(
@@ -590,7 +590,7 @@ record.freezePage = () => {
}; };
record.takeFullSnapshot = (isCheckout?: boolean) => { record.takeFullSnapshot = (isCheckout?: boolean) => {
if (!takeFullSnapshot) { if (!recording) {
throw new Error('please take full snapshot after start recording'); throw new Error('please take full snapshot after start recording');
} }
takeFullSnapshot(isCheckout); takeFullSnapshot(isCheckout);