Skip to content

Conversation

@brichet
Copy link
Collaborator

@brichet brichet commented Oct 17, 2025

Adds the layout restorer, to restore the state of the side/down panels.
It includes the current widgets opened in each panel, and the size of the panels.

record-2025-10-17_20.16.35.webm

Fixes #6990

User facing change

  • save and restore the layout, only for the Notebook view, since it is the only one with side and bottom panels
  • use only one workspace (unlike Jupyterlab), to avoid confusion. This means that changing the layout in one Notebook will affect the layout of other Notebook if they are reloaded. This workspace file is save in the jupyterlab workspace directory (.jupyter/lab/workspaces) and is named nb-default.

Code changes

  • add the RestoreLayout and SaveLayout function to the shell, which uses some dedicated function to "dehydrate" and "rehydrate" the shell
  • adds 2 plugins:
    • '@jupyter-notebook/application-extension:layout', which handle the shell layout restoration
    • '@jupyter-notebook/apputils-extension:state', which was previously activated from jupyterlab. Providing our own IStateDB allow to avoid some side effect, that the tab title update (which does not work correctly in Notebook, see Add the layout restorer #7747 (comment))

@github-actions
Copy link
Contributor

Binder 👈 Launch a Binder on branch brichet/notebook/restorer

@brichet
Copy link
Collaborator Author

brichet commented Oct 21, 2025

EDIT this error has been fixed

There is a conflict on the title of the browser tab with this PR.

BEFORE THE PR

record-2025-10-21_11.29.54.webm

AFTER THE PR

record-2025-10-21_11.30.28.webm

The tab title is not updated correctly anymore, probably because of https://github.com/jupyterlab/jupyterlab/blob/21f9c73298d7a450dba9927d404c87aae3011f7a/packages/apputils-extension/src/index.ts#L462-L469.
The code above wasn't called before this PR because there was no window resolver. It is required in this PR to allow saving the layout.

Maybe we should provide the IStateDB token in Notebook too.

@brichet
Copy link
Collaborator Author

brichet commented Oct 21, 2025

Maybe we should provide the IStateDB token in Notebook too.

Added in c1b056e

@brichet brichet marked this pull request as ready for review October 21, 2025 13:28
@jtpio jtpio added this to the 7.5.0 milestone Oct 22, 2025
@jtpio jtpio self-requested a review October 23, 2025 11:49
Copy link
Member

@jtpio jtpio left a comment

Choose a reason for hiding this comment

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

Many thanks @brichet for working on this!

Just did a first pass on the diff without testing locally for now, and overall the changes look good 👍

Left a couple of small comments before checking it locally.

/**
* The default layout restorer provider.
*/
const layoutRestorer: JupyterFrontEndPlugin<ILayoutRestorer | null> = {
Copy link
Member

Choose a reason for hiding this comment

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

Since the left and right panels can also be opened on other pages, maybe this plugin should always provide a LayoutRestorer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I though only the Notebook has side panel, but the tree view also have one indeed. And the header is also expandable for all the view.
To avoid confusion, we'll probably need a workspace file for each view (tree, notebook, console, terminal, file), because each view has its own panels.

Currently the workspace filename is set to nb-default in the state plugin, but we can probably have a dedicated one according to the URL, or the main widget in the shell.

Copy link
Member

Choose a reason for hiding this comment

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

Right, we could look into that separately, and only support the notebook page for now.

},
});

commands.addCommand(CommandIDs.resetOnLoad, {
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this command should be exposed somewhere in the UI? Like in JupyterLab under the Workspaces menu.

Users would then have a way to reset the UI to the defaults and clean things up.

It could be part of the command palette or the menu, or both.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, sounds good. It could be in the file menu, like in lab.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually we should probably create another command (reset) to expose it to the UI. This one checks the URL to find a reset in the query parameters.

@brichet brichet marked this pull request as draft October 24, 2025 14:38
@brichet
Copy link
Collaborator Author

brichet commented Oct 24, 2025

I converted it to draft to explore layout restoration on other views than Notebook, and workspace reset in the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JN 7.0. → Remembering layout of View panels upon saving and reopening a notebook

2 participants