Skip to content

Trim trailing whitespace and empty blocks from comments, descriptions and docs - #840

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
sebathi:fix/trim-trailing-whitespace-content
Dec 1, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
sebathi:fix/trim-trailing-whitespace-content

Conversation

@sebathi

@sebathi sebathi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

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.getBlocks only removed the single trailing empty block the editor keeps, never a second one and never trailing whitespace inside the last text run.
  • DescriptionSection.save and DocEditor.save treated 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 trimTrailingContent helper in comment-blocknote.tsx:

  • drops every trailing block that holds only whitespace,
  • right-trims the last text inline of the last remaining block (spaces, tabs and line breaks),
  • recurses into nested children so the last item of a nested list is trimmed too.

Blocks without text content (images, files, mermaid, annotation cards, tables) are never considered empty: only built-in text block types with an empty content array can be dropped, since mermaid and annotationCard are normalized with content: [] 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.ts covering 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 . and tsc --noEmit pass in apps/web.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ 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 — trimTrailingContent drops 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.save and DocEditor.save now use it, saving null when the content is empty after trimming.
  • Comment display — CommentDisplay trims stored blocks before replaceBlocks, 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Non-text block guard — isEmptyTextBlock now checks TEXT_BLOCK_TYPES before looking at content, and trimBlockEnd skips 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 content is returned unchanged.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 64e20bc into Paca-AI:master Dec 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants