All posts
Open SourceReactTypeScript

My Jaeger UI fix: stop losing your place when a trace reloads

Two earlier PRs had tried to fix this bug. Mine took about 130 lines across 5 files, and the creator of Jaeger reviewed it himself.

S
Sandip Godhani
23 Nov 2026 · 5 min read

Another one of my PRs got merged into Jaeger UI. The bug sounds small, but it is genuinely annoying when you hit it in the middle of debugging, which is exactly when people use Jaeger.

What Jaeger is

If you haven't used it: Jaeger is an open-source distributed tracing platform and a graduated CNCF project. When a request moves through dozens of microservices, Jaeger shows you exactly where the time went: every service call is a span, and the trace timeline lays them out as a tree you can collapse and expand. Engineers use it to debug latency and failures in production.

The bug (issue #4617)

Jaeger has a search box for the trace you're looking at. When you search, it expands the spans that match and scrolls you to the first one. That's useful the first time you open a trace.

But if the same trace reloaded while a search was still active, the search ran again from scratch. It undid every span you had collapsed or expanded by hand, and threw you back to the first match.

Picture digging deep into a large trace, collapsing everything you have ruled out, and losing your place every time it refreshes.

This wasn't an unclaimed bug. Two earlier PRs, #4620 and #4807, had already tried to fix it. Both made a reload reveal any new matches, which still moved the user's view around. My PR superseded both.

Reading those two first was useful. Both tried to make a reload smarter about the search, and both still moved the user's view. That pointed to a simpler rule: a reload shouldn't touch the view at all. Focus the matches only when the user actually opens a trace, or asks for it.

Reading before writing

The timeline state lives in a Zustand store (useTraceTimelineStore). Its setTrace action runs whenever trace data arrives, both when you open a trace and when the same trace is fetched again. It already treated those two cases differently for collapsed spans: a new trace resets them, a same-ID refetch keeps them. The find-focus step just ignored that distinction and ran every time.

Before changing anything I needed to know every path that reaches setTrace: a first open, a refetch, leaving the page and coming back, and switching to another view (like the graph) and back. Each one should behave differently, and the store outlives the page, which is where it gets subtle.

The fix

The core change is a single flag: is this a different trace, or the same one again? Only a newly opened trace focuses the matches.

store.timeline.ts (trimmed)ts
const isNewTrace = trace.traceID !== currentTraceID;

if (isNewTrace) {
  // reset collapses and detail states for a different trace
}

// Only a newly opened trace focuses the find matches. A same-ID reload leaves the view alone,
// so a match that arrives under a collapsed parent stays hidden until the user focuses it.
if (isNewTrace && matches) {
  let focused = calculateFocusedFindRowStates(matches, trace.spans);
  focused = trimFocusedDetailStatesForSidePanel(focused, detailPanelMode);
  Object.assign(base, focused);
}

That fixes reloads, but creates a new problem. Because the store outlives the page, if you leave a trace and later open the same one again, the store still remembers its ID. It would look like a reload, and your search would never get focused. So I added a clearTrace action and called it when the trace page unmounts:

TracePage/index.tsxtsx
// The timeline store outlives this page. Clearing it on unmount makes opening the same trace
// again an open, not a reload. This belongs here and not in the timeline view, because switching
// to another view and back must keep the collapses and the selection.
useEffect(() => zustandClearTrace, [zustandClearTrace]);

Where that line lives matters. Put it in the timeline view instead, and switching to the graph view and back would wipe your collapses too.

What it does now

  • Search focus runs only when you open a different trace, or when you click the focus button yourself.
  • Reloading the same trace keeps your collapsed spans, open details and scroll position. Only detail states for spans that no longer exist get pruned.
  • Leaving the trace page and coming back counts as a fresh open again.
  • Switching to another view and back keeps your collapses and selection.

There is one honest trade-off, written into the code comment: if a reload brings in a new match under a span you collapsed, it stays hidden until you ask for it. Moving the user's view without asking was the bug, so that felt like the right side to land on.

Tests

Some existing tests had locked in the old refocus behaviour, so I rewrote them, and added a test for the exact scenario in the issue: a same-ID reload with an active search keeps manual collapses and does not scroll. In total the PR was +130 / −19 lines across 5 files, and most of those lines are tests.

The best part: the review

Yuri Shkuro, the creator of Jaeger, reviewed it and pushed two small commits on top before merging. In my version, the initial store state, the new-trace branch of setTrace and clearTrace each listed the same reset fields. He moved them into one shared function, so a field added later gets reset in all three places. He also tightened the comments so the reason a reload skips the focus is stated once, and renamed a test variable from before to stateBeforeReload.

None of that changed behaviour. All of it made the code easier for the next person. Seeing how a maintainer thinks about naming, comments and future edge cases taught me more than any tutorial.

Read next
End-to-end encryption in my chat app: static ECDH, and where it breaks