Skip to content

Commit f094011

Browse files
authored
ui: Handle undefined BigInt values properly (#5961)
1 parent d99ff62 commit f094011

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

ui/packages/shared/profile/src/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ export const FlameNode = React.memo(
116116

117117
const mappingFile: string | null = arrowToString(mappingColumn?.get(row));
118118
const functionName: string | null = arrowToString(functionNameColumn?.get(row));
119-
const cumulative =
120-
cumulativeColumn?.get(row) !== null ? BigInt(cumulativeColumn?.get(row)) : 0n;
121-
const diff: bigint | null = diffColumn?.get(row) !== null ? BigInt(diffColumn?.get(row)) : null;
119+
const cumulative = cumulativeColumn?.get(row) != null ? BigInt(cumulativeColumn?.get(row)) : 0n;
120+
const diff: bigint | null = diffColumn?.get(row) != null ? BigInt(diffColumn?.get(row)) : null;
122121
const filename: string | null = arrowToString(filenameColumn?.get(row));
123122
const depth: number = depthColumn?.get(row) ?? 0;
124123

ui/packages/shared/profile/src/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export const useVisibleNodes = ({
8787

8888
return useMemo(() => {
8989
// Create a stable key for memoization to prevent unnecessary recalculations
90-
const memoKey = `${viewport.scrollTop}-${viewport.containerHeight}-${selectedRow}-${effectiveDepth}-${width}`;
90+
const memoKey = `${viewport.scrollTop}-${
91+
viewport.containerHeight
92+
}-${selectedRow}-${effectiveDepth}-${width}-${Number(total)}-${table.numRows}`;
9193

9294
// Return cached result if viewport hasn't meaningfully changed
9395
if (lastResultRef.current.key === memoKey) {
@@ -117,7 +119,7 @@ export const useVisibleNodes = ({
117119
? BigInt(valueOffsetColumn?.get(selectedRow))
118120
: 0n;
119121
const selectionCumulative =
120-
cumulativeColumn?.get(selectedRow) !== null ? BigInt(cumulativeColumn?.get(selectedRow)) : 0n;
122+
cumulativeColumn?.get(selectedRow) != null ? BigInt(cumulativeColumn?.get(selectedRow)) : 0n;
121123

122124
const totalNumber = Number(total);
123125
const selectionOffsetNumber = Number(selectionOffset);
@@ -134,7 +136,7 @@ export const useVisibleNodes = ({
134136

135137
for (const row of rowsAtDepth) {
136138
const cumulative =
137-
cumulativeColumn?.get(row) !== null ? Number(cumulativeColumn?.get(row)) : 0;
139+
cumulativeColumn?.get(row) != null ? Number(cumulativeColumn?.get(row)) : 0;
138140

139141
const valueOffset =
140142
valueOffsetColumn?.get(row) !== null && valueOffsetColumn?.get(row) !== undefined

ui/packages/shared/profile/src/ProfileView/components/InvertCallStack/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@ import {Icon} from '@iconify/react';
1515

1616
import {Button, useURLState} from '@parca/components';
1717

18+
import {useResetFlameGraphState} from '../../hooks/useResetFlameGraphState';
19+
1820
const InvertCallStack = (): JSX.Element => {
1921
const [invertStack = '', setInvertStack] = useURLState('invert_call_stack');
2022
const isInvert = invertStack === 'true';
23+
const resetFlameGraphState = useResetFlameGraphState();
24+
25+
const handleSetInvert = (value: boolean): void => {
26+
setInvertStack(value ? 'true' : '');
27+
28+
resetFlameGraphState();
29+
};
2130

2231
return (
2332
<div className="flex flex-col">
2433
<label className="text-sm">&nbsp;</label>
2534
<Button
2635
variant="neutral"
2736
className="flex items-center gap-2 whitespace-nowrap"
28-
onClick={() => setInvertStack(isInvert ? '' : 'true')}
37+
onClick={() => handleSetInvert(!isInvert)}
2938
id="h-invert-call-stack"
3039
>
3140
<Icon icon={isInvert ? 'ph:sort-ascending' : 'ph:sort-descending'} className="h-4 w-4" />

0 commit comments

Comments
 (0)