-
-
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
fix: Address different behavior between getHTML
and generateHTML
#5366
Conversation
🦋 Changeset detectedLatest commit: c734ef0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 54 packages
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 |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -67,7 +67,7 @@ export const TaskItem = Node.create<TaskItemOptions>({ | |||
keepOnSplit: false, | |||
parseHTML: element => element.getAttribute('data-checked') === '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.
I wonder if it is the parseHTML
that should be more lenient instead I don't think that it needs to be checked against true, just that it actually exists right?
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.
Yea so my testing shows that when data-checked is on the element (i.e. generateHTML outputted <li data-checked>...
) that it gives an empty string to say that it was set but has no vlaue.
As opposed to being completely empty which is just null.
So we should be more liberal in our parsing rather than more strict in our output and the result should be the same:
![image](https://private-user-images.githubusercontent.com/1852538/349907610-4f3865f8-c98e-4e72-8694-d79334f20c48.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODc2NDEsIm5iZiI6MTczODk4NzM0MSwicGF0aCI6Ii8xODUyNTM4LzM0OTkwNzYxMC00ZjM4NjVmOC1jOThlLTRlNzItODY5NC1kNzkzMzRmMjBjNDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMDQwMjIxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzI4ZmZlYmJkOTMyMjgzNzM5MGE1NTkzNWNhYjE3YmU3YjEzNWE4NTFiM2ZjYzBjYWM5MjU4NDBlMzI3OWUwNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.rvqhVQlO64mLrdshe17WeYEyx5yWh1jLfgRBgMgQC50)
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.
Please see my REPL repo. https://github.com/baseballyama/tiptap-tasklist-bug-repl
And actually there is data-checked='false'
attribute.
@@ -67,7 +67,7 @@ export const TaskItem = Node.create<TaskItemOptions>({ | |||
keepOnSplit: false, | |||
parseHTML: element => element.getAttribute('data-checked') === 'true', | |||
renderHTML: attributes => ({ | |||
'data-checked': attributes.checked, | |||
'data-checked': attributes.checked ? 'true' : undefined, |
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.
Others may rely on the specific output that this function generates so I would rather not introduce this sort of a change to the output
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.
Agreed: How about this? d938fa9
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.
Oh but I think my repl project doesn't work with this change...
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 reverts commit d938fa9.
parseHTML: element => { | ||
const dataChecked = element.getAttribute('data-checked') | ||
|
||
return dataChecked != null && dataChecked !== 'false' | ||
}, |
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.
I think I would do element.getAttribute('data-checked') === '' || element.getAttribute('data-checked') === 'true'
To be explicit about what we accept
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.
I don't have an opinion for this. updated: 0f4c85d
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.
Looks good, thanks for the quick turn around
@nperez0111 I didn't pay attention to the branch and this PR got merged into the main branch. I think the correct branch is develop, right?😅 (I don't know why main was selected by default) |
Thank you for the backmerge to develop @nperez0111! |
Yea, I saw that too. My mistake, it is on me to handle that. I will wait to get the release out though, I've been releasing a lot lately and have had several complaints of how many releases have been going out lately. |
Changes Overview
Using
generateHTML
function from@tiptap/html
package generates HTML like<li data-checked data-type="taskItem">
.However, in other parts of the code, the expected HTML is
<li data-checked="true" data-type="taskItem">
.Due to this behavior, the selection state is lost when the HTML obtained using the
generateHTML
function is rendered again.Implementation Approach
The value set for the
data-checked
attribute can be eithertrue
or undefined.Testing Done
I manually tested both cases, using
generateHTML
and not using thegenerateHTML
function, and confirmed that everything works correctly.Verification Steps
You can check out this repository to see how it works
https://github.com/baseballyama/tiptap-tasklist-bug-repl
Additional Notes
N/A
Checklist
Related Issues
N/A