GeezerVison is showing github.com — fix(shared): nonbreaking spaces no longer end Markdown fences or paragraphs during chunking by saphid · Pull Request #43702 · pingdotgg/t3code
Conversation
Problem
In packages/shared/src/markdownChunks.ts, splitMarkdown uses JavaScript String.prototype.trim() to check whether a line is blank and whether a closing code fence has trailing characters. Because .trim() strips Unicode whitespace such as U+00A0 (nonbreaking space) while the Markdown renderer (@pierre/words) follows CommonMark and treats U+00A0 as content, chunking can split inside a still-open fenced code block, emphasized paragraph, or blank-line HTML block.
Deterministic repro on origin/main (39388dd0d6aebb2de775739b4696249d2f6a2c48):
const md = "```md\n" + "x".repeat(4100) + "\n```\u00a0\n# literal\n```";
const prose = "*" + "x".repeat(4100) + "\n\u00a0\nmore*";
- Observed: Whole-file
@pierre/words keeps # literal inside <pre><code> (no <h1>) and renders prose as one <p><em>...</em></p>. Chunked rendering via splitMarkdown splits both fixtures into 2 chunks, emitting a live <h1>literal</h1> for md and two <p> elements with literal * for prose.
- Expected: U+00A0 remains content in both fixtures; neither splits at the U+00A0 line, and chunked rendering matches whole-file rendering.
Change
Replace .trim() for blank-line detection (closesAtBlankLine and afterBlankLine) and fence-closer suffix checks (blockCloser) in packages/shared/src/markdownChunks.ts with an explicit CommonMark ASCII space/tab check allowing the retained CR of CRLF (const BLANK_LINE = /^[ \t]*\r?$/), checking next.slice(match[0].length) after the matched closing fence. Because web, desktop, and mobile Markdown file previews all consume splitMarkdown from @t3tools/shared/markdownChunks, this single change covers every client surface.
Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
- Base failure (
origin/main 39388dd0d6aebb2de775739b4696249d2f6a2c48): vp test run packages/shared/src/markdownChunks.test.ts -t "nonbreaking" failed with AssertionError: expected [ { …(2) }, …(1) ] to have a length of 1 but got 2.
- Head pass (rebased onto
origin/main bc0f04da94f6 at febf90b4dbdd0e0243ae637b58c2cf4cde62f664): vp test run packages/shared/src/markdownChunks.test.ts passed 3/3 consecutive runs (14/14 tests, including U+00A0 backtick/tilde fence, prose, HTML block, link-definition continuation, and ASCII space/tab + CRLF controls).
- Changed-files gate:
vp run check:changed exited 0 (format, lint, knip, typecheck across 37 packages, and affected tests all passed).
- Before/after
@pierre/words transcript: https://gist.github.com/saphid/ad554c04869e422e618e9e3636276c22
- Not shown: Interactive browser/desktop/mobile UI walkthrough of file preview scrolling was not run; verified directly against
splitMarkdown and the same @pierre/words/core renderer used by FileMarkdownPreview. Cross-provider review via claudeAgent (claude-opus-5-5) returned 503 auth_unavailable, so a self-audit against the diff and checklist was performed instead.
Authored by Gemini 4 Neon (Antigravity).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 26, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
Blank-line and fence-closing detection now uses explicit spaces-and-tabs checks. Tests cover nonbreaking spaces, prose and HTML blocks, and CRLF input.
Changes: Markdown whitespace parsing
| Layer / File(s) |
Summary |
Blank-line and fence parsing packages/shared/src/markdownChunks.ts, packages/shared/src/markdownChunks.test.ts |
Blank-line detection accepts spaces and tabs, optionally followed by \r. Fence closing requires a matching fence character, a length at least equal to the opener, and only blank-line characters afterward. Tests cover nonbreaking spaces and CRLF input. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: juliusmarminge, marve10s
Merge Risk: Minimal · up to f8d22
-
This change keeps nonbreaking spaces from splitting Markdown fences or paragraphs during chunking, which fixes preview rendering for affected content. It is a small change to a pure function with added tests, and no merge-blocking risk was found.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title names the main change: the chunker no longer treats nonbreaking spaces (U+00A0) as blank-line or fence-closing whitespace. It matches the summary, which replaces trim() with an ASCII space/t… |
| Description check |
 |
The description follows the template's main sections. Problem gives the cause (trim() strips U+00A0, while CommonMark treats it as content), a deterministic repro, and expected behavior. Change names … |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Title check
-
Explanation
The title names the main change: the chunker no longer treats nonbreaking spaces (U+00A0) as blank-line or fence-closing whitespace. It matches the summary, which replaces trim() with an ASCII space/tab check in markdownChunks.ts. It is a conventional commit title in plain language, and it is specific enough for a teammate scanning history.
Full details: Description check
-
Explanation
The description follows the template's main sections. Problem gives the cause (trim() strips U+00A0, while CommonMark treats it as content), a deterministic repro, and expected behavior. Change names the replaced checks and the new BLANK_LINE regex. Scope says it is a small bug fix and that no issue is needed. Verification lists focused test runs, a failing base run, a passing head run, the check:changed gate, and what was not checked (interactive UI walkthrough). The template's optional agent-model line is present. The description is detailed and complete, so it passes.
Finishing Touches
-
Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
-
Run configuration
-
Commits
-
Reviewing files that changed from the base of the PR and between febf90b and f8d229c.
Files selected for processing: 1
-
packages/shared/src/markdownChunks.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:S
10-29 changed lines (additions + deletions).
vouch:trusted
Author is trusted by repo permissions or the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|