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

Make sure that all session contexts has unique IDs even if they don't have a kernel #3971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion python/jupyterlab_widgets/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function* chain<T>(
}
}

const NO_KERNEL_SESSION_CONTEXT_IDS = new WeakMap<ISessionContext, string>();

/**
* Get the kernel id of current notebook or console panel, this value
* is used as key for `Private.widgetManagerProperty` to store the widget
Expand All @@ -150,7 +152,15 @@ async function getWidgetManagerOwner(
sessionContext: ISessionContext
): Promise<Private.IWidgetManagerOwner> {
await sessionContext.ready;
return sessionContext.session!.kernel!.id;
let id = sessionContext.session?.kernel?.id;
if (id === undefined) {
id = NO_KERNEL_SESSION_CONTEXT_IDS.get(sessionContext);
if (id === undefined) {
id = 'no-kernel-' + base.uuid();
NO_KERNEL_SESSION_CONTEXT_IDS.set(sessionContext, id);
}
}
return id;
}

/**
Expand Down
Loading