addFieldChangeListener is calling twice though setFieldValue is called one time

I’ve a CKEditor (ckeditor4-react - npm), and onBlur we’re saving the text to the field value. But even if setFieldValue is called one time, addFieldChangeListener is called two times one with the updated value and the next one with the old value and we can’t save the updated value since it is overridden by the next change to the previous value.

I can’t track where the second addFieldChangeListener call is coming from. From the documentation(https://www.datocms.com/docs/building-plugins/sdk-reference#pluginaddfieldchangelistenerpathchunks-callbackfn) it says addFiledChangeListener will be called in two cases,

  1. When setFieldValue is called
  2. External event(eg, when multiple editors are working on the same entry)

I’ve checked that setFieldValue in our codebase has called one time, but I don’t understand the second case because there’re no other event which triggers update of the field value.

Please see the record, to see the problem.

If we click outside the field, and then click Save it will work as expected. But content users sometimes may click Save button directly.

1 Like

Hello @henok.tesfaye

Could you share with us the code of your plugin (maybe a git repository) at support@datocms.com so we can take a better look at what’s causing the issue?

Thank you!

Thank you @m.finamor . I’ve shared the plugin git repo in the support page.

1 Like