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

fix(core): editor.commands.setContent setting document attributes #5814

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-oranges-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---

Fixes editor.command.setContent not setting attributes on the Document Node.
4 changes: 4 additions & 0 deletions packages/core/src/commands/setContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const setContent: RawCommands['setContent'] = (content, emitUpdate = fals

if (dispatch) {
tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate)

Object.entries(document.attrs).forEach(([key, value]) => {
tr.setDocAttribute(key, value)
})
Comment on lines +61 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are planning to remove this branch in the next version (and already have).

So, I don't think that this is the right place for it.

I'm not sure that a method named setContent should update the doc's attributes. I think you may want to implement this in your application instead. I don't think it belongs in this command

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend not to promote doc attributes because they are not synchronized in collaboration with y-prosemirror because of a long standing bug.

So, we don't want to promote something that would not work in the Tiptap ecosystem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I do understand.

}
return true
}
Expand Down