Skip to content

Commit 7618e32

Browse files
authored
Merge pull request #500 from unpkg/mjackson/fix-run-demo-flicker
Hold the demo button's running state once shown
2 parents 59a1cf0 + 37f3113 commit 7618e32

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎packages/unpkg-www/src/components/run-demo.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ export function RunDemo({ runUrl }: { runUrl: string }): VNode {
2020
}
2121

2222
setState("running");
23-
let slowRunTimer = setTimeout(() => setSlowRun(true), 250);
23+
// Show the running state only when a run is genuinely slow, and once shown
24+
// keep it up for a minimum time — otherwise runs near the threshold (every
25+
// click does a real /transform round trip) blink the label.
26+
let slowRunShownAt = 0;
27+
let slowRunTimer = setTimeout(() => {
28+
slowRunShownAt = Date.now();
29+
setSlowRun(true);
30+
}, 300);
2431

2532
try {
2633
// Recreate the example's inline script tag and hand it to the real /run
@@ -42,7 +49,12 @@ export function RunDemo({ runUrl }: { runUrl: string }): VNode {
4249
setState("error");
4350
} finally {
4451
clearTimeout(slowRunTimer);
45-
setSlowRun(false);
52+
if (slowRunShownAt === 0) {
53+
setSlowRun(false);
54+
} else {
55+
let remaining = Math.max(0, 500 - (Date.now() - slowRunShownAt));
56+
setTimeout(() => setSlowRun(false), remaining);
57+
}
4658
}
4759
}
4860

0 commit comments

Comments
 (0)