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

Test: Webview persistence APIs #50696

Closed
1 of 2 tasks
mjbvz opened this issue May 29, 2018 · 2 comments
Closed
1 of 2 tasks

Test: Webview persistence APIs #50696

mjbvz opened this issue May 29, 2018 · 2 comments

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented May 29, 2018

Test for #49022 #48542

Complexity: 3

Summary
A new api for webview serialization has been added. This allows webviews to both save their state between becoming hidden and visible, as well as saving their state when VS Code restarts

Test
Try adding the two types of persistence to the new webview (you can use the cat coding example for this)

Visibility persistence is implemented using a getState and setState method inside the webview itself:

const vscode = acquireVsCodeApi();
const state = vscode.getState();
vscode.setState({ abc: 123 })

Serialization uses WebviewPanelSerializer and registerWebviewPanelSerializer to register a handler in the extension that can revive a webview from its state.

Things to test:

  • Can you implement the two types of persistence?
  • Does the API documentation make sense? (I'll be writing docs for it too but have not finished these yet)
  • Are there cases where the new APIs may not work?
@mjbvz mjbvz added this to the May 2018 milestone May 29, 2018
@mjbvz mjbvz changed the title TS: Webview persistence APIs Test: Webview persistence APIs May 29, 2018
@RMacfarlane RMacfarlane assigned octref, Tyriar and rebornix and unassigned Tyriar May 29, 2018
@rebornix
Copy link
Member

rebornix commented May 29, 2018

I have a react app (which is basically a tree view) running in the webview, tried to save/restore the state of tree expand/collapse state when the webview become visible/invisbile. Below are my attempts and findings

  • It took me a while to figure out how to use setState, I was expecting things @dbaeumer mentioned in Capturing state of a web view when it becomes invisible #48542, get an event for webview visibility change and post a message back to the webview and finally setState in the webview message handler. Turns out once the webview is invisible there is no way to post message to it. So I need to think of a way to store the view state when a bit more eagerly.

  • Then I tried to save React component's state when it's being changed. As I want to store states of all components, I tried to read the state for vscode storage first, apply changes to it and then save.

    const state = vscode.getState()
    vscode.setState({}, state, {
        componentId: expand
    })
    

    unluckily, the state I get is always undefined. It seems the state is only saved when the webview becomes invisible.

  • I didn't get WebviewPanelSerializer working yet. I'm not sure when should I register the seriablizer and when the callbacks will be invoked, especially when my extension is only activated when some commands are triggerred.

    • Discussed with @mjbvz offline, the only thing we need to do here is better documentation. The API works as expected.

@rebornix
Copy link
Member

Removed my name from the task but will revisit this item tomorrow when more fixes come in.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants