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: solve the smooth scrolling scene, the y value obtained is the data 100ms ago #1439

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
13 changes: 11 additions & 2 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ export function throttle<T>(
previous = now;
func.apply(context, args);
} else if (!timeout && options.trailing !== false) {
const argumentsList = args.map((arg: T)=> {
return {
...arg,
target: arg.target
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this argument transformation something specific to MouseEvent/TouchEvent/DragEvent ?

I think this needs a bit more explanation; the T type here is supposed to be generic, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still wondering why we need to do the transformation?
is it that an explicit reference to the target needs to be saved before the timeout?
I would have thought that args being in a closure should handle saving the reference?

timeout = setTimeout(() => {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
func.apply(context, args);
if (timeout) {
clearTimeout(timeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see why you need to clear the timeout here as it is a 'one-shot' timeout.
clearing it would make sense if it was setInterval, but it seems to me that it's already been called and won't be called again?
Is there some concurrency or similar here that is possible?

timeout = null;
}
func.apply(context, argumentsList);
}, remaining);
}
};
Expand Down
Loading