[PR #23451] [CLOSED] fix: preserve blank lines in code blocks when submitting messages #66056

Closed
opened 2026-05-06 12:09:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23451
Author: @weyseing
Created: 4/6/2026
Status: Closed

Base: devHead: fix/preserve-codeblock-newlines


📝 Commits (1)

  • 743eef5 fix: preserve blank lines in code blocks when submitting messages

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 src/lib/components/chat/Chat.svelte (+2 -2)

📄 Description

Summary

  • Removed .replaceAll('\n\n', '\n') from both on:submit handlers in Chat.svelte that blindly stripped all double newlines from message content before passing it to submitHandler
  • This was destroying intentional blank lines inside code blocks (and elsewhere), causing pasted/typed code to lose its formatting after submission

Steps to Reproduce (before fix)

  1. Open a chat and type a message containing a code block with blank lines:
    ```python
    def hello():
        print("hello")
    
        x = 1
    
        return x
    ```
    
  2. Send the message
  3. Bug: The blank lines inside the code block disappear — the code is collapsed together

Root Cause

In src/lib/components/chat/Chat.svelte, both submit handlers (lines 2954 and 2997) called:

submitHandler(e.detail.replaceAll('\n\n', '\n'));

This replaced all double newlines with single newlines across the entire message — including inside code blocks where blank lines are semantically meaningful.

Fix

Pass e.detail directly to submitHandler without stripping newlines:

submitHandler(e.detail);

Testing

  • Verified code blocks with blank lines are preserved after sending
  • Verified normal messages still work correctly
  • Tested with Ollama (llama3.2) via Docker Compose

Fixes #20302



🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/23451 **Author:** [@weyseing](https://github.com/weyseing) **Created:** 4/6/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/preserve-codeblock-newlines` --- ### 📝 Commits (1) - [`743eef5`](https://github.com/open-webui/open-webui/commit/743eef55a5df40d65dfdaf0629f81e2d1a2cf47b) fix: preserve blank lines in code blocks when submitting messages ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/chat/Chat.svelte` (+2 -2) </details> ### 📄 Description ## Summary - Removed `.replaceAll('\n\n', '\n')` from both `on:submit` handlers in `Chat.svelte` that blindly stripped all double newlines from message content before passing it to `submitHandler` - This was destroying intentional blank lines inside code blocks (and elsewhere), causing pasted/typed code to lose its formatting after submission ## Steps to Reproduce (before fix) 1. Open a chat and type a message containing a code block with blank lines: ```` ```python def hello(): print("hello") x = 1 return x ``` ```` 2. Send the message 3. **Bug:** The blank lines inside the code block disappear — the code is collapsed together ## Root Cause In `src/lib/components/chat/Chat.svelte`, both submit handlers (lines 2954 and 2997) called: ```javascript submitHandler(e.detail.replaceAll('\n\n', '\n')); ``` This replaced **all** double newlines with single newlines across the entire message — including inside code blocks where blank lines are semantically meaningful. ## Fix Pass `e.detail` directly to `submitHandler` without stripping newlines: ```javascript submitHandler(e.detail); ``` ## Testing - Verified code blocks with blank lines are preserved after sending - Verified normal messages still work correctly - Tested with Ollama (llama3.2) via Docker Compose Fixes #20302 --- - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 12:09:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#66056