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

Notebook canvas overflows out of the file tab and into the sidebar. #129120

Closed
Anshul7sp1 opened this issue Jul 21, 2021 · 19 comments
Closed

Notebook canvas overflows out of the file tab and into the sidebar. #129120

Anshul7sp1 opened this issue Jul 21, 2021 · 19 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders layout General VS Code workbench layout issues notebook-layout verified Verification succeeded
Milestone

Comments

@Anshul7sp1
Copy link

I changed my sidebar location while having a jupyter notebook open.
It resulted in the notebook canvas overflowing onto the sidebar.
Gets fixed once I switch to some other file then come back.
This glitch appears only when there is a switch of side bar position from left to right.

Environment data

  • VS Code version: 1.58
  • Jupyter Extension version (available under the Extensions sidebar): v2021.8.1046824664
  • Python Extension version (available under the Extensions sidebar): v2021.7.1050252941
  • OS (Windows | Mac | Linux distro) and version: Windows 11
  • Python and/or Anaconda version: Python 3.8.2 - 64bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): NA
  • Jupyter server running: Local

Actual behaviour

Initial state:
image

Just after I changed the layout (Move Side Bar Right)
image

Expected behaviour

After switching to a different file and coming back.

image

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Create a new empty jupyter notebook
  2. Try changing sidebar position. (only left to right switch gives this glitch, the other way is fine)

Logs

Not sure if this is relevant for this issue

@rchiodo rchiodo transferred this issue from microsoft/vscode-jupyter Jul 21, 2021
@vscodebot
Copy link

vscodebot bot commented Jul 21, 2021

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@abdlrhmanshehatamoussa
Copy link

Hi Guys,

I'm ready to help,

If any one could give a little push on where exactly can find the relevant code and any other recommendations, I'm ready to gooo.

Best of luck !

@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Jul 28, 2021
@rebornix rebornix added this to the July 2021 milestone Jul 28, 2021
@rebornix
Copy link
Member

This is a really good catch.

@rebornix
Copy link
Member

I can reproduce this issue with both notebook and custom editor. After toggling the position of the sidebar, a layout request is triggered after the sidebar moves to the right side, but no event when the activity bar moves to the right side. Thus there is a gap on the left side (whose width is the same as the activity bar)

@rebornix
Copy link
Member

Apparently editor.layout is invoked before setting left/top on the editor container DOM node thus the position tracking in notebook and custom editor is measuring position incorrectly. Adding a setTimeout(() => editor.layout()) can fix the problem but can also be too costly.

@rebornix
Copy link
Member

rebornix commented Jul 28, 2021

A proper fix would be we pass the left/top layout info from the grid view to the editor group view all the way down.

@bpasero
Copy link
Member

bpasero commented Aug 2, 2021

This seems like a general grid layout issue to me unrelated to editors specifically. Thus assigning @joaomoreno and @sbatten (who are on vacation though).

@bpasero bpasero added the layout General VS Code workbench layout issues label Aug 2, 2021
@mjbvz
Copy link
Contributor

mjbvz commented Aug 2, 2021

Both notebooks and normal webviews suffer from this problem. I believe the root cause is the same although the two have different implementations

After debugging, I believe that the root cause is that we get a call to layout before the activity bar has moved to the other side (or before the editor has shifted fully to replace the space the activity bar occupied). Here's a screenshot of the dom state when this happens. I was shifting the activity bar from left to right:

Screen Shot 2021-08-02 at 12 22 36 PM

The important bit is that left has been calculated to be 47px when it should be zero. Here's where the value is calculated:

