diff --git a/src/components/menu/ModeMenu.js b/src/components/menu/ModeMenu.js index b3bf959..5012be5 100644 --- a/src/components/menu/ModeMenu.js +++ b/src/components/menu/ModeMenu.js @@ -30,18 +30,13 @@ export default class ModeMenu extends Component { } handleClick = () => { - // we trigger the onChangeMode on the next tick, after the click event - // has been finished. This is a workaround for preact not neatly replacing - // a rendered app whilst the event is still being handled. - setTimeout(() => { - try { - this.props.onRequestClose() - this.props.onChangeMode(mode) - } - catch (err) { - this.props.onError(err) - } - }) + try { + this.props.onRequestClose() + this.props.onChangeMode(mode) + } + catch (err) { + this.props.onError(err) + } } componentDidMount () { diff --git a/src/index.js b/src/index.js index abc825e..bb794fd 100644 --- a/src/index.js +++ b/src/index.js @@ -179,13 +179,18 @@ function jsoneditor (container, options = {}) { } function handleChangeMode (mode) { - const prevMode = editor._mode + // we execute editor.setMode on the next tick, after the click event + // has been finished. This is a workaround for preact which does not + // neatly replace a rendered app whilst the event is still being handled. + setTimeout(() => { + const prevMode = editor._mode - editor.setMode(mode) + editor.setMode(mode) - if (editor._options.onChangeMode) { - editor._options.onChangeMode(mode, prevMode) - } + if (editor._options.onChangeMode) { + editor._options.onChangeMode(mode, prevMode) + } + }) } function handleError (err) {