Skip to content

Commit 54ba104

Browse files
Added check for files with really long lines (like minified files) and display a message that the file could not be rendered
1 parent ac397b4 commit 54ba104

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Fixed issue with the symbol hover popover clipping at the top of the page. [#326](https://github.com/sourcebot-dev/sourcebot/pull/326)
12+
- Fixed slow rendering issue with large reference/definition lists. [#327](https://github.com/sourcebot-dev/sourcebot/pull/327)
1213

1314
## [4.1.0] - 2025-06-02
1415

packages/web/src/app/[domain]/components/lightweightCodeHighlighter.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ interface LightweightCodeHighlighter {
2727
renderWhitespace?: boolean;
2828
}
2929

30+
// The maximum number of characters per line that we will display in the preview.
31+
const MAX_NUMBER_OF_CHARACTER_PER_LINE = 1000;
32+
3033
/**
3134
* Lightweight code highlighter that uses the Lezer parser to highlight code.
3235
* This is helpful in scenarios where we need to highlight a ton of code snippets
@@ -49,12 +52,19 @@ export const LightweightCodeHighlighter = memo<LightweightCodeHighlighter>((prop
4952
return code.trimEnd().split('\n');
5053
}, [code]);
5154

55+
const isFileTooLargeToDisplay = useMemo(() => {
56+
return unhighlightedLines.some(line => line.length > MAX_NUMBER_OF_CHARACTER_PER_LINE);
57+
}, [code]);
5258

5359
const [highlightedLines, setHighlightedLines] = useState<React.ReactNode[] | null>(null);
5460

5561
const highlightStyle = useCodeMirrorHighlighter();
5662

5763
useEffect(() => {
64+
if (isFileTooLargeToDisplay) {
65+
return;
66+
}
67+
5868
measure(() => Promise.all(
5969
unhighlightedLines
6070
.map(async (line, index) => {
@@ -103,12 +113,21 @@ export const LightweightCodeHighlighter = memo<LightweightCodeHighlighter>((prop
103113
const lineNumberDigits = String(lineCount).length;
104114
const lineNumberWidth = `${lineNumberDigits + 2}ch`; // +2 for padding
105115

116+
if (isFileTooLargeToDisplay) {
117+
return (
118+
<div className="font-mono text-sm px-2">
119+
File too large to display in preview.
120+
</div>
121+
);
122+
}
123+
106124
return (
107125
<div
108126
style={{
109127
fontFamily: tailwind.theme.fontFamily.editor,
110128
fontSize: tailwind.theme.fontSize.editor,
111129
whiteSpace: renderWhitespace ? 'pre-wrap' : 'none',
130+
wordBreak: 'break-all',
112131
}}
113132
>
114133
{(highlightedLines ?? unhighlightedLines).map((line, index) => (

0 commit comments

Comments
 (0)