Draft-js: v0.11 - Decorator component with a href on an Anchor causes caret placement issues & dies on deletion

Created on 15 Jul 2019  路  4Comments  路  Source: facebook/draft-js

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When creating a decorator component that returns an Anchor with a href the editor caret will jump to the start of the decorated component after the second character match.

When deleting the final character of the decorated component the Draft editor will crash.

decorator-anchor-480

A simple codesandbox example can be found here:
https://codesandbox.io/s/draft-js-v011-hash-with-link-example-yuiod

Some of my observations are as follows:

  • Removing the href from the anchor will no longer result in the caret errors or crashing.
  • In Draft v0.10.5 whenever a decorated component's match changes it will have its render method called.
  • In Draft v0.11 the render method is only called when the match is first created, when it's 'exited' or when backspace is pressed.

This behaviour would cause issues with components that rely on the matched string for some of their properties. For example creating a link when the text matches a URL (such as Draft JS Plugins' Linkify plugin).

Those examples can be found here:

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?

  • Draft.js v0.11 (worked in v0.10.5)
  • Safari v12.1 & Chrome v75

Note: Firefox does not crash and appears to work OK in this example, however its render method isn't called when the match changes.

bug

Most helpful comment

Pretty sure #2143 is related.

All 4 comments

Pretty sure #2143 is related.

Any updates? @claudiopro
I mean there is no way to auto link stuff now, sounds pretty important?

Also related to https://github.com/draft-js-plugins/draft-js-plugins/issues/1328

@thaoms I can confirm that reverting b2f6ed0 fixes the issues that I experienced, however I'm unsure of the side effects of doing so.
We've currently included a modified version of Draft v0.11 in our codebase, with that commit reverted, and we haven't experienced any other issues thus far.

Though you're probably more interested in the status of when a fix will be released, which I don't have any visibility over.

I can confirm this is fixed in 0.11.4, thanks Frank Thompson and claudiopro!

Was this page helpful?
0 / 5 - 0 ratings