Skip to content

Commit

Permalink
Fixed bug introduced in 39a6450
Browse files Browse the repository at this point in the history
`EditorView.update()` replaces all props, so `dispatchTransaction` needs
to be set every time props are updated.
  • Loading branch information
dminkovsky committed Aug 30, 2020
1 parent 7ba4dcb commit 76877f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-prosemirror",
"version": "1.1.3",
"version": "1.1.4",
"description": "ProseMirror for React",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
22 changes: 15 additions & 7 deletions src/ProseMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ export default forwardRef<Handle, Props>(function ProseMirror(
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
const viewRef = useRef<EditorView<any>>(null!);
viewRef.current?.update(props);
viewRef.current?.update(buildProps(props));
useEffect(() => {
const view = new EditorView(root.current, {
...initialProps.current,
dispatchTransaction: transaction => {
onChangeRef.current(view.state.apply(transaction));
},
});
const view = new EditorView(
root.current,
buildProps(initialProps.current),
);
viewRef.current = view;
return () => {
view.destroy();
Expand All @@ -50,4 +48,14 @@ export default forwardRef<Handle, Props>(function ProseMirror(
},
}));
return <div ref={root} style={style} className={className} />;
function buildProps(props: DirectEditorProps): DirectEditorProps {
return {
...props,
dispatchTransaction: transaction => {
onChangeRef.current(
viewRef.current.state.apply(transaction),
);
},
};
}
});

0 comments on commit 76877f8

Please sign in to comment.