react-codemirror icon indicating copy to clipboard operation
react-codemirror copied to clipboard

cumulative layout shift while loading

Open YoniChechik opened this issue 2 years ago • 7 comments

while initally loading the component we start with no placeholder div which causes layout shift. This can even be seen when reloading the demo site: https://uiwjs.github.io/react-codemirror/

is there a way to fix this?

YoniChechik avatar Jun 14 '23 06:06 YoniChechik

@YoniChechik I have no way to reproduce the problem you describe.

jaywcjlove avatar Jun 14 '23 06:06 jaywcjlove

Added a gif example: Animation

YoniChechik avatar Jun 14 '23 06:06 YoniChechik

@YoniChechik https://codesandbox.io/embed/react-codemirror-example-codemirror-6-https-github-com-uiwjs-react-codemirror-issues-523-6tv4zq?fontsize=14&hidenavigation=1&theme=dark

Not sure if it's what you want.

jaywcjlove avatar Jun 15 '23 11:06 jaywcjlove

import React, { useEffect, useState } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { javascript } from "@codemirror/lang-javascript";

export default function App() {
  const [loading, setLoading] = useState(true);
  const [text, setText] = useState('console.log("xx")');
  const onChange = React.useCallback((value, viewUpdate) => {
    console.log("value:", value);
  }, []);
  useEffect(() => {
    setTimeout(() => {
      setLoading(false);
      setText("function() {}");
    }, 2000);
  }, []);
  return (
    <div
      className={loading ? "loading" : ""}
      style={{ border: "1px solid red" }}
    >
      <CodeMirror
        value={text}
        height="200px"
        theme="dark"
        extensions={[javascript({ jsx: true })]}
        onChange={onChange}
      />
    </div>
  );
}

jaywcjlove avatar Jun 15 '23 11:06 jaywcjlove