[GH-ISSUE #20302] issue: Newlines in Codeblocks Mysteriously Disappear #34675

Closed
opened 2026-04-25 08:46:09 -05:00 by GiteaMirror · 12 comments
Owner

Originally created by @mherreshoff on GitHub (Dec 31, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/20302

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.6.43

Ollama Version (if applicable)

No response

Operating System

Mac OS Tahoe 26.2

Browser (if applicable)

Firefox, 146.0.1 (aarch64)

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

When submitting a prompt containing a code block, the contents of the code block should appear verbatim in the chat log after pressing enter (and presumably should also be sent to the LLM verbatim). Its displayed line numbers should match those of the text file it was pasted from.

Actual Behavior

Blank lines mysteriously disappear from the code block. The line numbers displayed in the code block after hitting enter are also no longer correct.

Steps to Reproduce

Instructions

  1. Download a copy of the open-webui repository on a mac with docker installed (though I imagine this problem is likely not platform specific). The main branch should be checked out. Launch the client with ./run-compose.sh. This gives us a fresh instance of OpenWebUI. When I ran this, the main branch was at a7271532f8a38da46785afcaa7e65f9a45e7d753, where v0.6.43 was merged in.
  2. Add an OpenAI API key in the connections settings in the admin panel and start a chat (on my machine the model defaulted to gpt-4-0613, though I doubt this matters.)
  3. Create a codeblock (by typing the back tick key three times, followed by pressing enter) within the chat.
  4. Paste in a block of code containing at least one blank line
  5. Press enter

The blank lines will vanish from the chat log.

Example Code Block For Testing

def square(x):
    return x * x

def _mag(v):
   return sum(map(square, v))

Logs & Screenshots

Screenshot from before pressing enter:

Image

Screenshot after pressing enter

Image

Note that if code were being preserved verbatim, there would be five lines, and line three should be blank.

Screenshot of console logs

Image

(Nothing seems especially amiss here)

Container Logs

open_webui_container_logs.txt

Notes: Nothing seems to have gone wrong here either. I think the permissions error is unrelated, and was caused by me leaving one of my old browser windows open.

Additional Information

I searched through the existing issues and conversations as requested. The closest issues I found were:

Originally created by @mherreshoff on GitHub (Dec 31, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/20302 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.6.43 ### Ollama Version (if applicable) _No response_ ### Operating System Mac OS Tahoe 26.2 ### Browser (if applicable) Firefox, 146.0.1 (aarch64) ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior When submitting a prompt containing a code block, the contents of the code block should appear verbatim in the chat log after pressing enter (and presumably should also be sent to the LLM verbatim). Its displayed line numbers should match those of the text file it was pasted from. ### Actual Behavior Blank lines mysteriously disappear from the code block. The line numbers displayed in the code block after hitting enter are also no longer correct. ### Steps to Reproduce ## Instructions 1. Download a copy of the open-webui repository on a mac with docker installed (though I imagine this problem is likely not platform specific). The `main` branch should be checked out. Launch the client with `./run-compose.sh`. This gives us a fresh instance of OpenWebUI. When I ran this, the `main` branch was at `a7271532f8a38da46785afcaa7e65f9a45e7d753`, where v0.6.43 was merged in. 2. Add an OpenAI API key in the connections settings in the admin panel and start a chat (on my machine the model defaulted to `gpt-4-0613`, though I doubt this matters.) 3. Create a codeblock (by typing the back tick key three times, followed by pressing enter) within the chat. 4. Paste in a block of code containing at least one blank line 5. Press enter The blank lines will vanish from the chat log. ## Example Code Block For Testing ``` def square(x): return x * x def _mag(v): return sum(map(square, v)) ``` ### Logs & Screenshots ## Screenshot from before pressing enter: <img width="1069" height="844" alt="Image" src="https://github.com/user-attachments/assets/ce3cfc42-544f-4090-a6d2-c40b7dff1183" /> ## Screenshot after pressing enter <img width="1061" height="614" alt="Image" src="https://github.com/user-attachments/assets/dd0d9b4c-69ae-46ce-b28b-81b921dd1741" /> Note that if code were being preserved verbatim, there would be five lines, and line three should be blank. ## Screenshot of console logs <img width="821" height="178" alt="Image" src="https://github.com/user-attachments/assets/9d1f7af5-d523-4eee-961d-8e2545d0e6d9" /> (Nothing seems especially amiss here) ## Container Logs [open_webui_container_logs.txt](https://github.com/user-attachments/files/24398008/open_webui_container_logs.txt) Notes: Nothing seems to have gone wrong here either. I think the permissions error is unrelated, and was caused by me leaving one of my old browser windows open. ### Additional Information I searched through the existing issues and conversations as requested. The closest issues I found were: * https://github.com/open-webui/open-webui/discussions/6539 reports a similar issue, but it did not mention code blocks which seem more important to preserve verbatim than user-formatted rich-text. * https://github.com/open-webui/open-webui/issues/17839 might be distantly related if the way it was fixed involved removing newlines too aggressively (though probably not, since this bug happens after the submit button is pressed.)
GiteaMirror added the bugconfirmed issue labels 2026-04-25 08:46:09 -05:00
Author
Owner

@owui-terminator[bot] commented on GitHub (Dec 31, 2025):

🔍 Similar Issues Found

I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions:

  1. #19370 issue: new lines from CLIPBOARD problems on Windows
    by daniporr • Nov 21, 2025 • bug

  2. #20092 issue:
    by VideoRyan • Dec 22, 2025 • bug

  3. #20019 issue:
    by j63440490 • Dec 17, 2025 • bug

  4. #19861 issue:
    by QuitHub • Dec 10, 2025 • bug

  5. #19864 issue:
    by Haervwe • Dec 10, 2025 • bug

Show 5 more related issues
  1. #19777 issue:
    by Yaute7 • Dec 05, 2025 • bug

  2. #20046 issue:
    by pierrelouisbescond • Dec 19, 2025 • bug

  3. #19563 issue:
    by naruto7g • Nov 28, 2025 • bug

  4. #18922 issue: When code is present in the return output, the dialog box does not use code blocks.
    by pureGavin • Nov 04, 2025 • bug

  5. #16380 issue: Line breaks in tables are not rendered
    by superjamie • Aug 08, 2025 • bug


💡 Tips:

  • If this is a duplicate, please consider closing this issue and adding any additional details to the existing one
  • If you found a solution in any of these issues, please share it here to help others

This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.

<!-- gh-comment-id:3702970126 --> @owui-terminator[bot] commented on GitHub (Dec 31, 2025): 🔍 **Similar Issues Found** I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions: 1. [#19370](https://github.com/open-webui/open-webui/issues/19370) **issue: new lines from CLIPBOARD problems on Windows** *by daniporr • Nov 21, 2025 • `bug`* 2. [#20092](https://github.com/open-webui/open-webui/issues/20092) **issue:** *by VideoRyan • Dec 22, 2025 • `bug`* 3. [#20019](https://github.com/open-webui/open-webui/issues/20019) **issue:** *by j63440490 • Dec 17, 2025 • `bug`* 4. [#19861](https://github.com/open-webui/open-webui/issues/19861) **issue:** *by QuitHub • Dec 10, 2025 • `bug`* 5. [#19864](https://github.com/open-webui/open-webui/issues/19864) **issue:** *by Haervwe • Dec 10, 2025 • `bug`* <details> <summary>Show 5 more related issues</summary> 6. [#19777](https://github.com/open-webui/open-webui/issues/19777) **issue:** *by Yaute7 • Dec 05, 2025 • `bug`* 7. [#20046](https://github.com/open-webui/open-webui/issues/20046) **issue:** *by pierrelouisbescond • Dec 19, 2025 • `bug`* 8. [#19563](https://github.com/open-webui/open-webui/issues/19563) **issue:** *by naruto7g • Nov 28, 2025 • `bug`* 9. [#18922](https://github.com/open-webui/open-webui/issues/18922) **issue: When code is present in the return output, the dialog box does not use code blocks.** *by pureGavin • Nov 04, 2025 • `bug`* 10. [#16380](https://github.com/open-webui/open-webui/issues/16380) **issue: Line breaks in tables are not rendered** *by superjamie • Aug 08, 2025 • `bug`* </details> --- 💡 **Tips:** - If this is a duplicate, please consider closing this issue and adding any additional details to the existing one - If you found a solution in any of these issues, please share it here to help others *This comment was generated automatically by a bot.* Please react with a 👍 if this comment was helpful, or a 👎 if it was not.
Author
Owner

@mherreshoff commented on GitHub (Dec 31, 2025):

Of the issues the owui-terminator bot surfaced, https://github.com/open-webui/open-webui/issues/19370 seems like the only related one. However, I doubt that fix will have any effect in this case since I tested this on a mac, and macs do not use CRLF newlines.

<!-- gh-comment-id:3702978318 --> @mherreshoff commented on GitHub (Dec 31, 2025): Of the issues the `owui-terminator` bot surfaced, https://github.com/open-webui/open-webui/issues/19370 seems like the only related one. However, I doubt that fix will have any effect in this case since I tested this on a mac, and macs do not use CRLF newlines.
Author
Owner

@dannyl1u commented on GitHub (Jan 1, 2026):

Can confirm I can reproduce this issue on MacOS

<!-- gh-comment-id:3703288300 --> @dannyl1u commented on GitHub (Jan 1, 2026): Can confirm I can reproduce this issue on MacOS
Author
Owner

@dannyl1u commented on GitHub (Jan 1, 2026):

Additional context: this occurs for regular text as well, not just code block

<!-- gh-comment-id:3703292611 --> @dannyl1u commented on GitHub (Jan 1, 2026): Additional context: this occurs for regular text as well, not just code block
Author
Owner

@silentoplayz commented on GitHub (Jan 1, 2026):

I am not able to reproduce this issue myself on Firefox or Chrome using the latest dev commit on Ubuntu.

<!-- gh-comment-id:3703803854 --> @silentoplayz commented on GitHub (Jan 1, 2026): I am not able to reproduce this issue myself on Firefox or Chrome using the latest `dev` commit on Ubuntu.
Author
Owner

@dannyl1u commented on GitHub (Jan 3, 2026):

The submission handler replaces double newlines (\n\n) and replaces them with single newlines (\n) for all content
a7271532f8/src/lib/components/chat/Chat.svelte (L2541)

this results in a user message like:

hello


world

gets sent to backend (e.g. OpenAI API) as

hello

world

Checking if settings.richTextInput === true here would fix that, seems like this was the original behavior but was removed in 153afd832c (diff-c867e0c9c90c94b02a2de567f2210ca9e600180d8fa3d6b121c7eb54da39a4edL2382)
I believe we can still check if settings.richTextInput === true here for newline stripping while preserving the intention to deprecate textarea input.

For code blocks, the Markdown renderer further collapses multiple newlines in the UI.
In Markdown.svelte, breaks: true is set,
a7271532f8/src/lib/components/chat/Messages/Markdown.svelte (L40)
however, per the docs, this only controls single newlines
https://marked.js.org/using_advanced?utm_source=chatgpt.com#:~:text=If%20true%2C%20add%20%3Cbr%3E%20on%20a%20single%20line%20break%20(copies%20GitHub%20behavior%20on%20comments%2C%20but%20not%20on%20rendered%20markdown%20files).%20Requires%20gfm%20be%20true.

@tjbck let me know if a PR is welcome/wanted here.

@silentoplayz can you reproduce the issue in https://github.com/open-webui/open-webui/discussions/6539 ?

<!-- gh-comment-id:3706780980 --> @dannyl1u commented on GitHub (Jan 3, 2026): The submission handler replaces double newlines (\n\n) and replaces them with single newlines (\n) for all content https://github.com/open-webui/open-webui/blob/a7271532f8a38da46785afcaa7e65f9a45e7d753/src/lib/components/chat/Chat.svelte#L2541 this results in a user message like: ``` hello world ``` gets sent to backend (e.g. OpenAI API) as ``` hello world ``` Checking if `settings.richTextInput === true` here would fix that, seems like this was the original behavior but was removed in https://github.com/open-webui/open-webui/commit/153afd832ccd12a1e5fd99b085008d080872c161#diff-c867e0c9c90c94b02a2de567f2210ca9e600180d8fa3d6b121c7eb54da39a4edL2382 I believe we can still check if `settings.richTextInput === true` here for newline stripping while preserving the intention to deprecate textarea input. For code blocks, the Markdown renderer further collapses multiple newlines in the UI. In Markdown.svelte, `breaks: true` is set, https://github.com/open-webui/open-webui/blob/a7271532f8a38da46785afcaa7e65f9a45e7d753/src/lib/components/chat/Messages/Markdown.svelte#L40 however, per the docs, this only controls **single** newlines https://marked.js.org/using_advanced?utm_source=chatgpt.com#:~:text=If%20true%2C%20add%20%3Cbr%3E%20on%20a%20single%20line%20break%20(copies%20GitHub%20behavior%20on%20comments%2C%20but%20not%20on%20rendered%20markdown%20files).%20Requires%20gfm%20be%20true. @tjbck let me know if a PR is welcome/wanted here. @silentoplayz can you reproduce the issue in https://github.com/open-webui/open-webui/discussions/6539 ?
Author
Owner

@Classic298 commented on GitHub (Jan 3, 2026):

If you plan on doing a PR, good luck with that. I have tried many times to fix styling errors in the messageinput and richtextinput frontend files. Dozens of hours wasted in total to no avail. When you fix one thing, another breaks. Before submitting your changes as a PR, make sure you thoroughly test it locally in many different scenarios

<!-- gh-comment-id:3706917891 --> @Classic298 commented on GitHub (Jan 3, 2026): If you plan on doing a PR, good luck with that. I have tried many times to fix styling errors in the messageinput and richtextinput frontend files. Dozens of hours wasted in total to no avail. When you fix one thing, another breaks. Before submitting your changes as a PR, make sure you thoroughly test it locally in many different scenarios
Author
Owner

@rgaricano commented on GitHub (Jan 3, 2026):

try changing this function:
6f1486ffd0/src/lib/components/common/RichTextInput.svelte (L418-L452)

<!-- gh-comment-id:3706925625 --> @rgaricano commented on GitHub (Jan 3, 2026): try changing this function: https://github.com/open-webui/open-webui/blob/6f1486ffd0cb288d0e21f41845361924e0d742b3/src/lib/components/common/RichTextInput.svelte#L418-L452
Author
Owner

@Classic298 commented on GitHub (Jan 3, 2026):

I will not try changing anything anymore. I will not touch the messageinput or richtextinput anymore with a 10ft poll

If you want you can do it @rgaricano

Good luck fixing it without breaking something else.

I tried to fix this very issue and #20198 for the past days but couldn't find a solution that didn't break something else.

You need to keep up GitHub Markdown support, Rich text support with it enabled or disabled, if you fix #20198 then you will lose the newlines again even outside of a codeblock

It's horrendous to fix it

<!-- gh-comment-id:3706926630 --> @Classic298 commented on GitHub (Jan 3, 2026): I will not try changing anything anymore. I will not touch the messageinput or richtextinput anymore with a 10ft poll If you want you can do it @rgaricano Good luck fixing it without breaking something else. I tried to fix this very issue and #20198 for the past days but couldn't find a solution that didn't break something else. You need to keep up GitHub Markdown support, Rich text support with it enabled or disabled, if you fix #20198 then you will lose the newlines again even outside of a codeblock It's horrendous to fix it
Author
Owner

@silentoplayz commented on GitHub (Jan 3, 2026):

@dannyl1u Negative. I am not able to reproduce https://github.com/open-webui/open-webui/discussions/6539.

I can reproduce https://github.com/open-webui/open-webui/issues/20198 though.

<!-- gh-comment-id:3706930155 --> @silentoplayz commented on GitHub (Jan 3, 2026): @dannyl1u Negative. I am **not** able to reproduce https://github.com/open-webui/open-webui/discussions/6539. I **can** reproduce https://github.com/open-webui/open-webui/issues/20198 though.
Author
Owner

@rgaricano commented on GitHub (Jan 3, 2026):

@Classic298
I was thinking more about @dannyl1u than you making the changes.

I don't know if I'm goint to have time to spend on that, my personal situation has changed radically and I have to make a decision between continuing to program or picking up a pick and shovel and dedicating myself to agricultural work in the countryside and to trees.

Also, since my system is very limited, it's difficult for me to work on several branches simultaneously (that's why I'm leaving reference notes instead of making a proposal and testing it).

In any case, I know it's problematic to work with codeblocks; they have the auto-rendering mechanism and frequent race collisions. I still have a pending proposal with the Mermaid and Vega diagrams; it's functional but has a small problem associated with this rendering configuration.

<!-- gh-comment-id:3707063543 --> @rgaricano commented on GitHub (Jan 3, 2026): @Classic298 I was thinking more about @dannyl1u than you making the changes. I don't know if I'm goint to have time to spend on that, my personal situation has changed radically and I have to make a decision between continuing to program or picking up a pick and shovel and dedicating myself to agricultural work in the countryside and to trees. Also, since my system is very limited, it's difficult for me to work on several branches simultaneously (that's why I'm leaving reference notes instead of making a proposal and testing it). In any case, I know it's problematic to work with codeblocks; they have the auto-rendering mechanism and frequent race collisions. I still have a pending proposal with the Mermaid and Vega diagrams; it's functional but has a small problem associated with this rendering configuration.
Author
Owner

@tjbck commented on GitHub (Apr 17, 2026):

Addressed in dev.

<!-- gh-comment-id:4265801525 --> @tjbck commented on GitHub (Apr 17, 2026): Addressed in dev.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#34675