Skip to content

Commit

Permalink
Make sure that all session contexts has unique IDs even if they don't…
Browse files Browse the repository at this point in the history
… have a kernel
  • Loading branch information
Kontinuation committed Jan 17, 2025
1 parent 303cae4 commit 55f929a
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 55f929a

Please sign in to comment.