Skip to content

Commit

Permalink
move react() check higher up
Browse files Browse the repository at this point in the history
  • Loading branch information
saranrapjs committed Nov 16, 2023
1 parent 4c572c5 commit 99f1811
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/hooks/useNodePos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export function NodePosProvider({ nodeKey, children }: Props) {
const editorState = useEditorState();
if (!editorState) return <>{children}</>;
const pluginState = reactPluginKey.getState(editorState);
if (!pluginState)
throw new Error(
"Can't find the react() ProseMirror plugin. Was it added to the EditorState.plugins?"
);
if (!pluginState) return <>{children}</>;
return (
<NodePosContext.Provider value={pluginState.keyToPos.get(nodeKey) ?? 0}>
{children}
Expand Down
9 changes: 6 additions & 3 deletions src/nodeViews/createReactNodeViewConstructor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ export function createReactNodeViewConstructor(
? "span"
: "div");

const nodeKey =
reactPluginKey.getState(editorView.state)?.posToKey.get(getPos()) ??
createNodeKey();
const reactPluginState = reactPluginKey.getState(editorView.state);
if (!reactPluginState)
throw new Error(
"Can't find the react() ProseMirror plugin, required for useNodeViews(). Was it added to the EditorState.plugins?"
);
const nodeKey = reactPluginState.posToKey.get(getPos()) ?? createNodeKey();

/**
* Wrapper component to provide some imperative handles for updating
Expand Down

0 comments on commit 99f1811

Please sign in to comment.