Skip to content
Open
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions packages/ui/src/NotificationCenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,38 @@ describe('NotificationCenter rendering and lifecycle', () => {
expect(renderCenter(center)).not.toContain('+ After');
});

it('destroy() cleans up store subscription and ignores later store updates', () => {
vi.spyOn(caps, 'unicode', 'get').mockReturnValue(false);
const center = new NotificationCenter({ width: 24 });

store.push('Before', 'info');
expect(renderCenter(center)).toContain('i Before');

center.destroy();
expect(renderCenter(center)).not.toContain('i Before');

store.push('After', 'success');
expect(renderCenter(center)).not.toContain('+ After');
});

it('destroy() is safe to call multiple times', () => {
const center = new NotificationCenter({ width: 24 });
center.destroy();
center.destroy();
// No error thrown
});

it('destroy() stops store callbacks from firing on the widget', () => {
const center = new NotificationCenter({ width: 24 });
const markDirtySpy = vi.spyOn(center, 'markDirty');

center.destroy();
markDirtySpy.mockClear();

store.push('After destroy', 'info');
expect(markDirtySpy).not.toHaveBeenCalled();
});

it('renders safely for zero-sized screens, empty messages, many notifications, and long messages', () => {
vi.spyOn(caps, 'unicode', 'get').mockReturnValue(false);
const center = new NotificationCenter({ width: 80, maxVisible: 100 });
Expand Down
17 changes: 14 additions & 3 deletions packages/ui/src/NotificationCenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,23 @@ export class NotificationCenter extends Widget {
}

override unmount(): void {
this._unsub?.();
this._unsub = undefined;
this._current = [];
this._cleanup();
super.unmount();
}

override destroy(): void {
this._cleanup();
super.destroy();
}

private _cleanup(): void {
if (this._unsub) {
this._unsub();
this._unsub = undefined;
}
this._current = [];
}

protected override _renderSelf(screen: Screen): void {
if (this._maxVisible <= 0) return;

Expand Down
Loading