-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix issue with scrolling not working #881
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 issue with scrolling not working #881
Conversation
… document was scrolling was on `window.pageYOffset`, so we hadn't been able to replay scrolling
bc39380 to
c2700f7
Compare
Yuyz0112
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, we can merge this after the CI passed
YunFeng0817
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI failed just because of some TS errors. I fixed these errors in the comments and wish these can help you.
| document?.body.scrollTop || | ||
| 0, | ||
| }, | ||
| initialOffset: getWindowScroll(window), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| initialOffset: getWindowScroll(window), | |
| initialOffset: getWindowScroll(window.document), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Mark, thanks for this review! What is the idea behind switching to document rather than window? I'm happy with either, just curious.
We could probably change it to getDocumentScroll too; I'm just wondering about the semantics of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.defaultView is nullable but window.document always exists.
If the parameter is a window and the window is null, the function can't retrieve a document object from it (win.document = null.document). The document and window can both be null. This is the reason those TS errors occurred.
I think renaming with getDocumentScroll is a good idea.
| const id = mirror.getId(target as Node); | ||
| if (target === doc) { | ||
| const scrollEl = (doc.scrollingElement || doc.documentElement)!; | ||
| const scrollLeftTop = getWindowScroll(doc.defaultView); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const scrollLeftTop = getWindowScroll(doc.defaultView); | |
| const scrollLeftTop = getWindowScroll(doc); |
| export function getWindowScroll(win): number { | ||
| const doc = win.document; | ||
| return { | ||
| left: | ||
| doc.scrollingElement ? doc.scrollingElement.scrollLeft | ||
| : win.pageXOffset !== undefined | ||
| ? win.pageXOffset | ||
| : doc?.documentElement.scrollLeft || | ||
| doc?.body?.parentElement?.scrollLeft || | ||
| doc?.body.scrollLeft || | ||
| 0, | ||
| top: | ||
| doc.scrollingElement ? doc.scrollingElement.scrollTop | ||
| : win.pageYOffset !== undefined | ||
| ? win.pageYOffset | ||
| : doc?.documentElement.scrollTop || | ||
| doc?.body?.parentElement?.scrollTop || | ||
| doc?.body.scrollTop || | ||
| 0, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export function getWindowScroll(win): number { | |
| const doc = win.document; | |
| return { | |
| left: | |
| doc.scrollingElement ? doc.scrollingElement.scrollLeft | |
| : win.pageXOffset !== undefined | |
| ? win.pageXOffset | |
| : doc?.documentElement.scrollLeft || | |
| doc?.body?.parentElement?.scrollLeft || | |
| doc?.body.scrollLeft || | |
| 0, | |
| top: | |
| doc.scrollingElement ? doc.scrollingElement.scrollTop | |
| : win.pageYOffset !== undefined | |
| ? win.pageYOffset | |
| : doc?.documentElement.scrollTop || | |
| doc?.body?.parentElement?.scrollTop || | |
| doc?.body.scrollTop || | |
| 0, | |
| } | |
| } | |
| export function getWindowScroll(doc: Document) { | |
| const win = doc.defaultView; | |
| return { | |
| left: doc.scrollingElement | |
| ? doc.scrollingElement.scrollLeft | |
| : win?.pageXOffset !== undefined | |
| ? win.pageXOffset | |
| : doc.documentElement.scrollLeft || | |
| doc.body?.parentElement?.scrollLeft || | |
| doc.body.scrollLeft || | |
| 0, | |
| top: doc.scrollingElement | |
| ? doc.scrollingElement.scrollTop | |
| : win?.pageYOffset !== undefined | |
| ? win.pageYOffset | |
| : doc.documentElement.scrollTop || | |
| doc.body?.parentElement?.scrollTop || | |
| doc.body.scrollTop || | |
| 0, | |
| }; | |
| } |
|
Close this because it is a duplicate of #1054 |
Fix issue where only indication I could see in any attribute that the document was scrolling was on
window.pageYOffset, so we hadn't been able to replay scrollingWebsite was https://www.malibal.com/boutique/pc/configurePrd.asp?idproduct=2061
I've no idea what conditions make this the case.