Skip to content
Closed
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
2 changes: 1 addition & 1 deletion examples/ai-streaming/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AIStreamingApp extends Widget {
this.addChild(this._toolCall);
this.addChild(this._streamingText);

setInterval(() => {
clearInterval(window.__interval); window.__interval = setInterval(() => {
this._streamingText.tick();
}, 50);
Comment on lines +43 to 45

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Give the streaming interval instance ownership and teardown.

window.__interval is shared by all AIStreamingApp instances. Constructing a second instance clears the first instance's timer. The class also does not clear the interval when the widget is unmounted, so the callback can continue calling tick() on a detached widget and retain the instance.

Store the handle in a private field and clear it from cleanup(), as shown by examples/widget-gallery/src/tabs/ai-tab.ts’s cleanup() implementation.

Proposed fix
+    private _streamInterval: ReturnType<typeof setInterval>;
+
     constructor() {
...
-        clearInterval(window.__interval); window.__interval = setInterval(() => {
+        this._streamInterval = setInterval(() => {
             this._streamingText.tick();
         }, 50);
     }
+
+    cleanup(): void {
+        clearInterval(this._streamInterval);
+    }
📝 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
clearInterval(window.__interval); window.__interval = setInterval(() => {
this._streamingText.tick();
}, 50);
private _streamInterval: ReturnType<typeof setInterval>;
constructor() {
this._streamInterval = setInterval(() => {
this._streamingText.tick();
}, 50);
}
cleanup(): void {
clearInterval(this._streamInterval);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/ai-streaming/src/index.tsx` around lines 43 - 45, Update
AIStreamingApp’s streaming timer setup to store the interval handle in a private
instance field instead of the shared window.__interval, so each instance owns
its timer. Extend cleanup() to clear that interval and release the handle,
preventing tick() after unmount and allowing multiple instances to run
independently.

}
Expand Down
2 changes: 1 addition & 1 deletion examples/chat-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function parseBlocks(text: string): Block[] {
}

// ── Handle Paragraphs ────────────────────────
if (line.trim() === '') {
if (line.trim().length === 0) {
blocks.push({
type: 'paragraph',
text: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function promptSelect<T = string>(options: SelectPromptOptions<T>): Promis
return;
}
const n = parseInt(trimmed, 10);
if (!isNaN(n) && n >= 1 && n <= choices.length) {
if (!Number.isNaN(n) && n >= 1 && n <= choices.length) {
rl.close();
resolve(choices[n - 1].value);
return;
Expand Down
Loading