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: Address different behavior between getHTML and generateHTML #5366

Merged
merged 7 commits into from
Jul 18, 2024

Conversation

baseballyama
Copy link
Contributor

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 either true or undefined.

Testing Done

I manually tested both cases, using generateHTML and not using the generateHTML 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

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

N/A

Copy link

changeset-bot bot commented Jul 18, 2024

🦋 Changeset detected

Latest commit: c734ef0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 54 packages
Name Type
@tiptap/extension-task-item Patch
@tiptap/core Patch
@tiptap/extension-blockquote Patch
@tiptap/extension-bold Patch
@tiptap/extension-bubble-menu Patch
@tiptap/extension-bullet-list Patch
@tiptap/extension-character-count Patch
@tiptap/extension-code-block-lowlight Patch
@tiptap/extension-code-block Patch
@tiptap/extension-code Patch
@tiptap/extension-collaboration-cursor Patch
@tiptap/extension-collaboration Patch
@tiptap/extension-color Patch
@tiptap/extension-document Patch
@tiptap/extension-dropcursor Patch
@tiptap/extension-floating-menu Patch
@tiptap/extension-focus Patch
@tiptap/extension-font-family Patch
@tiptap/extension-gapcursor Patch
@tiptap/extension-hard-break Patch
@tiptap/extension-heading Patch
@tiptap/extension-highlight Patch
@tiptap/extension-history Patch
@tiptap/extension-horizontal-rule Patch
@tiptap/extension-image Patch
@tiptap/extension-italic Patch
@tiptap/extension-link Patch
@tiptap/extension-list-item Patch
@tiptap/extension-list-keymap Patch
@tiptap/extension-mention Patch
@tiptap/extension-ordered-list Patch
@tiptap/extension-paragraph Patch
@tiptap/extension-placeholder Patch
@tiptap/extension-strike Patch
@tiptap/extension-subscript Patch
@tiptap/extension-superscript Patch
@tiptap/extension-table-cell Patch
@tiptap/extension-table-header Patch
@tiptap/extension-table-row Patch
@tiptap/extension-table Patch
@tiptap/extension-task-list Patch
@tiptap/extension-text-align Patch
@tiptap/extension-text-style Patch
@tiptap/extension-text Patch
@tiptap/extension-typography Patch
@tiptap/extension-underline Patch
@tiptap/extension-youtube Patch
@tiptap/html Patch
@tiptap/pm Patch
@tiptap/react Patch
@tiptap/starter-kit Patch
@tiptap/suggestion Patch
@tiptap/vue-2 Patch
@tiptap/vue-3 Patch

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

Copy link

netlify bot commented Jul 18, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit c734ef0
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/6698ee64d6adf50008b80ad0
😎 Deploy Preview https://deploy-preview-5366--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.

@@ -67,7 +67,7 @@ export const TaskItem = Node.create<TaskItemOptions>({
keepOnSplit: false,
parseHTML: element => element.getAttribute('data-checked') === 'true',

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?

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

Copy link
Contributor Author

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.

image

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

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

Copy link
Contributor Author

@baseballyama baseballyama Jul 18, 2024

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

Copy link
Contributor Author

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

Copy link
Contributor Author

@baseballyama baseballyama Jul 18, 2024

Choose a reason for hiding this comment

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

I believe this works as expected and reflects our consensus.
a5ebc62, c297eee

@baseballyama baseballyama requested a review from nperez0111 July 18, 2024 10:18
Comment on lines 68 to 72
parseHTML: element => {
const dataChecked = element.getAttribute('data-checked')

return dataChecked != null && dataChecked !== 'false'
},

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

Copy link
Contributor Author

@baseballyama baseballyama Jul 18, 2024

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

@baseballyama baseballyama requested a review from nperez0111 July 18, 2024 10:27
Copy link

@nperez0111 nperez0111 left a 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 nperez0111 merged commit e6c759b into ueberdosis:main Jul 18, 2024
14 checks passed
@baseballyama baseballyama deleted the patch-1 branch July 18, 2024 10:33
@baseballyama
Copy link
Contributor Author

baseballyama commented Jul 18, 2024

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

@baseballyama
Copy link
Contributor Author

Thank you for the backmerge to develop @nperez0111!

@nperez0111
Copy link

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.

bdbch pushed a commit that referenced this pull request Jul 31, 2024
…` instead of only when `<li data-checked="true"` (re-fix of #5366) (#5426)

* fix

* changeset
@nperez0111 nperez0111 mentioned this pull request Aug 6, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants