Skip to content

Commit

Permalink
editor: fix image shuffling on real-time editor sync
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Sep 4, 2023
1 parent 0a10df7 commit c80a998
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/editor/src/extensions/image/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const ImageNode = Node.create<ImageOptions>({

addNodeView() {
return createSelectionBasedNodeView(ImageComponent, {
componentKey: (node) => node.attrs.hash,
shouldUpdate: (prev, next) => !hasSameAttributes(prev.attrs, next.attrs),
forceEnableSelection: true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export class SelectionBasedNodeView<
this.isSelectedNode(this.editor.view.state.selection);

return (
<EmotionThemeProvider scope="editor" injectCssVars={false}>
<EmotionThemeProvider
key={this.options.componentKey?.(this.node)}
scope="editor"
injectCssVars={false}
>
<this.options.component
{...props}
editor={this.editor}
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/extensions/react/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type SelectionBasedReactNodeViewProps<TAttributes = Attrs> =
export type ReactNodeViewOptions<P> = {
props?: P;
component?: React.ComponentType<P>;
componentKey?: (node: PMNode) => string;
shouldUpdate?: ShouldUpdate;
contentDOMFactory?: (() => ContentDOM) | boolean;
wrapperFactory?: () => HTMLElement;
Expand Down

0 comments on commit c80a998

Please sign in to comment.