Skip to content

Debugger: Preserve variables panel contents when switching editor focus#17830

Merged
krassowski merged 3 commits into
jupyterlab:mainfrom
arjxn-py:debugger-variables
Sep 18, 2025
Merged

Debugger: Preserve variables panel contents when switching editor focus#17830
krassowski merged 3 commits into
jupyterlab:mainfrom
arjxn-py:debugger-variables

Conversation

@arjxn-py

Copy link
Copy Markdown
Member

References

Potential fix for #17829

Code changes

Currently, when switching focus between editors, the debugger’s _clearModel() method clears both the callstack and variables scopes:

private _clearModel(): void {
this._model.callstack.frames = [];
this._model.variables.scopes = [];
}

This causes the Variables panel to be emptied whenever focus changes, even if a debugging session is still active. In contrast, the Breakpoints panel correctly persists its state across focus changes.

This PR modifies _clearModel() to only clear the callstack frames, allowing the Variables panel to preserve the last known state until updated by the active session.

User-facing changes

Screen.Recording.2025-08-29.at.15.13.15.mp4

Backwards-incompatible changes

@jupyterlab-probot

Copy link
Copy Markdown

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@@ -709,7 +709,6 @@ export class DebuggerService implements IDebugger, IDisposable {
*/
private _clearModel(): void {
this._model.callstack.frames = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we do the same for stack frames?

If this is the proper fix, then why is _clearModel there and in which other case is it useful?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Shouldn't we do the same for stack frames?

I am not sure about stack frames but I tried removing that as well as while I tested it I didn't notice anything broken.

If this is the proper fix, then why is _clearModel there and in which other case is it useful?

_clearModel is used in several places in the same file (service.ts):

  1. In the session setter, when event.event === 'continued' line 117

  2. When DebuggerService Continues the execution of the current thread line 219

  3. When retrieving frames to get the latest state of variables line 263

  4. When the DebuggerService is started line 463

It seems useful to me but maybe @krassowski or @jtpio could give more insight. (sorry for the ping)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems that callstack panel isn't cleared when switching focus on notebooks:

Screencast.From.2025-09-02.13-03-16.mp4

Is this code this._model.callstack.frames = []; even called? It should right, so why is the callstack panel not being empty?

@krassowski

Copy link
Copy Markdown
Member

What happens if I click on a file in Sources panel, then set a breakpoint there and then switch between that file and the notebook?

@krassowski krassowski added the bug label Aug 29, 2025
@arjxn-py

Copy link
Copy Markdown
Member Author

What happens if I click on a file in Sources panel, then set a breakpoint there and then switch between that file and the notebook?

Hi, I tried doing this (behaviour looks normal to me):

Screen.Recording.2025-08-29.at.18.45.04.mp4

@krassowski

Copy link
Copy Markdown
Member

Apologies, I meant "Kernel Sources" like this:

image

I am not even sure if it currently works the way it should, just highlighting that sometimes the files can be open from debugger itself and it feels like they maybe should not clear these panels?

@arjxn-py

Copy link
Copy Markdown
Member Author

Thanks for more context @krassowski, I don't know if it works the way we expect it to but here it is -

Screen.Recording.2025-08-29.at.19.43.49.mp4

@arjxn-py

arjxn-py commented Sep 1, 2025

Copy link
Copy Markdown
Member Author

Hi @krassowski, I'm wondering if the visual regression test failure is actually related to the change because when i inspect the test assets it doesn't look like they are related - would be glad to know what you think. Thanks

@krassowski

Copy link
Copy Markdown
Member

No, the mermaid failures are known and tracked in #17820

@martinRenou martinRenou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That looks good to me! Thanks!

@krassowski krassowski merged commit 32bd836 into jupyterlab:main Sep 18, 2025
86 of 87 checks passed
@krassowski krassowski added this to the 4.5.0 milestone Sep 18, 2025
@github-actions github-actions Bot added the status:resolved-locked Closed inactive issues are locked after a while. Please open a new issue for related discussion. label Mar 18, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug pkg:debugger status:resolved-locked Closed inactive issues are locked after a while. Please open a new issue for related discussion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants