1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

remove extra force re-renders on onCompositionStart/End (#1711)

This commit is contained in:
Gergely Illés
2018-04-27 22:57:09 +02:00
committed by Ian Storm Taylor
parent fb172dec6f
commit da89f58c4c
2 changed files with 8 additions and 10 deletions

View File

@@ -71,7 +71,6 @@ class Content extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.tmp = {} this.tmp = {}
this.tmp.key = 0
this.tmp.isUpdatingSelection = false this.tmp.isUpdatingSelection = false
EVENT_HANDLERS.forEach(handler => { EVENT_HANDLERS.forEach(handler => {
@@ -276,12 +275,6 @@ class Content extends React.Component {
onEvent(handler, event) { onEvent(handler, event) {
debug('onEvent', handler) debug('onEvent', handler)
// COMPAT: Composition events can change the DOM out of under React, so we
// increment this key to ensure that a full re-render happens. (2017/10/16)
if (handler == 'onCompositionEnd') {
this.tmp.key++
}
// Ignore `onBlur`, `onFocus` and `onSelect` events generated // Ignore `onBlur`, `onFocus` and `onSelect` events generated
// programmatically while updating selection. // programmatically while updating selection.
if ( if (
@@ -491,7 +484,6 @@ class Content extends React.Component {
<Container <Container
{...handlers} {...handlers}
data-slate-editor data-slate-editor
key={this.tmp.key}
ref={this.ref} ref={this.ref}
data-key={document.key} data-key={document.key}
contentEditable={readOnly ? null : true} contentEditable={readOnly ? null : true}

View File

@@ -143,7 +143,10 @@ function BeforePlugin() {
// HACK: we need to re-render the editor here so that it will update its // HACK: we need to re-render the editor here so that it will update its
// placeholder in case one is currently rendered. This should be handled // placeholder in case one is currently rendered. This should be handled
// differently ideally, in a less invasive way? // differently ideally, in a less invasive way?
editor.setState({ isComposing: false }) // (apply force re-render if isComposing changes)
if (editor.state.isComposing) {
editor.setState({ isComposing: false })
}
}) })
debug('onCompositionEnd', { event }) debug('onCompositionEnd', { event })
@@ -164,7 +167,10 @@ function BeforePlugin() {
// HACK: we need to re-render the editor here so that it will update its // HACK: we need to re-render the editor here so that it will update its
// placeholder in case one is currently rendered. This should be handled // placeholder in case one is currently rendered. This should be handled
// differently ideally, in a less invasive way? // differently ideally, in a less invasive way?
editor.setState({ isComposing: true }) // (apply force re-render if isComposing changes)
if (!editor.state.isComposing) {
editor.setState({ isComposing: true })
}
debug('onCompositionStart', { event }) debug('onCompositionStart', { event })
} }