Fixed HTML rendered including empty trailing paragraphs#637
Open
ronaldlangeveld wants to merge 7 commits intobasecamp:mainfrom
Open
Fixed HTML rendered including empty trailing paragraphs#637ronaldlangeveld wants to merge 7 commits intobasecamp:mainfrom
ronaldlangeveld wants to merge 7 commits intobasecamp:mainfrom
Conversation
ref basecamp#441 - Added `normalizeEmptyContent` helper function to convert Lexical's default `<p><br></p>` (used for empty editor content to maintain `contentEditable` functionality) into an empty string, preventing unwanted HTML from being submitted to the server. - Updated the value `getter` in `src/elements/editor.js` to apply this normalization after sanitizing the generated HTML, ensuring clean data persistence without breaking editor usability. - This fix addresses the issue where empty editors would submit `<p><br></p>` instead of an empty string, improving data integrity and user experience by avoiding meaningless HTML storage in Action Text fields.
…y into fix-empty-paragraph
Collaborator
samuelpecher
left a comment
There was a problem hiding this comment.
Thanks for the PR! I like the direct approach vs checking the node state.
I've left a few comments to just touch up the code in line with our conventions.
src/elements/editor.js
Outdated
Comment on lines
175
to
177
| this.cachedValue = normalizeEmptyContent( | ||
| sanitize($generateHtmlFromNodes(this.editor, null)) | ||
| ) |
Collaborator
There was a problem hiding this comment.
I think the unnested route is clearer here
Suggested change
| this.cachedValue = normalizeEmptyContent( | |
| sanitize($generateHtmlFromNodes(this.editor, null)) | |
| ) | |
| const html = sanitize($generateHtmlFromNodes(this.editor, null)) | |
| this.cachedValue = normalizeEmptyContent(html) |
Collaborator
There was a problem hiding this comment.
This be rolled into HTML helpers file, or sanitization. We can keep it terse without the documentation, the intent is nice and clear.
test/javascript/editor/value.test.js
Outdated
Collaborator
There was a problem hiding this comment.
I'd lean towards dropping the unit test and relying on one ruby system test.
Author
|
Thank you so much for the thorough feedback @samuelpecher . Let me know if there's anything else I can do, happy to help. |
5df154f to
ceb54d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref #441
Added
normalizeEmptyContenthelper function to convert Lexical's default<p><br></p>(used for empty editor content to maintaincontentEditablefunctionality) into an empty string, preventing unwanted HTML from being submitted to the server.Updated the value
getterinsrc/elements/editor.jsto apply this normalization after sanitizing the generated HTML, ensuring clean data persistence without breaking editor usability.This fix addresses the issue where empty editors would submit
<p><br></p>instead of an empty string, improving data integrity and user experience by avoiding meaningless HTML storage in Action Text fields.Follows knowledge from my previous work on Ghost's Lexical Editor :)