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

Unable to restore Theia state when webview and several editor tabs are opened #8621

Closed

Conversation

vitaliy-guliy
Copy link
Contributor

What it does

Fixes an error with restoring the editor area when a webview and several editors are opened.

Short video demonstrating a problem is here https://www.youtube.com/watch?v=9ir1hTov350

How to test

Follow 'Steps to reproduce' in the original issue #8620

This PR is also fixes #6877. I haven't investigated sources of GitLens extension, but the bug with webview+preferences is not reproducible anymore.

Review checklist

Reminder for reviewers

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is the right fix: if we don't have a WebviewPanelSerializer, shouldn't we just recreate the webview to it's default state? After all, there are webviews that simply do not have mutable state.
Could you point me to the code that disposes the widget if there's now WebviewPanelSerializer? I didn't find it.

@vitaliy-guliy
Copy link
Contributor Author

I'm not convinced this is the right fix: if we don't have a WebviewPanelSerializer, shouldn't we just recreate the webview to it's default state? After all, there are webviews that simply do not have mutable state.

Theia finds a WebviewPanelSerializer when saving the layout, as the serializer is used to get the webview html content.

If the serializer is not registered for the webview, theia saves only widget ID, factory ID and empty content.

widget.storeState = () => {
if (this.webviewRevivers.has(widget.viewType)) {
return storeState();
}
return {};
};

Then when restoring the state after reload, Theia

@tsmaeder
Copy link
Contributor

The if (oldState.viewType) check could win an obfuscated code contest ;-). This could use a commment.

@vitaliy-guliy
Copy link
Contributor Author

Could somebody check this PR?

@vitaliy-guliy
Copy link
Contributor Author

@akosyakov @vince-fugnitto could you please take a look?

@tsmaeder
Copy link
Contributor

testing....

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I have not viewed the pull-request sooner, I was busy with EclipseCon.
I tested the functionality only at the moment, I see that editors are properly restored with this patch as compared to master.

@tsmaeder
Copy link
Contributor

tsmaeder commented Oct 21, 2020

Hmh...the pressing F5 does not restore the order of the editors: python files always first. Checking master...

@tsmaeder
Copy link
Contributor

Master seems to respect editor order. Need to look at that code again.

@tsmaeder
Copy link
Contributor

Here's what I do:

  1. start the browser example
  2. Open a python file, two json files and another python file
  3. Observe: the editor tabs are in the order they are opened from left to right
  4. Close the "hello" welcome page
  5. Press F5
  6. Observe: the two python files are the first editor tabs from the beginning.
  7. Observe: the "hello" welcome page is then opened as the second editor tab from the left.

@vitaliy-guliy
Copy link
Contributor Author

Here's what I do:

  1. start the browser example
  2. Open a python file, two json files and another python file
  3. Observe: the editor tabs are in the order they are opened from left to right
  4. Close the "hello" welcome page
  5. Press F5
  6. Observe: the two python files are the first editor tabs from the beginning.
  7. Observe: the "hello" welcome page is then opened as the second editor tab from the left.

What devfile did you use to test?

After refreshing the page, the order of opened editors must be restored.
But if the webview is not persisted, it will be opened again the next to active editor tab.

@tsmaeder
Copy link
Contributor

What devfile did you use to test?

No devfile, plain Theia.

After refreshing the page, the order of opened editors must be restored.
But if the webview is not persisted, it will be opened again the next to active editor tab.

That is correct, but the order of editors is not preserved in my case. Maybe we're iterating over property keys instead of an array somewhere?

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
@ericwill ericwill mentioned this pull request Oct 22, 2020
29 tasks
Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
@vitaliy-guliy
Copy link
Contributor Author

@tsmaeder I have just updated and double-checked the PR. The order of opened editors is preserved after refreshing the page.

@tsmaeder
Copy link
Contributor

🤦 I'll have to double-check, then. I'm pretty confident I did not dream it.

@tsmaeder
Copy link
Contributor

I'm still seeing reordering of the open files running the browser example when opening the following directory:

First.zip

  1. Open hello.py, then launch.json, then settings.json, then config.py
  2. Refresh the browser
  3. Files are in order hello.py config.py launch.json settings.json

@vitaliy-guliy
Copy link
Contributor Author

I reproduced the bug with your project. Sometimes (not always) the ordering of files is broken.
It could be because the speed of restoring of editors could be different for different type of files.
In my PR I changed a bit the order of inserting the widgets to the array. Then, the order could be broken if time for opening of the first widget is bigger comparing to the second one. In this case the second file will appear the first.

@tsmaeder
Copy link
Contributor

tsmaeder commented Oct 28, 2020

@vitaliy-guliy of course:

const widget = await this.convertToWidget(descs[i], context);
if (widget) {
  widgets.unshift(widget);
}

compiles to

this.convertToWidget(descs[i], context).then(()=> {
  if (widget) {
    widgets.unshift(widget);
  }
);

@tsmaeder
Copy link
Contributor

I'm glad I'm not crazy ;-)

@vitaliy-guliy
Copy link
Contributor Author

I created a PR #8680 with another approach. In that PR Theia does not store the webview if the serializer is not set.

Copy link
Member

@azatsarynnyy azatsarynnyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it with the provided plug-in. The previously opened files are restored well. But with restoring a WebView I see two problems:

  • the position of the WebView tab is not the same as it was before reloading the entire page
  • the contributed WebView is restored anyway, even if I've already closed it before reloading the Theia page 😄

@vitaliy-guliy
Copy link
Contributor Author

I've tested it with the provided plug-in. The previously opened files are restored well. But with restoring a WebView I see two problems:

  • the position of the WebView tab is not the same as it was before reloading the entire page

It's because the webview is not persisted and the plugin opens it next to active tab.

  • the contributed WebView is restored anyway, even if I've already closed it before reloading the Theia page

The plugin opens a webview always when Theia starts.

@ericwill
Copy link

I created a PR #8680 with another approach. In that PR Theia does not store the webview if the serializer is not set.

Does that mean this PR should be closed?

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

Successfully merging this pull request may close these issues.

Theia fails to load with webview and preferences opened
5 participants