From 31a4bf4fa9db0bf60d03df3f4e03a5673577ab40 Mon Sep 17 00:00:00 2001 From: Yonah Forst Date: Fri, 26 Apr 2019 23:20:57 +0200 Subject: [PATCH] Improve performance on large documents with many nodes (#2710) * don't evaluate expensive debug payloads unless debugging is actually enabled * fix for linter --- .../slate-react/src/components/content.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index 3faa99b97..648f7ebe5 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -162,7 +162,10 @@ class Content extends React.Component { const window = getWindow(this.element) const native = window.getSelection() const { activeElement } = window.document - debug.update('updateSelection', { selection: selection.toJSON() }) + + if (debug.enabled) { + debug.update('updateSelection', { selection: selection.toJSON() }) + } // COMPAT: In Firefox, there's a but where `getSelection` can return `null`. // https://bugzilla.mozilla.org/show_bug.cgi?id=827585 (2018/11/07) @@ -274,7 +277,7 @@ class Content extends React.Component { }) } - if (updated) { + if (updated && debug.enabled) { debug('updateSelection', { selection, native, activeElement }) debug.update('updateSelection-applied', { selection }) } @@ -483,11 +486,13 @@ class Content extends React.Component { debug('render', { props }) - debug.update('render', { - text: value.document.text, - selection: value.selection.toJSON(), - value: value.toJSON(), - }) + if (debug.enabled) { + debug.update('render', { + text: value.document.text, + selection: value.selection.toJSON(), + value: value.toJSON(), + }) + } return (