Skip to content

#27498 restore extension editor webview scroll positions - #85982

Merged
Matt Bierner (mjbvz) merged 13 commits into
microsoft:masterfrom
gjsjohnmurray:fix-27498
Dec 18, 2020
Merged

Matt Bierner (mjbvz) merged 13 commits into
microsoft:masterfrom
gjsjohnmurray:fix-27498

Conversation

@gjsjohnmurray

@gjsjohnmurray John Murray (gjsjohnmurray) commented Dec 2, 2019 •

Copy link
Copy Markdown
Contributor

This draft PR 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 draft PR 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.

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

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.

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

Matt Bierner (@mjbvz) in 98b0296 I have deferred the setInitialScrollPosition call by using a 1000ms setTimeout ...

function hookupOnLoadHandlers(newFrame) {
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.

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

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?

@mjbvz Matt Bierner (mjbvz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

@mjbvz Matt Bierner (mjbvz) Sep 29, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@mjbvz

Copy link
Copy Markdown
Contributor

Sorry John Murray (@gjsjohnmurray). This PR kept falling off my radar.

Is this change in a good state now to check in?

@mjbvz Matt Bierner (mjbvz) added this to the July 2020 milestone Jul 8, 2020
@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

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:

// 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?

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

Matt Bierner (@mjbvz) do you need any more from me to get this progressed?

@JacksonKearl

Copy link
Copy Markdown
Contributor

cc Matt Bierner (@mjbvz) moving this out

@mjbvz
Matt Bierner (mjbvz) merged commit 186792c into microsoft:master Dec 18, 2020
@mjbvz

Copy link
Copy Markdown
Contributor

Thanks John Murray (@gjsjohnmurray)! (and apologies for the long review process)

@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension editor: scroll position is not restored.

4 participants