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

WebView state unexpectedly persists across sessions without a WebviewPanelSerializer #236494

Open
DanTup opened this issue Dec 18, 2024 · 0 comments
Assignees

Comments

@DanTup
Copy link
Contributor

DanTup commented Dec 18, 2024

In the docs at https://code.visualstudio.com/api/references/vscode-api#WebviewPanelSerializer<T>, it says:

There are two types of webview persistence:

  • Persistence within a session.
  • Persistence across sessions (across restarts of the editor).

A WebviewPanelSerializer is only required for the second case: persisting a webview across sessions.

The suggestion is that without a WebviewPanelSerializer, state is not persisted across sessions.

However, that's not what I'm seeing. I don't have a WebviewPanelSerializer but my state is persisting across restarts. I added the following to the top of my webview script:

const vscode = acquireVsCodeApi();
const originalState = vscode.getState();
const originalFrameUrl = originalState?.frameUrl;

console.log(\`State log: \${originalState.log?.join("\\n")}\`);
vscode.setState({
	...(originalState ?? {}),
	log: [...(originalState.log ?? []), \`Webview state added at \${new Date()}\`]
});

Then I loaded the webview, ran "Reload Webviews" a few times, then shut down VS Code. Then when I re-opened VS Code and opened my webview, I saw the following:

Image

This is not what I'd expect - I would've expected any state from previous launches of VS Code to be gone.

As an aside, things that aren't clear to me from the limited docs:

  • is the intention that state is lost in VS Code restart, or extension host restart? What about "Reload Window"?
  • is state shared across all webviews, or scoped by an id?
  • does setState always replace the entire object, or is there a way to add just new fields (I ask because if the state is shared amongst all webviews, that could result in them overwriting each others state)

Does this issue occur when all extensions are disabled?: Yes

Version: 1.96.0 (user setup)
Commit: 138f619
Date: 2024-12-11T02:29:09.626Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.26100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants