fix(code-block): preserve empty lines in code blocks#420
Open
Jiasm wants to merge 1 commit intovercel:mainfrom
Open
fix(code-block): preserve empty lines in code blocks#420Jiasm wants to merge 1 commit intovercel:mainfrom
Jiasm wants to merge 1 commit intovercel:mainfrom
Conversation
## Summary Fix empty lines collapsing in code blocks by inserting a newline character for empty rows. ## Problem When rendering code blocks with empty lines, the `<span>` elements for empty rows had no content, causing them to collapse to zero height. This affected both visual display and copy behavior. ## Solution Insert `"\n"` for empty lines instead of rendering an empty span. This ensures: - **Visual**: Empty lines maintain proper height - **Copy**: Copied text includes the empty lines correctly ## Changes - `packages/streamdown/lib/code-block/body.tsx`: Add condition to detect empty rows (`row.length === 0` or single token with empty content) and render `"\n"` instead
Contributor
|
@Jiasm is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
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.
Description
Fix empty lines collapsing in code blocks by inserting a newline character for empty rows. Previously, empty lines had no content causing the
<span>elements to collapse to zero height, affecting both visual display and copy behavior.Type of Change
Related Issues
Related to empty line rendering in code blocks
Changes Made
row.length === 0or single token with empty content)"\n"for empty lines instead of rendering an empty spanTesting
Test Coverage
Tested with code containing empty lines to verify:
Screenshots/Demos
Before: Empty lines collapse to zero height
After: Empty lines maintain proper line height and copy correctly
Checklist
pnpm changeset)Changeset
Additional Notes
This is a minimal fix that inserts
"\n"for empty lines. Alternative approaches considered:min-height: 1lh- only fixes visual, doesn't preserve copy behavior\u200B- fixes visual but copies as invisible character, not newline