AI chat interfaces stream answers in pieces, so images, citations, lists and tables have to render while the response is still taking shape. That causes three problems. Streaming chunks don’t end where Markdown elements end. Unfinished syntax needs different handling depending on the element. And images and citations carry data that doesn’t belong inside Markdown text.
SiftHub’s frontend solves this by treating each response as one growing Markdown document:
- One Markdown input. All the text is combined so lists, paragraphs and tables keep their structure across updates. Images and citations sit in the document as lightweight placeholders, and their data is stored separately.
- A temporary display copy. Unfinished syntax gets patched for display only. For example, an open bold phrase is closed early, and partial image syntax is held back until it’s complete. The received content itself is never changed.
- Placeholder-to-component mapping. Each placeholder renders through a custom component that reads from its own data object. For an image, that’s the URL, name and dimensions. For a citation, it’s the source labels and references.
In short, the parser handles the document’s structure and the components handle the data. Images can start loading early, with space reserved so the text around them doesn’t shift. Citations appear in place as the answer streams, but they only become clickable once the full answer has rendered.
AI chat interfaces stream answers in pieces, so images, citations, lists and tables have to render while the response is still taking shape. That causes three problems. Streaming chunks don’t end where Markdown elements end. Unfinished syntax needs different handling depending on the element. And images and citations carry data that doesn’t belong inside Markdown text.
SiftHub’s frontend solves this by treating each response as one growing Markdown document:
- One Markdown input. All the text is combined so lists, paragraphs and tables keep their structure across updates. Images and citations sit in the document as lightweight placeholders, and their data is stored separately.
- A temporary display copy. Unfinished syntax gets patched for display only. For example, an open bold phrase is closed early, and partial image syntax is held back until it’s complete. The received content itself is never changed.
- Placeholder-to-component mapping. Each placeholder renders through a custom component that reads from its own data object. For an image, that’s the URL, name and dimensions. For a citation, it’s the source labels and references.
In short, the parser handles the document’s structure and the components handle the data. Images can start loading early, with space reserved so the text around them doesn’t shift. Citations appear in place as the answer streams, but they only become clickable once the full answer has rendered.
In a streaming AI chat interface, people can begin reading an answer while the rest is still being generated. The frontend receives the response in pieces and updates the conversation as more content arrives.
That experience becomes more demanding when the answer contains images, citations, lists, and tables. These elements need to become part of a readable response while its content and structure are still taking shape.

The starting point: one answer with several kinds of content
Consider an answer explaining how a request moves through a system. It opens with a paragraph, introduces an architecture diagram, compares retention periods in a table, and cites the source behind a statement.
For the reader, those parts belong together. The diagram should follow the explanation that introduces it. The citation should stay beside the statement it supports. The table should remain a table as more rows arrive.
Markdown supplies much of that structure. But the frontend receives it progressively, and images and citations bring additional data of their own.
At SiftHub, this led to a practical question: how do we preserve the shape of the answer while rendering rich content that arrives alongside its text?
The problems: the answer is still taking shape
1. Incoming pieces do not preserve document boundaries
A text event can end halfway through a list item, with the rest arriving in the next event:
First piece: "- Open the "
Next piece: "settings panel."
Together: "- Open the settings panel."
If each piece is parsed independently, the second fragment loses the list structure established by the first. The same applies to paragraphs, formatted phrases, and table rows. The boundaries of the incoming data do not tell us where a Markdown element ends.
Later content can also change how earlier content is interpreted. A line of column names may initially appear as ordinary text. When the separator row arrives, those words become a table header:
| Category | Retention |
| —------ | —------- |
The second line establishes the relationship between the lines, following the table rules in GitHub Flavored Markdown. The renderer must be able to revisit the earlier content with that new context.
This makes a simple sequence of separately rendered fragments insufficient. The frontend needs to preserve the relationships between them.
2. Unfinished content cannot all be displayed the same way
A bold phrase can arrive before its closing characters. An image reference can arrive before its destination is complete. Both are unfinished, but they ask different things of the interface.
The words in the bold phrase are already readable. The missing characters affect how those words should be formatted. An incomplete image expression, however, does not yet provide enough syntax to create the intended image element.
Even when the image reference is complete, its pixels may not be ready. The browser still has to fetch and decode the resource. Content arrival, document interpretation, and image loading therefore have separate timing.
The frontend needs a deliberate way to present what is ready while allowing the rest to continue arriving.
3. Images and citations need more than Markdown text
Markdown already supports ordinary image references through a description and destination. Its image syntax can represent this directly:

