I have an initialization function to create a PM editor and which I rerun whenever editor props change. As part of this, I recreate the plugins which I reconfigure on the old state with state.reconfigure
. Then I attempt to set the state with view.setProps
but which crashes throwing:
Uncaught TypeError: Cannot read properties of null (reading 'matchesNode')
at EditorView.updateStateInner
Here is a code sandbox sharp-khorana-mcpwz - CodeSandbox
But the main part is:
function init(
element: HTMLElement,
props: EditorProps,
oldView?: EditorView | null
) {
if (oldView) {
const state = oldView.state.reconfigure({
plugins: exampleSetup({ schema })
});
oldView.setProps({
state
});
return oldView;
}
const state = EditorState.create({
schema,
plugins: exampleSetup({ schema })
});
const view = new EditorView(
{ mount: element },
{
state
}
);
props.onEditorReady && props.onEditorReady(view);
return view;
}