Skip to content

Commit 86ff177

Browse files
committed
Fix CauseBacktrace type to allow stack to be null.
We want stack-less "causes" whenever we want to filter out a stack completely, for example because it doesn't contain the focused function when we're applying a focus function transform. Pre-TypeScript, we were already using this field that way, even though it wasn't typed correctly.
1 parent 4c96d7d commit 86ff177

File tree

4 files changed

+39
-35
lines changed

4 files changed

+39
-35
lines changed

src/components/shared/MarkerContextMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
145145
return !marker || marker.end === null;
146146
}
147147

148-
_convertStackToString(stack: IndexIntoStackTable): string {
148+
_convertStackToString(stack: IndexIntoStackTable | null): string {
149149
const { thread, implementationFilter } = this.props;
150150

151-
if (thread === null) {
151+
if (thread === null || stack === null) {
152152
return '';
153153
}
154154

src/components/tooltip/Marker.tsx

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -423,40 +423,43 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
423423
categories,
424424
} = this.props;
425425
const { data, start } = marker;
426-
if (data && 'cause' in data && data.cause) {
427-
const { cause } = data;
428-
const causeAge = cause.time !== undefined ? start - cause.time : 0;
429-
return [
430-
<TooltipDetailSeparator key="backtrace-separator" />,
431-
<TooltipDetail label="Stack" key="backtrace">
432-
<div className="tooltipDetailsBackTrace">
433-
{
434-
/* The cause's time might be later than the marker's start. For
426+
if (!data || !('cause' in data) || !data.cause) {
427+
return null;
428+
}
429+
const { time, stack } = data.cause;
430+
if (stack === null) {
431+
return null;
432+
}
433+
const causeAge = time !== undefined ? start - time : 0;
434+
return [
435+
<TooltipDetailSeparator key="backtrace-separator" />,
436+
<TooltipDetail label="Stack" key="backtrace">
437+
<div className="tooltipDetailsBackTrace">
438+
{
439+
/* The cause's time might be later than the marker's start. For
435440
example this happens in some usual cases when the cause is
436441
captured right when setting the end marker for tracing pairs of
437442
markers. */
438-
causeAge > 0 ? (
439-
<h2 className="tooltipBackTraceTitle">
440-
{data.type === 'Styles' || marker.name === 'Reflow'
441-
? `First invalidated ${formatTimestamp(
442-
causeAge
443-
)} before the flush, at:`
444-
: `Triggered ${formatTimestamp(causeAge)} ago, at:`}
445-
</h2>
446-
) : null
447-
}
448-
<Backtrace
449-
maxStacks={restrictHeightWidth ? 20 : Infinity}
450-
stackIndex={cause.stack}
451-
thread={thread}
452-
implementationFilter={implementationFilter}
453-
categories={categories}
454-
/>
455-
</div>
456-
</TooltipDetail>,
457-
];
458-
}
459-
return null;
443+
causeAge > 0 ? (
444+
<h2 className="tooltipBackTraceTitle">
445+
{data.type === 'Styles' || marker.name === 'Reflow'
446+
? `First invalidated ${formatTimestamp(
447+
causeAge
448+
)} before the flush, at:`
449+
: `Triggered ${formatTimestamp(causeAge)} ago, at:`}
450+
</h2>
451+
) : null
452+
}
453+
<Backtrace
454+
maxStacks={restrictHeightWidth ? 20 : Infinity}
455+
stackIndex={stack}
456+
thread={thread}
457+
implementationFilter={implementationFilter}
458+
categories={categories}
459+
/>
460+
</div>
461+
</TooltipDetail>,
462+
];
460463
}
461464

462465
_maybeRenderNetworkPhases() {

src/profile-logic/merge-compare.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,8 @@ function mergeMarkers(
13561356
if (oldData && 'cause' in oldData && oldData.cause) {
13571357
// The old data has a cause, we need to convert the stack.
13581358
const oldStack = oldData.cause.stack;
1359-
const newStack = translationMapForStacks.get(oldStack);
1359+
const newStack =
1360+
oldStack !== null ? translationMapForStacks.get(oldStack) : null;
13601361
if (newStack === undefined) {
13611362
throw new Error(
13621363
`Missing old stack entry ${oldStack} in the translation map.`

src/types/markers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export type CauseBacktrace = {
201201
// No upgrader was written for this change.
202202
tid?: Tid;
203203
time?: Milliseconds;
204-
stack: IndexIntoStackTable;
204+
stack: IndexIntoStackTable | null;
205205
};
206206

207207
/**

0 commit comments

Comments
 (0)