-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Fix Cannot find DOM for readonly void elements #4887
Fix Cannot find DOM for readonly void elements #4887
Conversation
🦋 Changeset detectedLatest commit: ad63bba The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. We’re just starting to add tests for slate-react so it would be great if you can add a test (I won’t block for that, just want to start building up a decent test suite). Thanks.
Yup will do. I noticed that we use EDIT: Tried to do this, and I found it hard to atleast create a reasonable unit test that involves clicking in the void elements. I can do it with cypress, but I don't know if we want to modify examples and make the e2e tests more sophisticated (or they should just be simple tests as they are). I think the react-testing-library should help here. LMK what you think. |
Let me think about it a bit and ask a few of the other maintainers for their thoughts. There is https://github.com/mwood23/slate-test-utils which leverages react-testing-library, but there has been reasonable reluctance to stray too far from the approach used in slate core. |
Makes sense. It's definitely non-trivial to test the behavior right now given the existing framework in the repo. |
Just to mention: The logic with void elements changed in this PR was already there before my changes for readonly editors in #4727. So I guessed back then that some selection for void elements was indeed intended and decided to just avoided selection when the editor is readonly. In other words: I think, your PR changes behavior not only for readonly editors, but also for void elements in editable editors. Is this intended? Doing some git blaming, the initial code comes from PR #3649, fixing issue #3648. For testing, I removed the That said, even with a good set of automated tests I would be hesitating to remove some code I have no clue about, even worse without tests... 🤞 |
Thank you for looking at this with a keen eye!
That's true and it makes sense that you should be able to select elements when you're editing them.
Hm, I don't think so. If the editor is in readonly mode, that clause will return false and that clause should be ignored, right?
If Fwiw I also played around with the images and mentions examples and they seem to be working normally. Lmk if you think otherwise!
Hm, I don't see that locally. This is what I see without the Screen.Recording.2022-03-14.at.9.38.07.PM.mov |
Assume that there is a void element where I'm just saying that your changes cause a change in behavior also for non-readonly/editable editors, not just for readonly ones and I'm unsure if this is intended. From your issue description, I thought that your changes should only affect readonly editors. I guess that your void element has an editable target, causing the first part of the boolean operation to always be true. If you really want your changes to only affect readonly editors, then I think some change like the following (pseudo-code) would be needed, where
I only tried out my use case with image void elements, so your use case may still fail and that's a good reason to keep as much use cases unchanged as possible, I think - we don't know all the use cases the existing code is necessary for 😄 |
Ah that's true, but I guess it's unexpected for
I didn't do anything special to make my void element an editable target. Check out this sandbox for what the element looks like. It is curious though why the images element doesn't crash. 🤔 Here's the image example that doesn't crash EDIT: Aha, there's a |
Seems to be the correct way with |
Closing this because setting |
Description
Modified the logic for the editor to gracefully handle selections inside void elements of readonly editors.
Changed the
isTargetInsideNonReadonlyVoid
to beisTargetInsideReadonlyVoid
because double negatives are confusing :)PENDING: Tests based on feedback from @dylans.
Issue
Fixes: #4886
Example
Before:
Screen.Recording.2022-03-14.at.8.35.01.AM.mov
After:
Screen.Recording.2022-03-14.at.8.35.27.AM.mov
Context
The logic previously was:
The node selection wouldn't go inside the second if-statement because the first clause would return true (
hasEditableTarget
checks if this node target is in the same editor, which is true). The second clause also needs to be checked as well to see if the target is inside a readonly-void element. If it is, then we should avoid selection.I'm not sure if this is the right long term approach. Void elements should be selectable too, but the behavior should probably be up to the element-renderer.
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)