From a74fbd13908f10597a6fa0e829591ae45bcf9783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 2 Nov 2016 16:43:29 +0100 Subject: [PATCH] Don't calcul range decorations in shouldComponentUpdate when schema has no decorations --- src/components/node.js | 7 +++++-- src/models/schema.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/node.js b/src/components/node.js index 2a085335b..aa4aee459 100644 --- a/src/components/node.js +++ b/src/components/node.js @@ -143,8 +143,9 @@ class Node extends React.Component { // For text nodes, which can have custom decorations, we need to check to // see if the block has changed, which has caused the decorations to change. - if (nextProps.node.kind == 'text') { + if (nextProps.node.kind == 'text' && nextProps.schema.hasDecorators) { const { node, schema, state } = nextProps + const { document } = state const decorators = document.getDescendantDecorators(node.key, schema) const ranges = node.getRanges(decorators) @@ -155,7 +156,9 @@ class Node extends React.Component { const prevDecorators = prevDocument.getDescendantDecorators(prevNode.key, prevSchema) const prevRanges = prevNode.getRanges(prevDecorators) - if (!ranges.equals(prevRanges)) return true + if (!ranges.equals(prevRanges)) { + return true + } } // Otherwise, don't update. diff --git a/src/models/schema.js b/src/models/schema.js index 0bd18c549..2198aa371 100644 --- a/src/models/schema.js +++ b/src/models/schema.js @@ -46,6 +46,8 @@ class Schema extends new Record(DEFAULTS) { /** * Return true if one rule can normalize the document + * + * @return {Boolean} isNormalization */ get isNormalization() { @@ -53,6 +55,17 @@ class Schema extends new Record(DEFAULTS) { return rules.some(rule => rule.validate) } + /** + * Return true if one rule can decorate text nodes + * + * @return {Boolean} hasDecorators + */ + + get hasDecorators() { + const { rules } = this + return rules.some(rule => rule.decorate) + } + /** * Return the renderer for an `object`. *