Skip to content

Commit c49513f

Browse files
committed
fix(playground): print tokenized URL, guard loadIndex with requestId + select check, disable select during load
1 parent 8fa0c37 commit c49513f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

packages/moss-cli/src/moss_cli/commands/playground.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,18 @@ def playground_command(
270270

271271
console.print()
272272
console.print(" [bold]Moss Playground[/bold]")
273-
console.print(f" [dim]Server:[/dim] [cyan]{url}[/cyan]")
273+
console.print(f" [dim]Server:[/dim] [cyan]{frag_url}[/cyan]")
274274
console.print(f" [dim]Project:[/dim] {pid[:8]}...")
275275
console.print(" [dim]Stop:[/dim] Ctrl+C")
276276
console.print()
277277

278+
opened = False
278279
if not no_open:
279-
webbrowser.open(frag_url)
280+
opened = webbrowser.open(frag_url)
281+
if not opened:
282+
console.print(f" [yellow]Open this URL in your browser:[/yellow]")
283+
console.print(f" [cyan]{frag_url}[/cyan]")
284+
console.print()
280285

281286
try:
282287
server.serve_forever()

packages/moss-cli/src/moss_cli/playground/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ <h1>Moss <span>Playground</span></h1>
227227
const name = select.value;
228228
if (!name) return;
229229

230-
++requestId;
230+
const loadReqId = ++requestId;
231231
if (searchTimeout) clearTimeout(searchTimeout);
232+
select.disabled = true;
232233

233234
loadBtn.disabled = true;
234235
loadBtn.innerHTML = '<span class="spinner">&#9696;</span> Loading...';
@@ -246,6 +247,7 @@ <h1>Moss <span>Playground</span></h1>
246247
const err = await res.json();
247248
throw new Error(err.error || 'Failed to load index');
248249
}
250+
if (loadReqId !== requestId || select.value !== name) return;
249251
currentIndex = name;
250252
loadBtn.innerHTML = '&#10003; Loaded';
251253
loadBtn.className = 'btn btn-success';
@@ -257,13 +259,16 @@ <h1>Moss <span>Playground</span></h1>
257259
topkInput.disabled = false;
258260
alphaSlider.disabled = false;
259261
} catch (e) {
262+
if (loadReqId !== requestId) return;
260263
console.error('loadIndex failed:', e);
261264
currentIndex = null;
262265
loadBtn.innerHTML = 'Load Index';
263266
loadBtn.className = 'btn btn-primary';
264267
loadBtn.disabled = false;
265268
loadStatus.className = 'status-box status-error';
266269
loadStatus.textContent = `Failed: ${e.message || e}`;
270+
} finally {
271+
select.disabled = false;
267272
}
268273
}
269274

0 commit comments

Comments
 (0)