Skip to content

Commit 9ef0f34

Browse files
fix(web): Fix "Invalid line number XXX in 21-line document" (#745)
1 parent 27cd248 commit 9ef0f34

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111
- Added dialog when no authentication provider is configured. [#744](https://github.com/sourcebot-dev/sourcebot/pull/744)
1212

13+
### Fixed
14+
- Fixed "Invalid line number XXX in 21-line document" error when a invalid highlight range is passed to the file viewer. [#745](https://github.com/sourcebot-dev/sourcebot/pull/745)
15+
1316
## [4.10.11] - 2026-01-16
1417

1518
### Fixed

packages/web/src/app/[domain]/browse/[...path]/components/pureCodePreviewPanel.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ export const PureCodePreviewPanel = ({
114114
const doc = editorRef.state.doc;
115115
const { start, end } = highlightRange;
116116

117+
if (start.lineNumber > doc.lines || end.lineNumber > doc.lines) {
118+
console.warn(`Highlight range is out of bounds: start.lineNumber=${start.lineNumber}, end.lineNumber=${end.lineNumber}, doc.lines=${doc.lines}`);
119+
return;
120+
}
121+
117122
const from = doc.line(start.lineNumber).from;
118123
const to = doc.line(end.lineNumber).to;
119124
const selection = EditorSelection.range(from, to);

packages/web/src/app/[domain]/browse/[...path]/components/rangeHighlightingExtension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export const rangeHighlightingExtension = (range: BrowseHighlightRange) => State
1616
create(state) {
1717
const { start, end } = range;
1818

19+
if (start.lineNumber > state.doc.lines || end.lineNumber > state.doc.lines) {
20+
console.warn(`Highlight range is out of bounds: start.lineNumber=${start.lineNumber}, end.lineNumber=${end.lineNumber}, doc.lines=${state.doc.lines}`);
21+
return Decoration.none;
22+
}
23+
1924
if ('column' in start && 'column' in end) {
2025
const from = state.doc.line(start.lineNumber).from + start.column - 1;
2126
const to = state.doc.line(end.lineNumber).from + end.column - 1;

0 commit comments

Comments
 (0)