Closed jcortell68 closed 1 year ago
Hi @jcortell68,
I was debugging this issue and the following seems to be the root cause:
The flow for restoring a web view seems to be as follows (see hosted-plugin.ts)
HostedPluginSupport
there is a method called doLoad
doLoad
method is responsible for calling the restoreWebviews
method at the end of itrestoreWebviews
method further attempts to restore each web view by calling the restoreWebview
methodrestoreWebview
method, no webviewRevivers
are registered yetrestoreWebview
, the registerWebviewReviver
method is called via the rpc protocol to register a webviewReviver
So as you can see webviewRevivers
are being registered after we have attempted to restore the view.
Purposed solution:
Instead of trying to restore the web views in the doLoad
method, we should instead try to restore a web view when its webviewReviver
has been registered and for that I've done the following changes
Revised flow:
preserveWebview
method which is called whenever we're restoring a webview, we'll set a map webviewsToRestore
with the key being webview.viewType
and the value being the webview
itself. We'll also emit an activation event to activate the said web view.registerWebviewReviver
method to register a webviewReviver
and at that time we'll check if the previously set webviewsToRestore
map has an entry for the given viewType
and if it does we'll then call the restoreWebview
method but this time it should work correctly as it would correctly find the appropriate webviewReviver
The way I am testing this is quite janky since I am modifying the package.json in your test repo by adding an entry like:
"@theia/plugin-ext": "C:\\Users\\vatsal\\theia\\packages\\plugin-ext"
If there's a better way to test please do tell
@vatsal-uppal-1997 I've tested your changes and they fix the issue for me as well. Changes look good to me as well.
When it comes to testing, you could build a vsix
(https://code.visualstudio.com/api/working-with-extensions/publishing-extension#usage vsce package
without publish
) from the test repo and simply install it in theia's example browser or electron app (https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#quick-start) run from source.
This way all Theia sources are in sync.
I'll assign the issue to you, if you don't mind
@vatsal-uppal-1997 Thanks for the investigation and fix!
Hi @jfaltermeier,
Thanks for testing my changes and guiding me regarding how to test this issue 😄 !
Consequently, I've raised this PR to fix this issue.
Hope this helps!
Description
A VS Code extension can register a
WebviewPanelSerializer
. Such an object is exercised by VS Code to recreate a webview panel's content in the event that the previous VS Code instance was terminated with the webview open. It appears Theia supports this (the associated API is there), but the serializer isn't exercised.I tried the same thing in VS Code and it works as expected.
Part of this mechanism involves declaring an activation event so that if Theia needs to recreate a webview of type, e.g.,
myextWebviewPanelType
, then your extension will be activated on VS Code launch, such that it can register the serializer (presumably before Theia needs to make use of it).In package.json, I have
and in fact, my extension is being activated on launch because of it. However, the serializer's
deserializeWebviewPanel
method is never called.Steps to Reproduce:
Open Webview
, which the extension contributes. You should see the webview.My Webview Panel
is open, but has no content. Also, looking at stdout, you can see thatconsole.log()
in the serializer code doesn't appear. I.e., it was not called.Additional Information