From 61c08d52277feff8d002def9e666be258c7734b2 Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Sat, 9 Dec 2023 11:13:15 +0000 Subject: [PATCH] Fix: `serializeHtml` mutates the live `editor` instance --- .changeset/silver-rings-own.md | 5 +++++ packages/serializer-html/src/elementToHtml.ts | 1 - packages/serializer-html/src/utils/createElementWithSlate.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changeset/silver-rings-own.md diff --git a/.changeset/silver-rings-own.md b/.changeset/silver-rings-own.md new file mode 100644 index 0000000000..22c6245c1a --- /dev/null +++ b/.changeset/silver-rings-own.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-serializer-html': patch +--- + +Fix: `serializeHtml` mutates the live `editor` instance diff --git a/packages/serializer-html/src/elementToHtml.ts b/packages/serializer-html/src/elementToHtml.ts index 10de567a5f..f7065e9ba5 100644 --- a/packages/serializer-html/src/elementToHtml.ts +++ b/packages/serializer-html/src/elementToHtml.ts @@ -50,7 +50,6 @@ export const elementToHtml = ( renderToStaticMarkup( createElementWithSlate( { - editor: editor as any, ...plateProps, children: plugin.serializeHtml?.(props as any) ?? diff --git a/packages/serializer-html/src/utils/createElementWithSlate.ts b/packages/serializer-html/src/utils/createElementWithSlate.ts index b18b3925a5..053630ad8a 100644 --- a/packages/serializer-html/src/utils/createElementWithSlate.ts +++ b/packages/serializer-html/src/utils/createElementWithSlate.ts @@ -1,5 +1,5 @@ import React, { ComponentClass, FunctionComponent } from 'react'; -import { Plate, PlateProps } from '@udecode/plate-common'; +import { createPlateEditor, Plate, PlateProps } from '@udecode/plate-common'; /** * Create a React element wrapped in a Plate provider. @@ -9,7 +9,7 @@ export const createElementWithSlate = ( dndWrapper?: string | FunctionComponent | ComponentClass ) => { const { - editor, + editor = createPlateEditor(), value = [], onChange = () => {}, children,