Skip to content

fix(shared): nonbreaking spaces no longer end Markdown fences or paragraphs during chunking - #43702

Merged
juliusmarminge merged 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-12692943de
Nov 26, 2026
Merged

juliusmarminge merged 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-12692943de

Conversation

@saphid

@saphid saphid commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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)

  • Create a new PR
  • 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.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 26, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Real web app, Chromium, 1280×800, light theme, fresh synthetic state on each commit.

Steps: Render a fenced file with 4,100 x characters followed by a fence plus U+00A0 and # literal; render prose with 4,100 x characters and emphasis spanning a U+00A0-only line. Repeat with four-character controls. Scroll to the affected endings.

Case Before After
Commit d8a52dda31 f8d229cba3
Long fence Before: literal becomes a heading outside the fence After: # literal remains inside one code block
Long prose Before: prose loses emphasis and ends with literal more* After: prose remains emphasized through more
Short fence control Before: short fence renders correctly After: short fence renders correctly
Short prose control Before: short prose retains emphasis After: short prose retains emphasis

Scenario source · Before recording · After recording

The scenario fails on base and passes on head; both short controls pass on both.

Not shown:

  • Blank-line-terminated HTML blocks and reference-definition collection were not exercised; the scenario covers the supplied fence and paragraph reproductions.
  • Mobile and the Electron shell were not run; evidence covers the real web client.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 26, 2026
@juliusmarminge
juliusmarminge merged commit a066eb0 into pingdotgg:main Nov 26, 2026
60 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 26, 2026
github-actions Bot pushed a commit to Ryoku-dev/hyakki that referenced this pull request Nov 26, 2026
…graphs during chunking (pingdotgg#43702)

Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
(cherry picked from commit a066eb0)
github-actions Bot pushed a commit to Ryoku-dev/hyakki that referenced this pull request Nov 26, 2026
…graphs during chunking (pingdotgg#43702)

Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
(cherry picked from commit a066eb0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants