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: scrolling can be incorrect when fast-forwarding #1352

Merged

Conversation

juliecheng
Copy link
Contributor

@juliecheng juliecheng commented Nov 9, 2023

👋 hello! i'm seeing an issue where the scrolling position of the dom can end up being incorrect after skipping when using the virtual dom. here is an example replay to visualize the issue:

https://rrwebdebug.com/play/index.html?url=https%3A%2F%2Fgist.githubusercontent.com%2Fjuliecheng%2F6f264bae8fa3bcfc56b3011d4bf3b737%2Fraw%2F84f6ddc329abb88b6b8d26a76306b4f10a33028a%2Fbroken-scrolling.json&version=2.0.0-alpha.8&virtual-dom=on&play=on

if you let it play regularly, you'll see that about 2 seconds in I scroll down so the number 7 + "click" button is now visible for the remainder of the replay. if you skip all the way back to the beginning of the replay + pause immediately (so that you still see "Test Page"), then skip to some spot in the middle of the replay, the scrolling position is incorrect (it didn't scroll) compared to the regular playback.

if the node we're trying to call applyScroll on has its height affected by the styles of its parent node, and the parent node is missing attributes that prevent the CSS selector rules from matching at the time applyScroll is called, we run into an issue w/ scrolling. the node's clientHeight can equal scrollHeight w/o the parent styles which means scrollTo won't actually do anything. here is an example css:

parent[data-v-12345] { <--- isn't applied yet because it's missing the data attribute at the time applyScroll is called
  position: fixed;
  height: calc(100% - 0px);
}

targetElement[data-v-12345] {
  overflow: auto;
  height: 100%;
}

not sure if there is a more elegant solution in mind for this but my thought process was to run diffProps inside diffBeforeUpdatingChildren so that newly created nodes that are missing attributes will now have them added (and therefore styles applied). then when diffChildren runs and applyScroll is called on one of its child nodes all of the styling and height calculations should be correct

Copy link

changeset-bot bot commented Nov 9, 2023

🦋 Changeset detected

Latest commit: 7a7a0d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
rrdom Patch
rrweb Patch
rrweb-snapshot Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/types Patch
@rrweb/web-extension Patch
rrvideo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eoghanmurray
Copy link
Contributor

Thank you! Do you think it would be possible to extract a minimal test case from the rrdebug data? We have can fast forward scroll events in rrweb/test/replayer.test.ts already, so a new test based on that but with your failing events would be perfect to exemplify the problem and ensure we don't later get a regression.

@juliecheng juliecheng force-pushed the jc-add-props-before-diff-children branch from 540ca8b to 18ae4c2 Compare November 17, 2023 18:36
@juliecheng
Copy link
Contributor Author

Thank you! Do you think it would be possible to extract a minimal test case from the rrdebug data? We have can fast forward scroll events in rrweb/test/replayer.test.ts already, so a new test based on that but with your failing events would be perfect to exemplify the problem and ensure we don't later get a regression.

thanks for taking a look! just added a test case and confirmed it passes w/ my changes (and fails without them) 👍

Copy link
Member

@YunFeng0817 YunFeng0817 left a comment

Choose a reason for hiding this comment

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

@juliecheng Thanks for finding out this bug. This is amazing!
I made one minor change on this pull request, can you please review it?
pendo-io#9

…-children

add changeset and remove duplicate diffProps process
@juliecheng
Copy link
Contributor Author

@YunFeng0817 ready for re-review when you get a chance please 🙏

@YunFeng0817 YunFeng0817 merged commit e607e83 into rrweb-io:master Feb 27, 2024
6 checks passed
jaj1014 pushed a commit to pendo-io/rrweb that referenced this pull request Apr 30, 2024
* fix: scrolling can be incorrect when fast-forwarding

* add test case

* add changeset and remove duplicate diffProps process

---------

Co-authored-by: Yun Feng <[email protected]>
jxiwang pushed a commit to amplitude/rrweb that referenced this pull request Jul 31, 2024
* fix: scrolling can be incorrect when fast-forwarding

* add test case

* add changeset and remove duplicate diffProps process

---------

Co-authored-by: Yun Feng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants