-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
add insertContent logic to setContent #4895
Conversation
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Thanks again for your work on this! This all seems sound. One concern though.
If that's the case, I think that the That means we'd be stuck at I don't know how long the team is planning to support the |
@slapbox could you point me to the issues which are blocking you from upgrading to 2.2.x right now? Not sure if we should start releasing or reverting patch versions of an older minor. |
Thanks again for your work on this @bdbch. I'm wondering if you have any updates about how/when this change will be rolled out, or if |
Friendly bump. Is there any way to provide some clarity on plans for this fix? |
I'll take a look at the failing tests today to see if they are coming from the changes introduced by this PR - otherwise I'll try to get another review. |
Ah yes I hadn't even realized there were failing tests. I expect the failures are unrelated based on it being complaining about editable vs non-editable, but maybe you'll find otherwise. |
Inserting Do you know why this might be? This is now the last known blocker for us to get off of the |
@svenadlung any update on when this might be reviewed? I'm increasingly concerned we have no upgrade path and that it will only become more difficult to find one as this issue is baked into more and more versions of TipTap. Patch releases should not break editors and when they do that should really be addressed. The lack of attention to fixing this unexpected breakage has been discouraging. |
// don’t dispatch an empty fragment because this can lead to strange errors | ||
if (content.toString() === '<>') { | ||
return true | ||
} | ||
|
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.
This was removed because commands.clearContent
relies on setContent
to be able to reset the document to the initial schema. This was early exiting and causing a no-op making clearContent
not actually clear anything.
This is very old code that wasn't very well documented but after some testing, I'm confident in this not "leading to strange errors". insertContentAt
is much more robust than when this was written.
I tested inserting empty content into a node and a block and it essentially resulted in a no-op.
Thanks for reviewing @nperez0111. Will this be merged soon? We're still stuck on 2.1.x as 2.4.0 is released due to the underlying issue I hope this PR will resolve. |
I understand your urgency. We are currently in discussion of whether this is actually a breaking change or not. We have discussed the possibility of releasing an We will get back to you soon on this. We appreciate your patience. |
I noticed Could this be addressed by adding a flag to Has any decision been reached? Thanks for reading! PS: To clarify what exactly the problem the existing behavior causes for us: 2.1.13: inserting |
I had the idea for a workaround trying to remove one of the inserted |
So, I've taken a slightly different approach with this one. I made it only ever apply the new "correct" logic when
This therefore keeps backwards compatibility, while also exposing the correct behavior behind an existing option that now is respected. Eventually this should be removed and we rely on insertContentAt's behaviors for everything, but I left only a comment to deal with that in the next major. Thoughts @svenadlung & @bdbch ? |
bcaef5c
to
7e7ae19
Compare
Any update here? This has been broken for over half a year now. |
@Nantris it is now part of v2.5.0-beta.5 Thanks for pushing this forward |
Many thanks to you all! Looks good! |
Please describe your changes
This PR removes some logical differences between
setContent
andinsertContent
orinsertContentAt
.setContent
was usingcreateDocument
which is using a completely different way of parsing the content and creating an initial document.Since
setContent
is never used on a non-existing document as the doc already exists as it is initialized while setting up the prosemirror editor inside the Editor class, we can just simply useinsertContentAt
to replace the whole document content instead of initializing a completely new doc to set.This should help to make sure that in the future we only have one way of setting content into the editor removing the confusion regarding setContent and insertContent.
How did you accomplish your changes
I removed the old code from
setContent
and added a simpleinsertContent
call to make sure all content commands are using the same way of content insertion logic.How have you tested your changes
I created several tests for
setContent
and made sure they run in positive.How can we verify your changes
Run the tests locally on your machine via
npm run test:open
and open thesetContent
spec. Otherwise you can also just runsetContent
in any editor.Remarks
While I don't think this is a breaking change I think we should bump this change into a new minor version. In theory it does the same as the
setContent
logic (taking a document, setting the specified content as child content) - the only difference now is that escape characters\n
or\t
are now included while setting content and are not stripped out.I'm open for this discussion on this one though.
Checklist
Related issues
setContent