Ask a question, on the chatGPT web, with the typewriter effect output, you will find that when it outputs the second line, the first line can already be copied and will not be updated again. It is truly incremental DOM updates.
Imagine implementing something similar with Vue/React:
- Fetch the GPT API, stream the result incrementally, and each time parse the content containing markdown tags, then text += content (executed once per return)
- Parse the text into HTML tags: result = markdownIt(text) (executed once per return)
- v-html/innerHTML = result, rendering the final markdown form of HTML.
Here is a problem: constantly parsing the markdown text into the result will lead to re-rendering the entire HTML output. While the output screen appears incremental, the entire rendered DOM content keeps refreshing, causing the already output content to be unselectable, which results in a poor experience and performance issues. Any optimization suggestions?