Skip to content
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

retainContextWhenHidden not working as expected #107843

Closed
sbatten opened this issue Sep 30, 2020 · 5 comments
Closed

retainContextWhenHidden not working as expected #107843

sbatten opened this issue Sep 30, 2020 · 5 comments
Assignees
Labels
*not-reproducible Issue cannot be reproduced by VS Code Team member as described webview Webview issues

Comments

@sbatten
Copy link
Member

sbatten commented Sep 30, 2020

Testing #105764

Either I am using it wrong or it is not working but I expect if this value is true, the webview just exists and is not recreated when the view is collapsed.

@mjbvz
Copy link
Contributor

mjbvz commented Sep 30, 2020

Try adding a console.log in the script run inside the webview. With retainContextWhenHidden disabled, you should see logging when the webview is first shown and when it is expanded

With retainContextWhenHidden true, you should only see logging when the view is recreated (and not on expand). This would happen: on first load, when the webview is disposed, the webview is hidden using the context menu and then shown again

@mjbvz mjbvz added the webview Webview issues label Sep 30, 2020
@mjbvz
Copy link
Contributor

mjbvz commented Sep 30, 2020

Note that #107842 causes the webview to be disposed more often than it should be, but the main thing to confirm is that simply collapsing and expanding the webview should not destroy the webview when retainContextWhenHidden is set

@sbatten
Copy link
Member Author

sbatten commented Sep 30, 2020

As discussed: turns out I was setting the value in the wrong place because I misread the documentation and the sample does not include an example.

Potential improvement: Include this option in the sample with the value set to false. include a comment explaining that this is the default, not necessary but included for clarifying how and why to change it to true.

@usernamehw
Copy link
Contributor

Can we have a separate option to never dispose webview view? (false by default).

@mjbvz
Copy link
Contributor

mjbvz commented Sep 30, 2020

Closing this since from our discussion it does sound like the setting is behaving as expected.

Regarding documenting this in the sample: On second thought, I don't think we should include this option. We strongly encourage extensions to use VS Code's default webview behavior, which performs better and is suitable for most cases. An advanced extension user can use this setting if they need to, but with all the performance downsides of retainContextWhenHidden I want to avoid making it an easy options that normal extension authors fallback to instead of making their webviews quick to setup and teardown

@mjbvz mjbvz closed this as completed Sep 30, 2020
@mjbvz mjbvz added the *not-reproducible Issue cannot be reproduced by VS Code Team member as described label Sep 30, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*not-reproducible Issue cannot be reproduced by VS Code Team member as described webview Webview issues
Projects
None yet
Development

No branches or pull requests

3 participants