Open kachkaev opened 2 years ago
I can repro this. Would love some advice on addressing it!
Had a quick look in the morning, seems like need a bit more time to investigate. I'll try and spend some time this week.
Hi, I ran into this error on a Next.js app and see the warnings as well. I'm using bangle.dev as a wrapper and have a special component that loads the dev tools because it's the only way I can access the view but I think the issue is the same. I fixed this by moving the call to applyDevTools(view) into a useEffect hook that watches the view. (In my example, Bangle.dev exposes the editor view using context):
import { useEditorState, BangleEditor, useEditorViewContext } from '@bangle.dev/react';
export default function Editor() {
const editorState = useEditorState({ initialValue: 'Hello world!' });
return (
<BangleEditor state={editorState}>
<RegisterDevTools />
</BangleEditor>
);
}
# fails when editor is re-rendered
function RegisterDevTools () {
const view = useEditorViewContext();
applyDevTools(view);
return null;
}
# no error
function RegisterDevTools () {
const view = useEditorViewContext();
useEffect(() => {
applyDevTools(view);
}, [view]);
return null;
}
Hope this helps someone
š @d4rkr00t! Thanks a lot for this awesome package!
Iād like to share one issue I could not resolve myself, it is to do with React fast refresh in Next.js. Here is the MWE: https://codesandbox.io/s/prosemirror-dev-tools-hot-reloading-mwe-d7osb?file=/pages/index.jsx
https://user-images.githubusercontent.com/608862/140981365-19c686fb-52ee-46d3-870f-e7e83a837cb5.mp4
Scenario 1
Open
pages/index.jsx
in dev modeTrigger fast refresh (e.g. add comment and save)
Observe ProseMirror DevTools icon disappearing Expected: It stays up
Trigger fast refresh again
Observe ProseMirror DevTools icon re-appearing
Scenario 2
Observe
Expected: No crash
Console output in both scenarios
Any thoughts are welcome š