fix: mini repl could eval before modules are ready

This commit is contained in:
Felix Roos 2023-01-14 01:27:22 +01:00
parent 49bcb5e19f
commit a2d7d6e81f
2 changed files with 6 additions and 5 deletions

View file

@ -3,8 +3,9 @@ import { initAudioOnFirstClick } from '@strudel.cycles/webaudio';
import { useEffect, useState } from 'react';
import { prebake } from '../repl/prebake';
let modules;
if (typeof window !== 'undefined') {
evalScope(
modules = evalScope(
controls,
import('@strudel.cycles/core'),
// import('@strudel.cycles/tone'),
@ -27,9 +28,9 @@ export function MiniRepl({ tune, drawTime, punchcard, canvasHeight = 100 }) {
useEffect(() => {
// we have to load this package on the client
// because codemirror throws an error on the server
import('@strudel.cycles/react').then((res) => {
setRepl(() => res.MiniRepl);
});
Promise.all([import('@strudel.cycles/react'), modules])
.then(([res]) => setRepl(() => res.MiniRepl))
.catch((err) => console.error(err));
}, []);
return Repl ? (
<div className="mb-4">