if (this._webviewTransparentCover) {

Here you can also see how we are calling layout before main the editor dom node has shifted to the left to replace the activity bar:

Screen Shot 2021-08-02 at 12 29 44 PM (3)

I believe this could be fixed by calling layout again once the activity bar (or editor locations) have been fully updated. Ideally we would also avoid calling layout until we have the final locations as well. While debugging I noticed that toggling the sidebar already seems to trigger 3 calls to layout today

@bpasero bpasero removed their assignment Aug 3, 2021
@bpasero
Copy link
Member

bpasero commented Aug 3, 2021

I think the sidebar location change code is here:

private setSideBarPosition(position: Position): void {
const activityBar = this.getPart(Parts.ACTIVITYBAR_PART);
const sideBar = this.getPart(Parts.SIDEBAR_PART);
const wasHidden = this.state.sideBar.hidden;
const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
const oldPositionValue = (this.state.sideBar.position === Position.LEFT) ? 'left' : 'right';
this.state.sideBar.position = position;
// Adjust CSS
const activityBarContainer = assertIsDefined(activityBar.getContainer());
const sideBarContainer = assertIsDefined(sideBar.getContainer());
activityBarContainer.classList.remove(oldPositionValue);
sideBarContainer.classList.remove(oldPositionValue);
activityBarContainer.classList.add(newPositionValue);
sideBarContainer.classList.add(newPositionValue);
// Update Styles
activityBar.updateStyles();
sideBar.updateStyles();
// Layout
if (!wasHidden) {
this.state.sideBar.width = this.workbenchGrid.getViewSize(this.sideBarPartView).width;
}
if (position === Position.LEFT) {
this.workbenchGrid.moveViewTo(this.activityBarPartView, [2, 0]);
this.workbenchGrid.moveViewTo(this.sideBarPartView, [2, 1]);
} else {
this.workbenchGrid.moveViewTo(this.sideBarPartView, [2, 4]);
this.workbenchGrid.moveViewTo(this.activityBarPartView, [2, 4]);
}
this.layout();
}

I resort to Steven for a fix who authored this.

@sbatten
Copy link
Member

sbatten commented Aug 5, 2021

After digging into this, I believe 0449a18 is the reason we hit this issue. @joaomoreno

Essentially, if a grid gets the same dimensions and position info it will not call layout again on the contained view (in this case the webview or notebook). At the workbench level, after moving the activity bar (the 2nd action in moving the sidebar, we can see that the editor part layout is correctly called.) however, the editor part has several nested grids, one of which does not use top/left info. Since the size and position are the same on the 2nd call, the cache check is hit and we bail before the webview or notebook can get the correct offset info.

It seems this shouldn't work on the first call either but moving the sidebar triggers a size and position change on the top level grid and the activity bar does not.

@sbatten sbatten modified the milestones: August 2021, September 2021 Aug 25, 2021
@joaomoreno
Copy link
Member

After digging into this, I believe 0449a18 is the reason we hit this issue. @joaomoreno

Does reverting this commit fix this issue?

@sbatten
Copy link
Member

sbatten commented Aug 31, 2021

@joaomoreno yes reverting fixes the issue. I did not, however, because I was not sure of the repercussions.

@mjbvz mjbvz modified the milestones: September 2021, October 2021 Sep 27, 2021
@sbatten sbatten removed their assignment Oct 15, 2021
@sbatten
Copy link
Member

sbatten commented Oct 15, 2021

@joaomoreno there was a lot of discussion in the issue that led to the caching you introduced with 0449a18 . Unless you say so I will not revert that change for this fix since a simple reload resolves this issue.

The crux of the issue with caching however is that the notebook layout code does not treat 2 layout calls with the same dimensions as the same since they can be in a different position overall and that impacts the layout. You could say this is a bug with notebook layout, but I am not sure where we draw that line.

@joaomoreno
Copy link
Member

0449a18 was pushed as a way to force all views to think about layout, since that's such a core part of performance. I don't think we should revert it and should rather fix the notebook layout.

The crux of the issue with caching however is that the notebook layout code does not treat 2 layout calls with the same dimensions as the same since they can be in a different position overall and that impacts the layout

Grid view layout calls do not only take dimension into account but positioning as well. Even 0449a18 shows it clearly. So the reason above can't be the problem, right?

@joaomoreno
Copy link
Member

however, the editor part has several nested grids, one of which does not use top/left info

Hmmm just read this again. I see. Let me see what I can do about that.

@joaomoreno
Copy link
Member

I've connected both grids such that views on the inner grid get absolute offsets, in respect to the outter grid.

@joaomoreno
Copy link
Member

@mjbvz @rebornix This also means that this getBoundingClientRect call can just be avoided altogether... there's no reason for the positioning information not to be reaching all the way down there, now that it's propagated from both grids throughout layout calls. This would be great, since getBoundingClientRect is expensive.

The hard part of doing the above is making sure positional data gets passed around the composite world, ideally Composite.layout would look like this instead:

	abstract layout(width: number, height: number, top: number, left: number): void;

So maybe @sbatten would give you this. 😉

Handing it over to you all. ❤️

@mjbvz
Copy link
Contributor

mjbvz commented Oct 25, 2021

Thanks @joaomoreno! I confirmed the issue is fixed now for notebooks and webviews

@mjbvz mjbvz added the verified Verification succeeded label Oct 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders layout General VS Code workbench layout issues notebook-layout verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

10 participants