diff --git a/website/src/repl/components/panel/SoundsTab.jsx b/website/src/repl/components/panel/SoundsTab.jsx
index 363f6b98a..a9f10bf12 100644
--- a/website/src/repl/components/panel/SoundsTab.jsx
+++ b/website/src/repl/components/panel/SoundsTab.jsx
@@ -62,11 +62,9 @@ export function SoundsTab() {
// stop current sound on mouseup
useEvent('mouseup', () => {
- const t = trigRef.current;
+ const ref = trigRef.current;
trigRef.current = undefined;
- t?.then((ref) => {
- ref?.stop(getAudioContext().currentTime + 0.01);
- });
+ ref?.stop?.(getAudioContext().currentTime + 0.01);
});
return (
@@ -124,12 +122,19 @@ export function SoundsTab() {
duration: 0.5,
};
soundPreviewIdx++;
- const time = ctx.currentTime + 0.05;
const onended = () => trigRef.current?.node?.disconnect();
- trigRef.current = Promise.resolve(onTrigger(time, params, onended));
- trigRef.current.then((ref) => {
- connectToDestination(ref?.node);
- });
+ try {
+ // Pre-load the sample by calling onTrigger with a future time
+ // This triggers the loading but schedules playback for later
+ const time = ctx.currentTime + 0.5; // Give 500ms for loading
+ const ref = await onTrigger(time, params, onended);
+ trigRef.current = ref;
+ if (ref?.node) {
+ connectToDestination(ref.node);
+ }
+ } catch (err) {
+ console.warn('Failed to trigger sound:', err);
+ }
}}
>
{' '}