Repository navigation
Trim trailing whitespace and empty blocks from comments, descriptions and docs - #840
Merged
pikann merged 2 commits intoDec 1, 2026
Merged
Conversation
Comments, task descriptions and docs saved whatever the BlockNote editor held, including a trailing space in the last text run and any number of empty paragraphs after the content. The editor renders with pre-wrap, so that whitespace showed up as a visible gap after every such comment or description. Replace the one-block strip in the comment editor with a shared trimTrailingContent helper that drops every trailing whitespace-only text block and right-trims the last text inline, recursing into nested children. Blocks without text content (images, files, mermaid, annotation cards, tables) and trailing mentions or links are left untouched, as is the space between a mention and the text after it. Apply it when a comment is sent, when a description or doc is saved, and when a stored comment is displayed, so content saved before this change renders without the gap too.
Contributor
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline.
Approach: sound — a single shared helper replaces the previous one-block strip and runs at every save site plus the comment display path, so new saves and old stored comments both render without the trailing gap.
Reviewed changes
- Shared trim helper —
trimTrailingContentdrops trailing whitespace-only text blocks, right-trims the last text inline, and recurses into the last block's children; media/custom blocks and trailing mentions/references are preserved. - Save sites —
CommentEditor.getBlocks,DescriptionSection.saveandDocEditor.savenow use it, savingnullwhen the content is empty after trimming. - Comment display —
CommentDisplaytrims stored blocks beforereplaceBlocks, so comments saved before this change lose the gap too. - Tests — 12 unit cases cover whitespace runs, multiple empty blocks, mention spacing, media blocks, nested children and the all-whitespace case.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
Check the block type before anything else in isEmptyTextBlock and skip inline trimming for non-text blocks in trimBlockEnd, so a custom block is left exactly as stored whatever its content holds. Avoid adding an undefined children key to blocks that had none.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Non-text block guard —
isEmptyTextBlocknow checksTEXT_BLOCK_TYPESbefore looking atcontent, andtrimBlockEndskips inline trimming entirely for non-text blocks, so custom blocks (mermaid,annotationCard) survive with their content untouched. - Regression test — new case asserts a custom block with whitespace-only
contentis returned unchanged.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
approved these changes
Dec 1, 2026
pikann
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀
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.

Problem
A trailing space (or a trailing line break) typed at the end of a comment or a task description is saved as-is, and so are empty paragraphs left after the content. BlockNote renders inline text with
white-space: pre-wrap, so the saved comment shows a visible gap after the text. Nothing on the save path trimmed it:CommentEditor.getBlocksonly removed the single trailing empty block the editor keeps, never a second one and never trailing whitespace inside the last text run.DescriptionSection.saveandDocEditor.savetreated the content as empty only when it was exactly one empty paragraph, and saved everything else untouched.Fix
Replace the one-block strip with a shared
trimTrailingContenthelper incomment-blocknote.tsx:Blocks without text content (images, files, mermaid, annotation cards, tables) are never considered empty: only built-in text block types with an empty
contentarray can be dropped, sincemermaidandannotationCardare normalized withcontent: []on load. Only a trailing text inline is trimmed, so a mention at the end of a block, and the space between a mention and the text after it, stay as they are.The helper runs when a comment is sent, when a description or doc is saved, and when a stored comment is displayed in
CommentDisplay, so comments saved before this change render without the gap as well.Tests
12 new vitest cases in
comment-blocknote.test.tscovering trailing space, multiple empty paragraphs, mention followed by text, trailing mention, whitespace-only runs, trailing line break, trailing image/mermaid blocks, nested children and the all-whitespace case.vitest run(189 files, 1957 tests),biome check .andtsc --noEmitpass inapps/web.