Skip to content

Commit 76877f8

Browse files
committed
Fixed bug introduced in 39a6450
`EditorView.update()` replaces all props, so `dispatchTransaction` needs to be set every time props are updated.
1 parent 7ba4dcb commit 76877f8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "use-prosemirror",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "ProseMirror for React",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/ProseMirror.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ export default forwardRef<Handle, Props>(function ProseMirror(
3131
const onChangeRef = useRef(onChange);
3232
onChangeRef.current = onChange;
3333
const viewRef = useRef<EditorView<any>>(null!);
34-
viewRef.current?.update(props);
34+
viewRef.current?.update(buildProps(props));
3535
useEffect(() => {
36-
const view = new EditorView(root.current, {
37-
...initialProps.current,
38-
dispatchTransaction: transaction => {
39-
onChangeRef.current(view.state.apply(transaction));
40-
},
41-
});
36+
const view = new EditorView(
37+
root.current,
38+
buildProps(initialProps.current),
39+
);
4240
viewRef.current = view;
4341
return () => {
4442
view.destroy();
@@ -50,4 +48,14 @@ export default forwardRef<Handle, Props>(function ProseMirror(
5048
},
5149
}));
5250
return <div ref={root} style={style} className={className} />;
51+
function buildProps(props: DirectEditorProps): DirectEditorProps {
52+
return {
53+
...props,
54+
dispatchTransaction: transaction => {
55+
onChangeRef.current(
56+
viewRef.current.state.apply(transaction),
57+
);
58+
},
59+
};
60+
}
5361
});

0 commit comments

Comments
 (0)