Unexpected refresh of a webview

I get an unexpected behavior that my webview refreshes when i double click on it’s tab.
Is it a known issue ?

@slavik-lvovsky do you have an example webview which you notices is refreshed when a tab is double clicked? When a tab is double-clicked the tab is maximized (same goes for editors, and widgets/views).

We discussed this recently (you were not in that meeting Vince). Someone mentioned an option that looks promising, but that we have not yet tried AFAIK:

retainContextWhenHidden?: boolean

Controls if the webview panel’s content (iframe) is kept around even when the panel is no longer visible.

Normally the webview panel’s html context is created when the panel becomes visible and destroyed when it is hidden. Extensions that have complex state or UI can set the retainContextWhenHidden to make VS Code keep the webview context around, even when the webview moves to a background tab. When a webview using retainContextWhenHidden becomes hidden, its scripts and other dynamic content are suspended. When the panel becomes visible again, the context is automatically restored in the exact same state it was in originally. You cannot send messages to a hidden webview, even with retainContextWhenHidden enabled.

retainContextWhenHidden has a high memory overhead and should only be used if your panel’s context cannot be quickly saved and restored.

1 Like

in all my webviews i use this retainContextWhenHidden: true.
It does not help with the refresh. It happens all the time when i double click a webview tab.
May be this will help that my webviews UI is vuejs …

@slavik-lvovsky - Interesting. Can you confirm if using retainContextWhenHidden: true. helps at least avoid a refresh when switching tab to something else and then back to your webview tab?

Double-clicking on the webview tab to maximise/restore it (Toggle Maximized) is not supported in VS Code, as far as I can tell, so I was not able to compare their behaviour vs a Theia app. Depending on your answer to the question above, the refresh might be caused by a momentary loss of focus of the webview tab.

I am able to reproduce by using the webview created by the vscode-extension-contributed “Open Preview” command, to open a MarkDown file’s preview.

When I double-click on the tab of the MarkDown preview, it goes full screen and there is a moment where nothing is displayed during the refresh - the webview probably re-rendered from scratch from what I understand:

This is exactly what I get in my webviews. They are fully refreshed.
retainContextWhenHidden: true helps not to refresh webview when just switching between opened tabs.

Please file a bug report with steps to reproduce.

Opened: https://github.com/eclipse-theia/theia/issues/8251
Thank you.

1 Like