-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[draft-js-resizeable-plugin] not working when added to an existent project #2272
Comments
What kind of element are you trying to resize? It looks like it doesn't set the ref which it should. The source can be found here:
|
I just noticed this error as well ( I've had draft plugins in my project for a long time without an issue. I did update draft-js-plugin dependencies recently, and confirmed that the older build with the older draft-js-plugins works fine (I don't believe I changed other code here). I'll post more as I learn more. As far as I can tell, my error appears to be in the Alignment plugin. For example, the error sends me here:
|
@nperichSYKES can you create a codesandbox eample? |
I'll focus on this Monday and see if I can figure anything out. |
Ok, here you go. This is the image example in the docs with an imageComponent option added. (EDIT: I updated it to a working version)
|
You should be able to fix the issue by adding a forwardRef for your image: const imagePlugin = createImagePlugin({
decorator,
imageComponent: React.forwardRef(({
block,
className,
theme = {},
blockProps,
customStyleMap,
customStyleFn,
decorator,
forceSelection,
offsetKey,
selection,
tree,
contentState,
...elementProps
},ref) => {
const { src } = contentState.getEntity(block.getEntityAt(0)).getData();
console.log("src is accurate: ", src);
return <img src={src} {...elementProps} ref={ref} />;
})
}); Maybe we should notice it in the docs. |
Thanks, yeah that makes sense as a first step. If ref behavior was changed internally, it's definitely worth updating the docs and attaching a Breaking Change warning to the changelog with 5.x with a hint about wrapping imageComponent with forwardRef. However, though just adding forwardRef did fix the minimal example I posted, it didn't fix my actual code. And I assume that most people who bother to use For whoever comes here later (and for when you update the docs!), it seems the problem with upgrading to 5.x when using the As far as I can tell, the best solution is to use an obscure React utility called At least to me, it wasn't entirely clear exactly how you use this...and if you just follow the React doc examples to just add the "handles" you need, it won't really work. Since, I think (?), it won't actually carry over everything draft-js-plugins needs. But I figured out that you can just return the entire
I updated my Code Sandbox with an example of how this could work: I'm not sure this is the best way to do it, or there isn't a gotcha. It seems pretty ugly. But it seems to work for now... |
Environment
Operating System version: macOS 11.5.1
Browser version: Version 92.0.4515.159 (Official Build) (x86_64)
Description
It seems the library has issues when being added to an existing project. In a fully new one, everything works fine.
The project I'm working on currently uses. However, when upgrading to the current version resizable stops working.
The text was updated successfully, but these errors were encountered: