Skip to content

Commit 7e8094e

Browse files
committed
also yield every 100 patches
1 parent 3aa9cfb commit 7e8094e

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

web/src/lib/components/progress-bar/ProgressBar.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{@const percent = state.getPercent()}
2121
{#if percent !== undefined}
2222
<div
23-
class="h-full w-full rounded-full bg-primary drop-shadow-sm drop-shadow-primary/50 transition-all duration-250 ease-in-out"
23+
class="h-full w-full rounded-full bg-primary drop-shadow-sm drop-shadow-primary/50 transition-all duration-50 ease-in-out will-change-transform"
2424
style={`transform: translateX(-${100 - percent}%)`}
2525
></div>
2626
{:else}

web/src/lib/diff-viewer-multi-file.svelte.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ import {
2020
import type { BundledTheme } from "shiki";
2121
import { browser } from "$app/environment";
2222
import { getEffectiveGlobalTheme } from "$lib/theme.svelte";
23-
import { countOccurrences, type FileTreeNodeData, makeFileTree, type LazyPromise, lazyPromise, watchLocalStorage, animationFramePromise } from "$lib/util";
23+
import {
24+
countOccurrences,
25+
type FileTreeNodeData,
26+
makeFileTree,
27+
type LazyPromise,
28+
lazyPromise,
29+
watchLocalStorage,
30+
animationFramePromise,
31+
yieldToBrowser,
32+
} from "$lib/util";
2433
import { onDestroy, tick } from "svelte";
2534
import { type TreeNode, TreeState } from "$lib/components/tree/index.svelte";
2635
import { VList } from "virtua/svelte";
@@ -506,16 +515,18 @@ export class MultiFileDiffViewerState {
506515
// Load patches
507516
const tempDetails: FileDetails[] = [];
508517
let lastYield = performance.now();
518+
let i = 0;
509519
for await (const details of generator) {
520+
i++;
510521
this.loadingState.loadedCount++;
511522

512523
// Pushing directly to the main array causes too many signals to update (lag)
513524
tempDetails.push(details);
514525

515526
const now = performance.now();
516-
if (now - lastYield > 50) {
527+
if (now - lastYield > 50 || i % 100 === 0) {
517528
await tick();
518-
await animationFramePromise();
529+
await yieldToBrowser();
519530
lastYield = now;
520531
}
521532
}

web/src/lib/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ export function animationFramePromise() {
471471
});
472472
}
473473

474+
export async function yieldToBrowser() {
475+
await new Promise((resolve) => setTimeout(resolve, 0));
476+
}
477+
474478
// from bits-ui internals
475479
export type ReadableBoxedValues<T> = {
476480
[K in keyof T]: ReadableBox<T[K]>;

0 commit comments

Comments
 (0)