Conflict with Grammarly chrome extension
Do you want to request a feature or report a bug? Bug
What is the current behavior? When using the Grammarly extension which has 10K reviews in the google app store (with 4.5 stars), text that you type occasionally stops.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Using the draft.js sample site, you can see the behavior in this video: http://screencast.com/t/8xhRQz9sZt
It seems to be related to when grammarly detects an issue.
What is the expected behavior? Not to erase text.
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js? Current version in Chrome on OS X 10.11.4
Any updates on this, or does anybody know of a workaround? We are working on a project using Draft.js, and would like to integrate with Grammarly if possible.
It seems that Grammarly is injecting spans into the editor, wrapping any errors it finds, and this throws the editor into a state where the selection changes suddenly, and there doesn't appear to be a way to differentiate this from a normal selection.
I got the same problem, but I see that facebook.com is using draft-js as in the "status update editor" and this editor doesn't have this problem. I figured out that on facebook.com grammarly is creating a grammarly-ghost div instead of wrapping the text in a span. Does anyone know how to achieve this?
Has anyone found a workaround for this, or are there any updates?
I've filed a support ticket with Grammarly. I'll post any updates here.
I contacted the Grammarly folks, and the support wasn't helpful at all.
At this time, due to technical incompatibility, Grammarly malfunctions on the reported pages. The only workaround is to disable Grammarly for the following pages.
I have escalated your case to the development team. I can confirm that our engineers have backlogged the issue and plan on resolving it at their earliest convenience.
Unfortunately, this will not be a quick fix and I cannot provide you with an estimated timeframe, as the developers will need some time to analyze the cause of this issue.
I pointed out that they've already solved the issue on Facebook.com, and offered a few suggestions to fix it everywhere, but I was returned the usual customer support responses.
Such a shame, because our clients love Grammarly. It wasn't pleasant telling them they can't use it.
Hi, I'm a developer from Grammarly. Facebook fields are simpler because they are plain-text only. We can't easily use the same technique to support Draft.js. It's a rich-text editor. Right now we are working on integration guidelines that will help developers of text editors to support Grammarly. In meantime, I would love to chat with Draft.js developers to show a draft of API spec and get feedback from them. My email: [email protected]
@kigorw - thanks for commenting on this issue!
FYI - Facebook's Notes app uses Draft.js, and even though it has issues, it doesn't mess up as bad as the example on Draft's homepage. For instance, if you type an error and wait for Grammarly to detect it, then start typing again, it doesn't change the cursor position or overwrite any characters like the example on the homepage does. I doubt this helps much but I wanted to point it out in case it did.
I would love to see these things work together, so hopefully somebody from the Draft team reaches out and you can come up with something (even a workaround would be great).
If Grammarly offered any sort of API it would be very easy to integrate it directly into the editor itself. I hope this happens sooner rather than later. I'm really surprised they don't offer one already.
Hmm, this pretty much breaks the whole editor. Is there any way to detect Grammarly? I could then inform the user about the compatibility issues..
@markpradhan You can always disable it by editor.setAttribute('data-gramm', 'false') (editor being the draft-js editor instance).
@nuc it's really hard to set attributes to draft-js editor :/ can't get it to work.. is there no way to detect grammarly?
@markpradhan Why is it hard? For us it works well in componentDidMount like that:
componentDidMount() {
const { editor } = this.refs
const draftEditor = editor.refs.editor
draftEditor.setAttribute('data-gramm', 'false')
}
yeah, i figured it out as well.. was just about to post it here, but your solution is more elegant :D
For anyone using the draft-js-plugins editor, I had to do the following to disable Grammarly:
componentDidMount() {
// disable Grammarly extension, incompatible with draft.js
// https://github.com/facebook/draft-js/issues/616
const pluginEditor = this.refs.editor;
const draftEditor = pluginEditor.refs.editor;
const contentEditable = draftEditor.refs.editor;
ReactDOM.findDOMNode(contentEditable).setAttribute('data-gramm', 'false');
}
@kigorw could you please provide an update from Grammarly's side? Are there any plans to take an intermediate step and disable Grammarly on all Draft.js editors? Otherwise people using Grammarly on a site with a Draft.js editor seem extremely likely to lose their writing...
We released an update that skips all draft.js powered fields. Let me know if you still have somewhere this problem.
Looks like this was fixed on Grammerly's side, so I'm going to close this out.
FYI: I am working on making the editor compatible with Grammarly, and potentially with other extensions that decorate the DOM text with extra tags for its metadata.
So far I managed to handle proper sync of selection and update on input so that editing works and it displays Grammarly suggestions properly.
As Grammarly doesn't fire onInput event while applying fixes, the editor doesn't catch such change. I plan to experiment with MutationObserver to handle this part, after which Grammarly might fully work with the editor.
The work is progress is here if anyone is interested: https://github.com/kenticomartinh/draft-js/tree/experiments/Grammarly_demo
My questions are the following:
- Is this something that editor authors would be willing to adopt to its code if it works and is properly tested?
- Should we handle this in this issue or create a new issue for it? (As this one is about the collision, not necessarily about making Grammarly work with it)
Hey @kenticomartinh,
I am the lead developer for the Grammarly extension. We were excited to see that you're working on making Draft.js compatible with Grammarly! One of our goals is to make Grammarly available everywhere on the web, and we're trying to figure out the best way to do this. Please let me know if there is any way I can be of help.
Hi @blacktaxi,
Thanks for letting me know. I am proceeding quite slowly with this, as currently this is not our top priority so I do it more in a spare time. I expect that we will focus on that more heavily in about a month or two. I am now basically doing my homework to make sure process-based delays with 3rd parties will not delay our process if we need it.
But anyway, I think mutual cooperation could be beneficial for both of us. We use Draft editor for our Cloud-based headless CMS which targets enterprise customers so if we make it work, there is also a business opportunity for you to acquire some Premium subscriptions through that.
As I wrote above I handled the first of the two major burdens, which was syncing the selection properly in case an external tool modifies the structure of the DOM nodes. I am now experimenting with MutationObserver, but given the life-cycle of React and your extension, the received changes to DOM from both React and your extension are bulked to a single list of changes, and I am not able to extract the text change made by your extension as it is already overwriten again by React DOM sync at the time of receiving Observer callback. I will look at that more closely, but so far this option seems as a dead-end option to me.
What I believe is the main problem of how your extension applies changes is what I mentioned above. It doesn't act the same way as native browser spell-check when replacing the text, as it is not firing the on(Before)Input event. This is a problem with modern editors which use object-driven model for editing rather than native contenteditable DOM. What you should ideally do instead of replacing nodes and text in DOM is making a DOM selection, and simulate regular text input that overwrites the selection. By handling this, you should be able to support many more modern editors based on frameworks which use some kind of virtual DOM for rendering such as React does.
I am not able to effectively propose changes to your extension as I can only access its minimized JS through debug. If there was some way to be able to access your browser extension source code for experiments (preferably the Chrome version), I may be able to prepare a pull request with suggested changes for you.
One another (minor) problem that I think I noticed earlier is that even if the element has data-gramm="true" attribute, your rules to disable Grammarly for specific editors are always stronger. I believe the attribute should be stronger for such check as it is an explicit indication from developer that he/she really wants it and probably knows what he/she is doing. I bypassed it for the purpose of experiment this way https://github.com/kenticomartinh/draft-js/commit/1eff16a85df43083eb528065c799b9cb719dcfe3 but I don't believe that DraftJS authors would like such changes in their code base. This might be a show-stopper for the fix PR.
Let me know your thoughts