-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Description
Currently, if you render a CodeView with a large amount of code (say, 10,000 lines of JSON), the browser will be stuck for a noticeable period of time because CodeView renders and highlights all of that code at once.
The underlying ace-code library supports virtualization (rendering only the code that's actually visible to the user) but CodeView doesn't.
I asked Copilot about this and got this response:
Here’s how the current
CodeViewdiffers from relying on Ace’s incremental/virtual rendering, with direct references:
In
src/code-view/internal.tsxthe component tokenizes and renders the entire code block eagerly into React nodes:It splits the entire
contentstring into lines and builds React elements for every line (textHighlight), or calls the providedhighlightfunction to do the same.See lines 18–32:
textHighlightsplitscodeinto lines and wraps each line in a<span>with a newline appended.Then it wraps those nodes in a fragment and extracts them as a single React element (
codeElement), lines 53–58.Finally, it maps over every child to render a
<tr>for each line (lines 90–118), producing the full table up front.This means the entire content is in the DOM at once and fully tokenized before render, which defeats virtualization. Ace’s normal renderer would keep the session text and only paint the visible rows; here, React is asked to create DOM for all rows every time.
The
scroll-container(<div className={styles["scroll-container"]}>at line 69) wraps a static<table>of all lines; there’s no hook into Ace’s row windowing or renderer. So the browser ends up with one row per line regardless of viewport.In short, today’s
CodeViewprecomputes and mounts every line (and every highlight token if a customhighlightis used). To use Ace’s virtualization, the component would need to hand the text to Ace and let Ace’s renderer manage which rows to paint, instead of building the entire table of lines in React.
Code of Conduct
- I agree to follow this project's Code of Conduct
- I checked the current issues on this and main repositories for duplicate requests