uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.68k stars 134 forks source link

BUG: Memory Leak when rerendering CodeMirror #484

Open humpalum opened 1 year ago

humpalum commented 1 year ago

Hey yall,

I think i found a memory leak in the CodeMirror Component...

You can find the PoC in the following Codesandbox:

CAREFUL: It will fill up your memory in just few minutes... I used a quite small interval as well as many CodeMirror to speed up the process...

https://codesandbox.io/s/gallant-danilo-nc8euu?file=/src/App.js

Memory usage: image ~1 min later: image

It seems like Firefox is more affected by this than Chrome.. Chromes memory fills up way slower...

The workaround that i use is the following: Instead of:

<CodeMirror
   theme={theme.colorScheme}
   height="500px"
   value={originalFilters}
   //defaultValue={originalFilters}
   placeholder={placeholder}
   onChange={setCurrentFilters}
   readOnly={readOnly}
 />

I use a memo:

<CodeMirrorMemo
  theme={theme.colorScheme}
  height="500px"
  value={originalFilters}
   //defaultValue={originalFilters}
  placeholder={placeholder}
   onChange={setCurrentFilters}
   readOnly={readOnly}

                />

const CodeMirrorMemo = memo(CodeMirror)

I'm not sure what else i could provide right now but feel free to request whatever else i can provide to help out. Thank you :)

humpalum commented 1 year ago

Might be related to https://github.com/codemirror/dev/issues/1070 ?

jaywcjlove commented 1 year ago

@humpalum I can't solve this problem. If there is any optimization direction in the future, please let me know.