diff --git a/packages/slate/src/changes/by-key.js b/packages/slate/src/changes/by-key.js index 67862b02a..4a2cee528 100644 --- a/packages/slate/src/changes/by-key.js +++ b/packages/slate/src/changes/by-key.js @@ -489,7 +489,7 @@ Changes.replaceNodeByKey = (change, key, newNode, options = {}) => { const parent = document.getParent(key) const index = parent.nodes.indexOf(node) change.removeNodeByKey(key, { normalize: false }) - change.insertNodeByKey(parent.key, index, newNode, options) + change.insertNodeByKey(parent.key, index, newNode, { normalize: false }) if (normalize) { change.normalizeNodeByKey(parent.key) } diff --git a/packages/slate/test/changes/by-key/replace-node-by-key/no-intermediate-normalization.js b/packages/slate/test/changes/by-key/replace-node-by-key/no-intermediate-normalization.js new file mode 100644 index 000000000..d34a4cf85 --- /dev/null +++ b/packages/slate/test/changes/by-key/replace-node-by-key/no-intermediate-normalization.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +/* + * This test makes sure there are no intermediate normalization + * when calling replaceNodeByKey which calls removeNodeByKey and insertNodeByKey successively. + */ + +export default function(change) { + // Replacing by an empty text means the is now empty + // and empty inlines are removed, according to Slate's core schema. + // If an intermediate normalization were to happen, the final normalization + // would fail to find the node's parent and thus throw because that parent + // has already been removed before (due to the intermediate normalization). + change.replaceNodeByKey('a', { object: 'text', text: '' }) +} + +export const input = ( + + + + + lorem + + + + +) + +export const output = ( + + + + + +)