Skip to content

Commit

Permalink
Fix(@inquirer/core): Reduce memory consumption of usePrefix in loadin…
Browse files Browse the repository at this point in the history
…g mode
  • Loading branch information
SBoudrias committed Jun 19, 2024
1 parent 9735dea commit 3d15d50
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/core/src/lib/use-prefix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ export function usePrefix({

useEffect((): void | (() => unknown) => {
if (isLoading) {
const timeout = setTimeout(
let inc = -1;
const interval = setInterval(
AsyncResource.bind(() => {
setTick(tick + 1);
inc = inc + 1;
setTick(inc % spinner.frames.length);
}),
spinner.interval,
);

return () => clearTimeout(timeout);
return () => clearInterval(interval);
}
}, [isLoading, tick]);
}, [isLoading]);

if (isLoading) {
const frame = tick % spinner.frames.length;
return spinner.frames[frame]!;
return spinner.frames[tick]!;
}

return prefix;
Expand Down

0 comments on commit 3d15d50

Please sign in to comment.