Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/selectors/per-thread/composed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import type {
StackTimingByDepth,
} from '../../profile-logic/stack-timing';

import { ensureExists } from '../../utils/flow';

/**
* Infer the return type from the getStackAndSampleSelectorsPerThread function. This
* is done that so that the local type definition with `Selector<T>` is the canonical
Expand Down Expand Up @@ -92,8 +90,15 @@ export function getComposedSelectorsPerThread(
}
let hasSamples = samples.length > 0 && stackTable.length > 0;
if (hasSamples) {
const stackIndex = ensureExists(samples.stack[0]);
if (stackTable.prefix[stackIndex] === null) {
// Find at least one non-null stack.
const stackIndex = samples.stack.find((stack) => stack !== null);
if (
stackIndex === undefined ||
stackIndex === null // We know that it can't be null at this point, but Flow doesn't.
) {
// All samples were null.
hasSamples = false;
} else if (stackTable.prefix[stackIndex] === null) {
// There's only a single stack frame, check if it's '(root)'.
const frameIndex = stackTable.frame[stackIndex];
const funcIndex = frameTable.func[frameIndex];
Expand Down
14 changes: 14 additions & 0 deletions src/test/store/useful-tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,18 @@ describe('getUsefulTabs', function () {
'marker-table',
]);
});

it('works when the first sample is null', () => {
const { profile } = getProfileFromTextSamples('A B');
profile.threads[0].samples.stack[0] = null;

const { getState } = storeWithProfile(profile);
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([
'calltree',
'flame-graph',
'stack-chart',
'marker-chart',
'marker-table',
]);
});
});