From 8b39f5ac05df5de1efcd721298c3e165f224729b Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 26 Jan 2021 11:09:49 +0100 Subject: [PATCH] Fixes #9180 (#9204) Signed-off-by: soupette --- .../admin/src/components/InputJSON/index.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/strapi-plugin-content-manager/admin/src/components/InputJSON/index.js b/packages/strapi-plugin-content-manager/admin/src/components/InputJSON/index.js index f03f3d49bf..5f492f2909 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/InputJSON/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/InputJSON/index.js @@ -29,7 +29,7 @@ class InputJSON extends React.Component { constructor(props) { super(props); this.editor = React.createRef(); - this.state = { error: false, markedText: null, hasInitValue: false }; + this.state = { error: false, markedText: null }; } componentDidMount() { @@ -54,7 +54,7 @@ class InputJSON extends React.Component { } componentDidUpdate(prevProps) { - if (prevProps.value !== this.props.value && !this.state.hasInitValue) { + if (prevProps.value !== this.props.value && !this.codeMirror.state.focused) { this.setInitValue(); } } @@ -65,9 +65,9 @@ class InputJSON extends React.Component { try { if (value === null) return this.codeMirror.setValue(''); - this.setState({ hasInitValue: true }); + const nextValue = typeof value !== 'string' ? stringify(value, null, 2) : value; - return this.codeMirror.setValue(stringify(value, null, 2)); + return this.codeMirror.setValue(nextValue); } catch (err) { return this.setState({ error: true }); } @@ -119,8 +119,6 @@ class InputJSON extends React.Component { return; } - this.setState({ hasInitValue: true }); - const { name, onChange } = this.props; let value = doc.getValue();