mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 11:38:37 +00:00
fix: dumb react ssr workaround
This commit is contained in:
parent
f477273d8a
commit
b0bdd09032
@ -1,4 +1,4 @@
|
|||||||
import { useState, useRef, useCallback, useMemo, useEffect } from 'react';
|
import { useState, useRef, useCallback, useMemo, useEffect, useLayoutEffect } from 'react';
|
||||||
import { Icon } from './Icon';
|
import { Icon } from './Icon';
|
||||||
import { silence, getPunchcardPainter, noteToMidi } from '@strudel.cycles/core';
|
import { silence, getPunchcardPainter, noteToMidi } from '@strudel.cycles/core';
|
||||||
import { transpiler } from '@strudel.cycles/transpiler';
|
import { transpiler } from '@strudel.cycles/transpiler';
|
||||||
@ -9,6 +9,9 @@ import { prebake } from '../repl/prebake.mjs';
|
|||||||
import { loadModules } from '../repl/util.mjs';
|
import { loadModules } from '../repl/util.mjs';
|
||||||
import Claviature from '@components/Claviature';
|
import Claviature from '@components/Claviature';
|
||||||
|
|
||||||
|
// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
||||||
|
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
||||||
|
|
||||||
let prebaked, modulesLoading;
|
let prebaked, modulesLoading;
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
prebaked = prebake();
|
prebaked = prebake();
|
||||||
@ -89,7 +92,8 @@ export function MiniRepl({
|
|||||||
const editorRef = useRef();
|
const editorRef = useRef();
|
||||||
const containerRef = useRef();
|
const containerRef = useRef();
|
||||||
const [client, setClient] = useState(false);
|
const [client, setClient] = useState(false);
|
||||||
useEffect(() => {
|
|
||||||
|
useIsomorphicLayoutEffect(() => {
|
||||||
setClient(true);
|
setClient(true);
|
||||||
if (!editorRef.current) {
|
if (!editorRef.current) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user