Skip to content
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/components/NotebookPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ReactWidget } from '@jupyterlab/apputils';
import { NotebookPanel } from '@jupyterlab/notebook';
import { HTMLSelect } from '@jupyterlab/ui-components';
import { deepnoteMetadataSchema } from '../types';
import { Widget } from '@lumino/widgets';
import { Message, MessageLoop } from '@lumino/messaging';

export class NotebookPicker extends ReactWidget {
private selected: string | null = null;
Expand Down Expand Up @@ -63,6 +65,13 @@ export class NotebookPicker extends ReactWidget {
this.update();
};

protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
requestAnimationFrame(() => {
MessageLoop.sendMessage(this.parent!, Widget.ResizeMessage.UnknownSize);
});
}
Comment on lines +68 to +73
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against null parent.

this.parent! will throw if no parent exists at attach time. Add a null check.

 protected onAfterAttach(msg: Message): void {
   super.onAfterAttach(msg);
   requestAnimationFrame(() => {
-    MessageLoop.sendMessage(this.parent!, Widget.ResizeMessage.UnknownSize);
+    if (this.parent) {
+      MessageLoop.sendMessage(this.parent, Widget.ResizeMessage.UnknownSize);
+    }
   });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
requestAnimationFrame(() => {
MessageLoop.sendMessage(this.parent!, Widget.ResizeMessage.UnknownSize);
});
}
protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
requestAnimationFrame(() => {
if (this.parent) {
MessageLoop.sendMessage(this.parent, Widget.ResizeMessage.UnknownSize);
}
});
}
🤖 Prompt for AI Agents
In src/components/NotebookPicker.tsx around lines 68 to 73, the code uses a
non-null assertion this.parent! when sending a resize message which will throw
if parent is null; update the method to check that this.parent is non-null
before calling MessageLoop.sendMessage (e.g., if (this.parent) {
MessageLoop.sendMessage(this.parent, Widget.ResizeMessage.UnknownSize); }) and
remove the non-null assertion so the resize is only sent when a parent exists.


render(): JSX.Element {
const deepnoteMetadata = this.panel.context.model.getMetadata('deepnote');

Expand All @@ -81,7 +90,7 @@ export class NotebookPicker extends ReactWidget {
aria-label="Select active notebook"
title="Select active notebook"
style={{
maxWidth: '120px',
width: '120px',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden'
Expand Down
Loading