Skip to content

Notebook renderer: state persistence #95361

@rebornix

Description

@rebornix

Issue Type: Feature Request

When building a regular webview extenison or a custom editor, extension authors can follow the existing guidance https://code.visualstudio.com/api/extension-guides/webview#persistence for intermediate state persistence. Extensions will use the vscodeAPI to communicate with the extension and also get/set its intermediate state for recovery. The API is as below

const vscode = acquireVsCodeApi();

// Check if we have an old state to restore from
const previousState = vscode.getState();
...

setInterval(() => {
  vscode.setState({ count });
}, 100);

acquireVsCodeAPI can only be run once, which ensures that it's not being used unexpectedly. However in Notebook world, there are multiple layers who want to access this API

  • Our core logic. It uses this API to send out scroll and sizeChange events.
  • Renderers. We allow multiple renderers to be loaded in the same output webview.

To allow renderers to communite with its coresponding extension, we relaxed it a bit to allow acquireVSCodeAPI to be run multiple times. However it's a bad idea as renderers now don't know how to save/restore states correctly, as vscode.setState can be run by any code.

One solution is creating vscodeAPI object for every indidual player

const vscode = acquireVsCodeApi('_vscodeCore');
const ipyWidgets = acquireVsCodeApi('python.ipywidget');

vscode.getState();
...
ipyWidgets.getState();

acquireVsCodeApi with the same id can only be invoked once. This way each renderer can have its own communication channel with its extension and also its own state restoration.

Particularly for ipywidgets, it should always setState before it sends states to the kernel side and read state when it's being restored.

cc @kieferrm @mjbvz @connor4312

VS Code version: Code - Insiders 1.45.0-insider (44c5185, 2020-04-10T19:43:46.226Z)
OS version: Darwin x64 19.2.0

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions