[GH-ISSUE #11895] issue: Syntax Highlighting is being apply on every change #16393

Closed
opened 2026-04-19 22:19:29 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @gaby on GitHub (Mar 20, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/11895

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Git Clone

Open WebUI Version

0.5.20

Ollama Version (if applicable)

No response

Operating System

Ubuntu 24.04

Browser (if applicable)

Firefox

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 listed steps to reproduce the bug in detail.

Expected Behavior

When dealing with large code bases the UI should get all the content first then apply syntax highlighting. Instead of trying to apply it for every single response change.

ChatGPT for example will start rendering in the chat with no syntax highlight. It will then apply it after rendering the full response.

Actual Behavior

In a chat with large code bases the UI will take a long time to render the response. In some cases up to 30-60s after the GPU has finished.

Upon checking, I believe this is caused by the ContentRendering being applied on every change when processing response content.

The call is here: https://github.com/open-webui/open-webui/blob/main/src/lib/components/chat/Messages/Markdown.svelte#L36

Using o3-mini-high, one solution would be to debounce this:

$: (async () => {
	if (content) {
		tokens = marked.lexer(
			replaceTokens(processResponseContent(content), sourceIds, model?.name, $user?.name)
		);
	}
})();

to one that debounces the parsing:

<script>
	import { marked } from 'marked';
	import { replaceTokens, processResponseContent } from '$lib/utils';
	import { user } from '$lib/stores';
	import markedExtension from '$lib/utils/marked/extension';
	import markedKatexExtension from '$lib/utils/marked/katex-extension';
	import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
	import { createEventDispatcher, onDestroy } from 'svelte';

	const dispatch = createEventDispatcher();

	export let id;
	export let content;
	export let model = null;
	export let save = false;
	export let sourceIds = [];
	export let onSourceClick = () => {};
	export let onTaskClick = () => {};

	let tokens = [];

	const options = { throwOnError: false };

	marked.use(markedKatexExtension(options));
	marked.use(markedExtension(options));

	let debounceTimeout;

	// Debounce the markdown processing so that we only re-parse once content stops changing
	$: {
		// Clear any pending timeout if content changes
		clearTimeout(debounceTimeout);
		if (content) {
			debounceTimeout = setTimeout(() => {
				tokens = marked.lexer(
					replaceTokens(processResponseContent(content), sourceIds, model?.name, $user?.name)
				);
			}, 300);
		} else {
			tokens = [];
		}
	}

	onDestroy(() => {
		clearTimeout(debounceTimeout);
	});
</script>

{#key id}
	<MarkdownTokens
		{tokens}
		{id}
		{save}
		{onTaskClick}
		{onSourceClick}
		on:update={(e) => {
			dispatch('update', e.detail);
		}}
		on:code={(e) => {
			dispatch('code', e.detail);
		}}
	/>
{/key}

Steps to Reproduce

N/a

Logs & Screenshots

N/a

Additional Information

N/a

Originally created by @gaby on GitHub (Mar 20, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/11895 ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [x] I am using the latest version of Open WebUI. ### Installation Method Git Clone ### Open WebUI Version 0.5.20 ### Ollama Version (if applicable) _No response_ ### Operating System Ubuntu 24.04 ### Browser (if applicable) Firefox ### 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 listed steps to reproduce the bug in detail. ### Expected Behavior When dealing with large code bases the UI should get all the content first then apply syntax highlighting. Instead of trying to apply it for every single response change. ChatGPT for example will start rendering in the chat with no syntax highlight. It will then apply it after rendering the full response. ### Actual Behavior In a chat with large code bases the UI will take a long time to render the response. In some cases up to 30-60s after the GPU has finished. Upon checking, I believe this is caused by the ContentRendering being applied on every change when processing response content. The call is here: https://github.com/open-webui/open-webui/blob/main/src/lib/components/chat/Messages/Markdown.svelte#L36 Using `o3-mini-high`, one solution would be to debounce this: ```svelte $: (async () => { if (content) { tokens = marked.lexer( replaceTokens(processResponseContent(content), sourceIds, model?.name, $user?.name) ); } })(); to one that debounces the parsing: <script> import { marked } from 'marked'; import { replaceTokens, processResponseContent } from '$lib/utils'; import { user } from '$lib/stores'; import markedExtension from '$lib/utils/marked/extension'; import markedKatexExtension from '$lib/utils/marked/katex-extension'; import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; import { createEventDispatcher, onDestroy } from 'svelte'; const dispatch = createEventDispatcher(); export let id; export let content; export let model = null; export let save = false; export let sourceIds = []; export let onSourceClick = () => {}; export let onTaskClick = () => {}; let tokens = []; const options = { throwOnError: false }; marked.use(markedKatexExtension(options)); marked.use(markedExtension(options)); let debounceTimeout; // Debounce the markdown processing so that we only re-parse once content stops changing $: { // Clear any pending timeout if content changes clearTimeout(debounceTimeout); if (content) { debounceTimeout = setTimeout(() => { tokens = marked.lexer( replaceTokens(processResponseContent(content), sourceIds, model?.name, $user?.name) ); }, 300); } else { tokens = []; } } onDestroy(() => { clearTimeout(debounceTimeout); }); </script> {#key id} <MarkdownTokens {tokens} {id} {save} {onTaskClick} {onSourceClick} on:update={(e) => { dispatch('update', e.detail); }} on:code={(e) => { dispatch('code', e.detail); }} /> {/key} ``` ### Steps to Reproduce N/a ### Logs & Screenshots N/a ### Additional Information N/a
GiteaMirror added the bug label 2026-04-19 22:19:29 -05:00
Author
Owner

@gaby commented on GitHub (Mar 20, 2025):

The solution from o3 is a band-aid. In reality syntax highlight should be applied after response rendering has completed.

<!-- gh-comment-id:2739133341 --> @gaby commented on GitHub (Mar 20, 2025): The solution from o3 is a band-aid. In reality syntax highlight should be applied after response rendering has completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#16393