From 76877f8748b23961aaf0622a9395987f19fdee76 Mon Sep 17 00:00:00 2001 From: Dmitry Minkovsky Date: Sun, 30 Aug 2020 10:53:14 -0400 Subject: [PATCH] Fixed bug introduced in 39a6450 `EditorView.update()` replaces all props, so `dispatchTransaction` needs to be set every time props are updated. --- package.json | 2 +- src/ProseMirror.tsx | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a290013..0134bf8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ProseMirror.tsx b/src/ProseMirror.tsx index f323ce7..c6c68d2 100644 --- a/src/ProseMirror.tsx +++ b/src/ProseMirror.tsx @@ -31,14 +31,12 @@ export default forwardRef(function ProseMirror( const onChangeRef = useRef(onChange); onChangeRef.current = onChange; const viewRef = useRef>(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(); @@ -50,4 +48,14 @@ export default forwardRef(function ProseMirror( }, })); return
; + function buildProps(props: DirectEditorProps): DirectEditorProps { + return { + ...props, + dispatchTransaction: transaction => { + onChangeRef.current( + viewRef.current.state.apply(transaction), + ); + }, + }; + } });