Skip to content

Commit 0b8192f

Browse files
ui: Flamegraph state reset bug fix and verbose logs (#6054)
* Flamegraph state reset bug fix and verbose logs * [pre-commit.ci lite] apply automatic fixes * Linter fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 1184525 commit 0b8192f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

ui/packages/shared/components/src/hooks/URLState/index.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,46 @@ export const useURLState = <T extends ParamValue>(
251251
const value = useMemo<ParamValue>(() => {
252252
if (typeof state[param] === 'string') {
253253
if (alwaysReturnArray === true) {
254+
if (debugLog === true) {
255+
console.log('useURLState returning single string value as array for param', param, [
256+
state[param],
257+
]);
258+
}
254259
return [state[param]] as ParamValue;
255260
}
261+
if (debugLog === true) {
262+
console.log('useURLState returning string value for param', param, state[param]);
263+
}
256264
return state[param];
257265
} else if (state[param] != null && Array.isArray(state[param])) {
258266
if (state[param]?.length === 1 && alwaysReturnArray !== true) {
267+
if (debugLog === true) {
268+
console.log(
269+
'useURLState returning first array value as string for param',
270+
param,
271+
state[param][0]
272+
);
273+
}
259274
return state[param]?.[0] as ParamValue;
260275
} else {
276+
if (debugLog === true) {
277+
console.log('useURLState returning array value for param', param, state[param]);
278+
}
261279
return state[param];
262280
}
263281
}
264-
}, [state, param, alwaysReturnArray]);
282+
}, [state, param, alwaysReturnArray, debugLog]);
283+
284+
if (value == null) {
285+
if (debugLog === true) {
286+
console.log(
287+
'useURLState returning defaultValue for param',
288+
param,
289+
defaultValue,
290+
window.location.href
291+
);
292+
}
293+
}
265294

266295
return [(value ?? defaultValue) as T, setParam];
267296
};

ui/packages/shared/profile/src/hooks/useQueryState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {Query} from '@parca/parser';
1818

1919
import {QuerySelection} from '../ProfileSelector';
2020
import {ProfileSelection, ProfileSelectionFromParams, ProfileSource} from '../ProfileSource';
21+
import {useResetFlameGraphState} from '../ProfileView/hooks/useResetFlameGraphState';
2122
import {sumByToParam, useSumBy, useSumByFromParams} from '../useSumBy';
2223

2324
interface UseQueryStateOptions {
@@ -71,6 +72,7 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
7172
} = options;
7273

7374
const batchUpdates = useURLStateBatch();
75+
const resetFlameGraphState = useResetFlameGraphState();
7476

7577
// URL state hooks with appropriate suffixes
7678
const [expression, setExpressionState] = useURLState<string>(`expression${suffix}`, {
@@ -304,6 +306,7 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
304306
// Clear ProfileSelection for non-delta profiles
305307
setSelectionParam(undefined);
306308
}
309+
resetFlameGraphState();
307310
});
308311
},
309312
[
@@ -324,6 +327,7 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
324327
setMergeFromState,
325328
setMergeToState,
326329
setSelectionParam,
330+
resetFlameGraphState,
327331
]
328332
);
329333

0 commit comments

Comments
 (0)