Skip to content

Commit

Permalink
Fix(@inquirer/core): Delay showing any loader by 300ms to avoid spinn…
Browse files Browse the repository at this point in the history
…er flickering. Ref #1407
  • Loading branch information
SBoudrias committed Jun 19, 2024
1 parent 47cbb40 commit 36c735c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
23 changes: 13 additions & 10 deletions packages/core/src/lib/use-prefix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export function usePrefix({
let tickInterval: NodeJS.Timeout | undefined;
let inc = -1;
// Delay displaying spinner by 300ms, to avoid flickering
const delayTimeout = setTimeout(AsyncResource.bind(() => {
setShowLoader(true);
const delayTimeout = setTimeout(
AsyncResource.bind(() => {
setShowLoader(true);

tickInterval = setInterval(
AsyncResource.bind(() => {
inc = inc + 1;
setTick(inc % spinner.frames.length);
}),
spinner.interval,
);
}), 300);
tickInterval = setInterval(
AsyncResource.bind(() => {
inc = inc + 1;
setTick(inc % spinner.frames.length);
}),
spinner.interval,
);
}),
300,
);

return () => {
clearTimeout(delayTimeout);
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"license": "MIT",
"homepage": "https://github.com/SBoudrias/Inquirer.js",
"dependencies": {
"@inquirer/prompts": "^5.0.5",
"@inquirer/core": "^8.2.2",
"@inquirer/prompts": "^5.0.5",
"chalk": "^4.1.2"
},
"publishConfig": {
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@inquirer/demo@workspace:packages/demo"
dependencies:
"@inquirer/core": "npm:^8.2.2"
"@inquirer/prompts": "npm:^5.0.5"
chalk: "npm:^4.1.2"
bin:
Expand Down

0 comments on commit 36c735c

Please sign in to comment.