Skip to content

feat(markdown-renderer): complete unfinished code blocks during streaming#1814

Draft
Killusions wants to merge 3 commits intomainfrom
feat/markdown-renderer-streaming
Draft

feat(markdown-renderer): complete unfinished code blocks during streaming#1814
Killusions wants to merge 3 commits intomainfrom
feat/markdown-renderer-streaming

Conversation

@Killusions
Copy link
Copy Markdown
Member

@Killusions Killusions commented Apr 2, 2026

Merge after #1810 and #1811

Add temporary closing marker logic that automatically completes unfinished code blocks during streaming (to make it more smooth)


Documentation.
Examples.
Dashboards Demo.
Playwright report.

Coverage Reports:

Code Coverage

Add max-inline-size constraint to message bubble and wrapper to prevent
overflow. Fix attachment preview backdrop click behavior. Use index-based
tracking for message list and add scroll-to-bottom on message send.
Update example action labels for clarity.
…line and caching

Rewrite the markdown renderer to use a recursive processing pipeline with
placeholder-based architecture. Add SSR support via optional doc/isBrowser
parameters. Introduce LRU caching for code blocks and tables. Improve
table rendering with proper thead/th support. Add code-wrapper structure
with language labels. Update SCSS for new structural layout including
code-wrapper, table-wrapper, and table-scroll-container.
…ming

Add temporary closing marker logic that automatically completes
unfinished code blocks during streaming (to make it more smooth)
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the markdown renderer for SSR support, implements LRU caching for code blocks and tables, and updates component styles and UX labels. It also adds automatic scrolling to the chat container. Feedback includes a suggestion to import ChangeDetectionStrategy for OnPush compliance and a recommendation to optimize table row filtering for better performance and SSR compatibility.

*/
import { Component, effect, inject, input, ElementRef } from '@angular/core';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { Component, effect, inject, input, ElementRef, PLATFORM_ID } from '@angular/core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ChangeDetectionStrategy enum should be imported from @angular/core to support the use of OnPush change detection in the component.

Suggested change
import { Component, effect, inject, input, ElementRef, PLATFORM_ID } from '@angular/core';
import { ChangeDetectionStrategy, Component, effect, inject, input, ElementRef, PLATFORM_ID } from '@angular/core';

Comment on lines +364 to 373
const filteredRows = rows.filter(row => {
const tempTable = docRef.createElement('table');
tempTable.innerHTML = `<tbody>${row}</tbody>`;
const tableCells = tempTable.querySelectorAll('td, th');
return Array.from(tableCells).some(cell => {
const hasText = !!cell.textContent?.trim();
const hasHtml = !!cell.innerHTML?.trim();
return hasText || hasHtml;
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current approach of filtering empty rows by creating a temporary DOM element and parsing HTML for every row is computationally expensive and breaks Server-Side Rendering (SSR) compatibility, as browser-specific DOM APIs are not available on the server. A more efficient approach would be to check for content during the row generation phase in the forEach loop above (around line 359) and only add the row to the rows array if it contains non-empty cells or is a header row.

References
  1. Avoid using browser-specific DOM APIs in code that needs to support Server-Side Rendering (SSR), as they are not available on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant