Skip to content

Commit 39e7d20

Browse files
committed
fix(LogViewer): Adjust parsed data to remove tab character
When we estimate the height in guessRowHeight, the data we are using has a \t character rather than tabs. This leads to a misleading character count, which impacts the calculated number of rows displayed. Some example data was provided by OpenShift that had overlapping rows. This data had tabs in it. When tabs were removed or replaced with strings, the issue could not be recreated. There may be other issues involved here, but this at least fixes this one provided example. We should talk to products that are continuing to experience this and gather sample outputs to see if we can recreate/adjust on an individual basis.
1 parent ae3436b commit 39e7d20

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/module/src/LogViewer/LogViewer.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export interface LogViewerProps {
6464
* measured to prevent a bug where one line can overlap another.
6565
*/
6666
fastRowHeightEstimationLimit?: number;
67+
/** Number of spaces used to replace tabs */
68+
numSpaces?: number;
6769
}
6870

6971
let canvas: HTMLCanvasElement | undefined;
@@ -98,6 +100,7 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
98100
initialIndexWidth,
99101
useAnsiClasses,
100102
fastRowHeightEstimationLimit = 5000,
103+
numSpaces = 8,
101104
...props
102105
}: LogViewerProps) => {
103106
const [searchedInput, setSearchedInput] = useState<string | null>('');
@@ -112,7 +115,13 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
112115
const [listKey, setListKey] = useState(1);
113116

114117
/* Parse data every time it changes */
115-
const parsedData = useMemo(() => parseConsoleOutput(data), [data]);
118+
const parsedData = useMemo(
119+
() =>
120+
// use of tabs in data can throw off the character count when we estimate height since we see it as \t, so replace them with spaces
121+
// spaces seem to get picked up by height calculations
122+
parseConsoleOutput(data).map((datum) => datum.replace(/\t/g, ' '.repeat(numSpaces))),
123+
[data]
124+
);
116125

117126
const isChrome = useMemo(() => navigator.userAgent.indexOf('Chrome') !== -1, []);
118127

@@ -183,6 +192,10 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
183192
}, [parsedData, scrollToRow]);
184193

185194
const createDummyElements = () => {
195+
if (!containerRef.current) {
196+
return;
197+
}
198+
186199
// create dummy elements
187200
const dummyIndex = document.createElement('span');
188201
dummyIndex.className = css(styles.logViewerIndex);

0 commit comments

Comments
 (0)