Making a TinyMCE plugin work with Synchrony

I’m currently writing a Confluence app which provides a plugin for the TinyMCE editor in Confluence. One task of the TinyMCE plugin is to insert text at the current cursor position, i. e. it manipulates the HTML structure of the document. I learned that this is problematic with respect to collaborative editing with Synchrony (for example, one has to deactivate Grammarly for this reason as described here

In order to make this work, I found out that apparently you have to trigger two Synchrony-related JavaScript events directly before and after making the changes to the HTML structure of the edited Confluence page. My TinyMCE plugin now uses the following code when inserting text at the current cursor position:

AJS.trigger('synchrony.stop', {id: 'some-custom-plugin-identifier'})

// insert text into HTML structure ...

AJS.trigger('synchrony.start', {id: 'some-custom-plugin-identifier'})

Before I added these events to my JavaScript code, I experienced the effect that the Synchrony process could not be started when rebooting Confluence after having used my plugin. By that, Confluence became unusable. Only after deleting a specific Jar file (with a name similar to 0.3.1-release-confluence_6.1-e20fb944.jar) in Confluence’s temp directory or by deactivating my Confluence app, Synchrony could be started again.

So I have two questions regarding Synchrony:

  • Is this Jar file 0.3.1-release-confluence_6.1-e20fb944.jar (which apparently contains the Synchrony server and will be started in a separate process) ordinarily deleted when Confluence is shut down? Is it an error when this file persists in the temp directory after shutting down Confluence?

  • Is triggering the two events synchrony.stop and synchrony.start enough to make a TinyMCE plugin play along nicely with Synchrony or do I have to take additional measures to make it work properly?

Thanks for helping!

Hi. Synchrony developer here.

Problem with Grammarly is not so much that it modifies the content, but that it adds html that shouldn’t be synchronized (think underlines, highlights, popups, etc). If your plugin only inserts some text I would think it should work fine. Synchrony in Confluence works by diffing the current dom state with the state it knows about, and generating deltas, so if all you insert into the dom should be synchronized, it should just work. Also I don’t think you should trigger synchrony.stop and synchrony.start. The effect you see with Synchrony being unable to start is extremly weird, I don’t see how tinymce plugin can possibly make it being unable to start. Can you please send me the logs?

Kind regards,
Ales Huzik

1 Like

Hi Ales,

thanks a lot for your input! I’m beginning to see things more clearly now. I see that my understanding of the events synchrony.stop and synchrony.stop was in so far incorrect, as I thought these events would be necessary to make changes to the edited document (i. e. inserting stuff). Now I understand these two events to be only necessary when some kind of selector (such as the Confluence autocomplete selection list) is shown to the user. In fact, my own Confluence app uses a similar selector, so I guess I should trigger the two events before and after my selector popup list is shown and not when I insert the selected text.

As to the Synchrony startup problem we experienced with my app, I thought the same as you at first. I couldn’t image that some client-side JavaScript code could possibly prevent a server process from starting. But somehow my app seemed to be the reason, since when we disabled my app, Synchrony could be started again (there’s no other server-side code which could cause this problem, it’s just a JavaScript file in combination with a licence check REST service). The problem only occurred after the app was actively used in the Confluence editor.

At the moment, I can’t provide you with any logs since the problem did not reoccur since the last deployment of the app. We’re crossing our fingers that we’ll not experience this problem anymore. The last time we had these issues there were no infos regarding the failed Synchrony startup process in the logs (no exceptions, no error messages, nothing at all). It just wouldn’t start up. If we’ll run into the same situation again, I’m happy to provide you with the corresponding Synchrony logs.

Cheers, Roland