Repository navigation
#27498 restore extension editor webview scroll positions - #85982
Conversation
|
Matt Bierner (@mjbvz) in 98b0296 I have deferred the setInitialScrollPosition call by using a 1000ms setTimeout. That figure was the result of trial and error testing with the Details tab of the Debugger for Chrome extension (scroll to a position, switch to the Contributions tab, then back to Details and check it scrolls to the old position). But this is clearly a hack, and I wish I could work out a 100% reliable way to call this code after the entire iframe contents have loaded and laid out. |
seems to explain why I need to delay the setInitialScrollPosition. If I'm understanding that code correctly, it will wait a maximum of 200ms before calling onLoad. This would explain why the previously-noted scroll position is sometimes re-established before the entire document has been rendered. The consequence is, the user sees the document scrolled somewhere, but not to the correct place. |
|
Matt Bierner (@mjbvz) I have just updated this branch so it's ready to be merged. Any chance of you looking at doing that for this iteration? |
Matt Bierner (mjbvz)
left a comment
There was a problem hiding this comment.
Thanks for taking a look! Just have a few comments and questions that I'd like addressed before we merge this in
|
|
||
| // Delay this in the hope that all of the iframe content will have loaded by the time we set | ||
| // the desired initial scroll position. But how can we be sure how long is long enough? | ||
| setTimeout(() => { |
There was a problem hiding this comment.
I don't think we should change this to fix this issue. This code is run for all webviews changing it may break other webviews
Can you tell me more about why was this part of the change is needed?
There was a problem hiding this comment.
I take your point about this change having effects beyond this issue, but I found that the onLoad in which I made this change is getting called even before the whole of the iframe content has loaded. I commented on this earlier in this PR, e.g. #85982 (comment) and #85982 (comment)
There was a problem hiding this comment.
This is by-design. We don't want to block the entire webview if it happens to load a slow-loading resource inside of it
What happens if you remove this part of the change?
There was a problem hiding this comment.
As I recall, without this part of the change the restore of scroll position is unreliable. You get scrolled somewhere, but not necessarily back to exactly the position you were at. If an extension's README.md includes some large screenshots for example. For resetting the former scroll position accurately it seems to me to be necessary for the webview to wait until the resources have loaded. Or at least all of the resources that occupy space above the desired scroll position.
There was a problem hiding this comment.
Again, doing this for all webviews seems like it will cause other problems. It's also a poor experience to have the scroll position suddenly jump when all the images are loaded, so maybe there's a better compromise here
There was a problem hiding this comment.
I'm running out of ideas. My understanding of the webviews code is that the mechanism to (optionally) restore the previous scroll position when reviving(?) a webview tries to set it to the same percentage (initData.initialScrollProgress) of the entire document contents as the former scroll position was at. Assuming that at the time the old scroll position was noted all the image resources had been fully loaded, then unless the same is true at the time we reinstate the scroll position for the revived document there's a chance we won't put the user back to where they remember being when they switched away.
So I'm going to remove my main.js change, leaving an imperfect fix for the original issue. But the imperfection will probably only show up in extension READMEs that pull in big images.
|
Sorry John Murray (@gjsjohnmurray). This PR kept falling off my radar. Is this change in a good state now to check in? |
Matt Bierner (@mjbvz) if you are satisfied with my explanation of the main.js change you queried here then yes, please merge it. But as indicated in the comment I added in the code there, it feels a bit of a hack: |
|
Matt Bierner (@mjbvz) do you need any more from me to get this progressed? |
|
cc Matt Bierner (@mjbvz) moving this out |
|
Thanks John Murray (@gjsjohnmurray)! (and apologies for the long review process) |
This
draftPR tries to fix #27498.Until now if an extension's README is being viewed and you scroll part way through it, then switch to another editor (e.g. to change settings), upon return to the extension editor the README gets scrolled back to the beginning.
This happens because the content of the extension editor is reloaded each time you switch back to it.
This
draftPR tracks the vertical scroll position of the two webviews corresponding to the Details and Changelog action bar items and instructs those webviews to scroll to the last-noted position when reloading.However it is not yet working reliably. For instance it seems to handle the README (aka Details) of my georgejames.vscode-serenji extension correctly, retaining the scroll position as I switch away to the Contributions subtab and back to the Details one. But in similar testing on that extension's Changelog subtab the scroll position is incorrectly restored. And when testing on the msjsdiag.debugger-for-chrome extension neither Details nor Changelog reposition correctly.I am submitting this PR in the hope someone else can help work out the flaw in my approach.UPDATE - it now uses a 1-second timer to defer its scroll position adjustment, giving the webview contents time to load completely.