virtualization: check for index (#107963)

* virtualization: check for index

* Add regression test
This commit is contained in:
Matias Chomicki
2025-07-10 13:18:02 +00:00
committed by GitHub
parent a8733f9a05
commit d74aac3da5
2 changed files with 13 additions and 1 deletions
@@ -67,6 +67,18 @@ describe('Virtualization', () => {
expect(size).toBe(SINGLE_LINE_HEIGHT + DETAILS_HEIGHT);
});
test('Should not throw when an undefined index is passed', () => {
const size = getLogLineSize(
virtualization,
[log],
container,
[],
{ ...defaultOptions, showTime: true, showDetails: [log], detailsMode: 'inline' },
1 // Index out of bounds
);
expect(size).toBe(SINGLE_LINE_HEIGHT);
});
test('Returns the a single line if the line is not loaded yet', () => {
const logs = [log];
const size = getLogLineSize(
@@ -255,7 +255,7 @@ export function getLogLineSize(
}
const gap = virtualization.getGridSize() * FIELD_GAP_MULTIPLIER;
const detailsHeight =
detailsMode === 'inline' && showDetails.findIndex((log) => log.uid === logs[index].uid) >= 0
detailsMode === 'inline' && logs[index] && showDetails.findIndex((log) => log.uid === logs[index].uid) >= 0
? window.innerHeight * (LOG_LINE_DETAILS_HEIGHT / 100) + gap / 2
: 0;
// !logs[index] means the line is not yet loaded by infinite scrolling