Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Feb 16, 2024

Please describe your changes

This PR removes some logical differences between setContent and insertContent or insertContentAt. setContent was using createDocument 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 use insertContentAt 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 simple insertContent 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 the setContent spec. Otherwise you can also just run setContent 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

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

Related issues

@bdbch bdbch self-assigned this Feb 16, 2024
Copy link

netlify bot commented Feb 16, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 1ed48ba
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/664354428706df000906835b
😎 Deploy Preview https://deploy-preview-4895--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Nantris
Copy link
Contributor

Nantris commented Feb 17, 2024

Thanks again for your work on this!

This all seems sound. One concern though.

I think we should bump this change into a new minor version.

If that's the case, I think that the 2.1.x branch should have 2.1.15 reverted since people affected by #4862 can't upgrade past 2.1.15 without this patch being applied to the 2.1.x version. If waiting for the next minor version then this won't land until 2.3.x. I'm guessing 2.3.x is a long ways off, and currently we're blocked from even 2.2.0 by other issues.

That means we'd be stuck at 2.1.14 for potentially a very long time.

I don't know how long the team is planning to support the 2.1.x branch, but it seems quite possible that some fix will land on that branch that we need in the meanwhile.

@bdbch
Copy link
Contributor Author

bdbch commented Feb 20, 2024

@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.

@Nantris
Copy link
Contributor

Nantris commented Feb 20, 2024

Sure @bdbch - the only known blocker for us is #4704, but there's always a chance there's more blockers we haven't been able to get to yet because #4704 causes crashes.

@Nantris
Copy link
Contributor

Nantris commented Feb 27, 2024

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 2.1.15 could be reverted? I think reverting 2.1.15 is the most appropriate approach, but if it's also incorporated into 2.2.x then I know that's a bit more complicated.

@Nantris
Copy link
Contributor

Nantris commented Mar 20, 2024

Friendly bump.

Is there any way to provide some clarity on plans for this fix?

@bdbch
Copy link
Contributor Author

bdbch commented Apr 6, 2024

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.

@Nantris
Copy link
Contributor

Nantris commented Apr 10, 2024

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.

@Nantris
Copy link
Contributor

Nantris commented Apr 11, 2024

2.3.0 seems to handle inserting /t properly, but not /n. If I insert /r/n it inserts a /n but it's not at all clear why this is necessary and it might have unintended consequences.

Inserting /n/n inserts two /n characters, leaving me all the more confused about why /n inserts zero of them.

Do you know why this might be? This is now the last known blocker for us to get off of the 2.1.x branch (so long as #5061 is also merged)

@Nantris
Copy link
Contributor

Nantris commented May 8, 2024

@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.

Comment on lines -67 to -71
// don’t dispatch an empty fragment because this can lead to strange errors
if (content.toString() === '<>') {
return true
}

Copy link
Contributor

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.

@Nantris
Copy link
Contributor

Nantris commented May 14, 2024

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.

@nperez0111
Copy link
Contributor

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 rc to get feedback on whether it breaks user's workflows or not.

We will get back to you soon on this. We appreciate your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready to Merge
Development

Successfully merging this pull request may close these issues.

None yet

3 participants