Our interface also needs the image's name, dimensions, and information used by its presentation. A citation needs its source details, and one visible citation may represent several sources.
Encoding all of that into the Markdown string would leave the frontend extracting application data from text that is still being assembled. It would also make source labels and file names part of the syntax the parser has to interpret.
We needed to preserve both the element's position in the answer and the data behind it.
The solution: one growing document, with rich data kept separately
These problems share a solution. We keep text, images, and citations distinguishable in the incoming data, then bring them together within one Markdown document.
The response is an ordered sequence of events. A simplified view looks like this, with additional metadata omitted:
[
{"type":"text","content":"The architecture is shown below."},
{"type":"image","name":"architecture.png","url":"/architecture.png"},
{"type":"text","content":"This follows the architecture guide."},
{"type":"citation","sources":[{"displayName":"Architecture guide"}]}
]
The order describes where each part belongs. The objects carry what each part needs to display. This example illustrates the approach; it is not the complete API payload.
From that data, three rendering decisions address the problems above.
1. Preserve the full Markdown context
To keep paragraphs, lists, and tables connected across updates, we combine the text into one Markdown input. Images and citations get lightweight placeholders at their positions in that document. Their data stays available separately.
Conceptually, the document looks like this:
The architecture is shown below.
[Image placeholder]
This follows the architecture guide. [Citation placeholder]
These labels illustrate the positions; they are not the actual marker syntax.
The renderer can now interpret the surrounding content together. A list continuation retains the text that established the list. A table header can be recognized when its separator arrives. An inline citation remains part of the paragraph or table cell that contains it.
This resolves the first problem: rich content can sit inside the response without forcing the surrounding Markdown into independently parsed fragments.
2. Handle incomplete syntax in a temporary display copy
To make unfinished content readable, the rendering layer prepares the accumulated Markdown for display. For example, it can temporarily close a bold phrase:
Received: Use **the private endpoint
Display copy: Use **the private endpoint**
The received words can appear with emphasis while the phrase continues. An unfinished ordinary image expression receives different treatment: it is withheld until enough syntax has arrived to recognize it.
These adjustments stay in the display copy. They do not change the received response. When more content arrives, the renderer prepares the accumulated source again.
This addresses the second problem at the Markdown level. The renderer can present a useful intermediate state while preserving the original content for the next update. Browser image loading remains a separate step once an image element has been created.
3. Resolve each placeholder using its accompanying object
To display the rich content, the renderer maps a placeholder to a custom component. That component uses the associated object to render the image or citation at the recorded position.
For an image, the object supplies its URL, name, and dimensions. For a citation, it supplies the source label and any additional references. Source names and file names remain data to display, so brackets or underscores in them do not become Markdown formatting instructions.
This addresses the third problem: the parser handles document structure while the components receive the application data they need.
The image's path through this approach is straightforward. When a complete image event arrives, we retain its data and insert its marker together. The parser encounters the marker; the image component uses the object to create the image presentation. The marker is internal to document processing, rather than a visible loading box waiting for a later metadata event.
Once the browser has an image element and its URL, the resource can load while more answer text arrives. When dimensions are available, the browser can reserve space before the pixels appear, reducing movement in the surrounding content. The browser's image-element reference explains that sizing behavior.
Citations use the same position-and-data approach. They can become visible as the response arrives, but our UI enables clicking them only after the full answer has rendered. Showing the reference and enabling its interaction remain separate decisions.
How the parts come together
Returning to the opening example, the paragraph, diagram, table, and citation can develop as parts of one answer. The renderer retains the context needed to interpret the Markdown, and each rich element receives its data through its placeholder.
The key choice was to give document structure and application data clear roles. That lets the frontend keep building the response without forcing image details or source information into the text it is still trying to interpret.





.avif)

