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
storeScrollPos / resetScrollPos conflict with Chrome scroll anchoring #933
Comments
Hm. I expect that the Chrome behavior won't always work (when the node it uses as a reference is redrawn), but I guess it should usually be fine. There's Trying to feature-detect this (with something like I'll look into this more closely later. |
…anchoring FIX: ProseMirror will no longer try to stabilize the scroll position during updates on browsers that support [scroll anchoring](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-anchor), since it'd inadvertently cancel the browser's behavior. Issue ProseMirror/prosemirror#933
Attached patch turns off this behavior on browsers that do overflow anchoring. |
For me this doesn't work in Firefox on Linux and Mac (didnt test on windows): the content still scrolls down if there are edits made above the visible area. Seems like Firefox and Chrome implment |
Weird, I tested Firefox Linux. What kind of edit are you making? |
Just basic insert/remove operations in a collaborative editor. |
Odd. With Firefox 67 Linux, both with a scrollable element and with the document being the scrollable container, scrolling halfway down the document and then repeatedly deleting the first node in the document shows a stable scroll position. |
I only tested it with my own project, not with the minimal example I created for this issue. I'll try to reproduce it there and then get back to you (I'll probably get around to it on friday). |
Sorry I didnt get around to it when I said I would. But I now managed to find the problem. TLDR: It was my own code. More detailed: Im using https://www.npmjs.com/package/resize-detector to track size changes and was doing so on one of the editor's parent elments. In Firefox, there is no native ResizeObserver, so it falls back to adding a hidden element for tracking resize events, which caused the overflow-anchor not to work... Anyways: sorry for the confusion and thanks for the quick fix :) |
Issue details
ProseMirror tries to persist what part of a document is visible, even if above the visible viewport DOM nodes are added/removed. This functionallity is implemented in prosemirror-view in the storeScrollPos/resetScrollPos functions, also if the scrolling happens inside a container element other than the body.
However, Chrome does this automatically by itself since version 56 (see https://www.chromestatus.com/feature/5700102471548928). This leads to the content scrolling with the current storeScrollPos/resetScrollPos implementation.
Workaround is to set
overflow-anchor: none;
on the editor container. However, I think it would be better to take advantage of this functionallity, since the preserve scroll implemention of ProseMirror seems to have minor calculation errors sometimes.Steps to reproduce
To reproduce in Chrome, simply put the editor into a fixed-height container with overflow auto, scroll somewhere to the middle of the document and instert something at the beginning:
https://glitch.com/edit/#!/join/89fb4025-d89a-41b8-9c12-20d3f420f4bd
ProseMirror version
Prosemirror view version 1.9.6
Affected platforms
The text was updated successfully, but these errors were encountered: