Skip to content

Commit 41be4e3

Browse files
committed
fix(editable-html): preserve existing spans on load and prevent unnecessary updates PIE-665
1 parent 0f9838f commit 41be4e3

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/editable-html-tip-tap/src/components/EditableHtml.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export const EditableHtml = (props) => {
334334
const nextMarkup = normalizeInitialMarkup(props.markup);
335335

336336
if (nextMarkup !== editor.getHTML()) {
337-
editor.commands.setContent(nextMarkup, false);
337+
editor.commands.setContent(nextMarkup, { emitUpdate: false });
338338
}
339339
}, [props.markup, editor]);
340340

packages/editable-html-tip-tap/src/extensions/css.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,27 @@ export const CSSMark = Mark.create({
169169
},
170170

171171
parseHTML() {
172-
// Any span with a class that matches one of allowed classes
172+
// Any span with a class that matches one of allowed classes any span that carries a class attribute
173+
// so that pre-existing spans are preserved when loading content
173174
return [
174175
{
175176
tag: 'span[class]',
176177
getAttrs: (el) => {
177178
const cls = el.getAttribute('class') || '';
178-
const match = this.options.classes.find((name) => cls.includes(name));
179-
return match ? { class: match } : false;
179+
180+
if (!cls) {
181+
return false;
182+
}
183+
184+
const allowedClasses = (this.options && this.options.classes) || [];
185+
186+
if (allowedClasses.length > 0) {
187+
const match = this.options.classes.find((name) => cls.includes(name));
188+
189+
return match ? { class: match } : false;
190+
}
191+
192+
return { class: cls };
180193
},
181194
},
182195
];

0 commit comments

Comments
 (0)