Skip to content

Commit d9e677d

Browse files
committed
Mock tween on server
1 parent 869b7b8 commit d9e677d

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

src/components/support-us/FundraisingProgress.svelte

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte';
32
import { Tween } from 'svelte/motion';
3+
import { onMount } from 'svelte';
44
55
import progressStore from './progress.store';
66
77
const { middleProgress, peopleCount: currentPeopleCount, progress, targetProgress } = $props();
8-
let currentProgressTween = new Tween<number>(progress);
8+
let currentProgressTween;
9+
if (typeof requestAnimationFrame === 'undefined') {
10+
currentProgressTween = {
11+
set: () => {},
12+
subscribe: () => {},
13+
current: progress,
14+
target: progress,
15+
};
16+
} else {
17+
currentProgressTween = new Tween<number>(progress);
18+
}
919
let peopleCount = $state(currentPeopleCount);
1020
let currentProgress = $derived(Math.round(currentProgressTween.current));
11-
onMount(() => {
12-
currentProgressTween.set(progress, { duration: 0 });
13-
progressStore.update((v) => ({ ...v, amount: progress }));
14-
});
15-
progressStore.subscribe((v) => {
16-
(currentProgressTween.target = v.amount), (peopleCount = v.people);
17-
});
1821
let waveOffset = $state(0);
1922
2023
let finished = $derived(currentProgress >= targetProgress);
@@ -33,9 +36,16 @@
3336
return;
3437
}
3538
// No animation during server rendering
36-
if (requestAnimationFrame != null) {
39+
if (typeof requestAnimationFrame === 'undefined') {
3740
return;
3841
}
42+
43+
currentProgressTween.set(progress, { duration: 0 });
44+
progressStore.update((v) => ({ ...v, amount: progress }));
45+
progressStore.subscribe((v) => {
46+
(currentProgressTween.target = v.amount), (peopleCount = v.people);
47+
});
48+
3949
let animationFrame: number;
4050
4151
const animateWave = (timestamp: number) => {

0 commit comments

Comments
 (0)