---
title: 'Animating a Tab Indicator with <em>left</em> Stalls It for the 0.3s the List Takes to Render'
tags:
  - browser
  - web-performance
  - animation
  - css
  - debugging
published: true
date: 2026-12-01 10:59:00
description: 'How to build a tab indicator that keeps moving while list rendering holds the main thread for 300ms. Why left and width transitions stall, the transform transition and its precondition, what layer hints cannot change, and when to read tab positions and add a ResizeObserver'
art:
  undraw: progress-indicator
---

Tap the second tab (Frontend) in the screen below. The 2px bar under the tabs (the indicator) moves about 12px toward the new tab and stops. 0.3 seconds later, at the moment the list below switches to its new content, the bar jumps the remaining 35px in one step.

<LiveDemo src="/demos/tab-indicator-transform-transition/index.html?v=left-width&lang=en" title="An indicator that transitions left and width. Tap a tab and it moves a little, stops, then jumps when the list changes" height={502} />

This indicator moves by transitioning `left` and `width`. Right after the tap, the list data arrives and the 200 rows of the list are rendered again. For the 300ms that takes, the main thread can do nothing else, so the indicator stops too. To reproduce this, each row burns 1.5ms in an empty loop while it renders. The data arrival is simulated with a 30ms timer.

The demo shares the main thread with this page. When you tap a tab, you can see that this page also stops responding to clicks for 0.3 seconds.

This post assumes the time it takes to render the list cannot be reduced. The goal is an indicator that moves all the way even while the list is rendering. Transitioning position and width with a single `transform` does that. I also measured, with the same method, the condition this implementation depends on, the layer hints that are tempting to add, and when to read the tab positions.

> Measurements were taken on December 1, 2026, on an Apple M5 running macOS 27.2.1. I ran Chromium 156.0.8078.4 as installed by Playwright 1.64.1 in headless mode, with a 430x480 viewport and DPR 1. Source quotes are from the tag of the same version (commit [`f842f52e`](https://github.com/chromium/chromium/tree/f842f52ef39fd97b449eb27cff414bf05a98ddce)). Mobile devices and other browsers were outside the scope of verification.
>
> The example page (React 18.3.1), the code for each implementation, the measurement scripts, and the measured values are in [blog-experiments `618b256` tab-indicator-main-thread](https://github.com/yceffort/blog-experiments/tree/618b2569a0ac694491648f66a4cb5fab78b418f6/tab-indicator-main-thread). The demos in this post are the same example page. The measurement script taps a tab once and analyzes the trace for the following 700ms. To exclude costs that only occur on the first transition after the browser starts, I tapped two other tabs before each measurement.
>
> The indicator position was measured from the screenshots included in the trace. In the bottom 2px row of the tab bar, the run of dark pixels is taken as the indicator, and the first dark pixel on the vertical center row is taken as the label of the selected tab. The label is read from the strokes of the glyphs, so it is a few px away from the left edge of the tab (12px for the sixth tab).
>
> "The time it arrived under the new tab" is the time of the first frame where the gap between the indicator and the label is within 2px of its final value and the indicator width is within 1.5px of its final value. If you count the frame that matches the final values exactly, the arrival of the `transform` transition on a tab without scrolling is one frame later, at 194-209ms (10 runs, median 203ms). The values for the `left`, `width` transition do not change.
>
> Forced calculations during click handling, and the code that caused them, were identified from the call stacks attached to the `UpdateLayoutTree` and `Layout` events in the trace. Compositing layers and compositing reasons were read through the CDP `LayerTree` domain. The experiment that reads positions with `requestAnimationFrame` inside the page was run separately. The two-thread timelines were drawn by extracting main thread tasks and the compositor thread's `DrawFrame` and `DroppedFrame` events from one traced run of each implementation. That run is different from the one used for the frame tables.

## An indicator moved with left and width

The top of the screen has 12 horizontally scrolling tabs and the bottom has a list of 200 rows. Tapping a tab makes two things happen in order.

1. The tab becomes selected immediately, and the indicator starts moving under the new tab over 200ms. The tab bar also scrolls smoothly so that the selected tab comes to the center of the screen.
2. 30ms later the list data arrives and the 200 rows are rendered again. An empty loop burns 1.5ms per row, so the main thread does nothing but this for about 300ms.

The first implementation that comes to mind for an indicator is to read the position and width of the selected tab, put them into the indicator's `left` and `width`, and put a transition on those two properties.

```css
.indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background-color: #111;
  transition:
    left 200ms ease-out,
    width 200ms ease-out;
}
```

```js
useLayoutEffect(() => {
  const bar = barRef.current
  const tab = tabRefs.current[active]
  const left = tab.offsetLeft
  const width = tab.offsetWidth

  const center = left + width / 2 - bar.clientWidth / 2
  bar.scrollTo({left: center, behavior: 'smooth'})
  indicatorRef.current.style.left = `${left}px`
  indicatorRef.current.style.width = `${width}px`
}, [active, tabs])
```

Moving from the first tab to the second, the indicator position read from the frames that actually reached the screen is as follows.

| After click | Left edge | Width |
| ----------- | --------- | ----- |
| 7.4ms       | 24px      | 31px  |
| 21.8ms      | 30px      | 38px  |
| 38.7ms      | 36px      | 43px  |
| 345ms       | 71px      | 78px  |

In the same trace, the main thread was handling a single task from 32ms to 333ms after the click. After the frame at 38.7ms there was no new frame for about 306ms, and in the next frame the indicator was already at its target. Across 3 measurements the arrival time was 345-346ms. The transition lasts 200ms, yet arrival took 145ms longer than that.

## Why the transition runs on the main thread

To understand this, the roles of the main thread and the compositor thread need to be separated. The main thread runs JavaScript, calculates styles, lays out the position and size of elements, and paints the result. The compositor thread moves and stacks the painted results, in units of compositing layers, and puts them on the screen.

If each frame of an animation only changes the position, size, or opacity of layers that are already painted, the compositor thread can produce frames on its own. This is why an animation can keep moving while the main thread is busy with other work. Properties like `left` and `width`, on the other hand, need a layout calculation every frame, so they have to go through the main thread. The effect of the changed position and size on the placement of elements has to be recalculated.

The Chromium source lists the animation properties that the compositor thread can handle.[^1]

```cpp
constexpr auto kCompositableProperties = std::to_array<CSSPropertyID>(
    {CSSPropertyID::kBackdropFilter, CSSPropertyID::kFilter,
     CSSPropertyID::kOpacity, CSSPropertyID::kRotate, CSSPropertyID::kScale,
     CSSPropertyID::kTransform, CSSPropertyID::kTranslate,
     // The following are native paint worklet properties and compositor support
     // hinges on having a corresponding paint image generator.
     CSSPropertyID::kBackgroundColor, CSSPropertyID::kClipPath});
```

`transform`, `translate`, `scale`, `rotate`, `opacity`, `filter`, and `backdrop-filter` are there. `left` and `width` are not.

The `left` and `width` transitions are each recorded in the trace as an `Animation` event. A transition that cannot run on the compositor thread also carries its failure reasons. Here is part of the event for the `left` transition.

```json
{"name":"Animation","ph":"b","args":{"data":{"displayName":"left","nodeName":"SPAN class='indicator'","state":"running"}}}
{"name":"Animation","ph":"n","args":{"data":{"compositeFailed":8224,"unsupportedProperties":["left"]}}}
```

The `width` transition had the same value. 8224 is the sum of `1 << 13` and `1 << 5`. In the Chromium source the former is the failure reason named `kUnsupportedCSSProperty` and the latter is `kTargetHasInvalidCompositingState`.[^2] The property is not supported by the compositor thread, and the target element has no compositing layer either.

A transition running on the main thread calculates its current value from the time elapsed since it started, each time a frame is produced. For the 300ms of list rendering, that calculation could not run. By the time the next frame could be produced, the 200ms transition duration had already passed, so the indicator was painted straight at its final position. With no frames in between, it looked like it stopped and then jumped.

Extracting the work of the two threads from the trace and laying it out in time order gives the following.

<LiveDemo src="/demos/tab-indicator-transform-transition/timeline.html?v=left-width&lang=en" title="What the main thread and the compositor thread did after the tap when transitioning left and width. The horizontal axis is time since the click" height={370} />

The main thread produced 3 frames before list rendering started, and the indicator position was only updated then. For the following 301ms of list rendering it kept handling a single task and could not produce a new frame. The compositor thread started a frame about every 16.7ms, but it never received an updated position from the main thread. During these 301ms the trace recorded 17 `DroppedFrame` events, which mark frames that could not be sent out.

At 332ms, when list rendering ended, the main thread produced the next frame, and at 344ms, when that frame reached the screen, the indicator arrived at its final position.

## Expressing position and width as a transform

For the indicator to move during list rendering, the transition has to be able to run on the compositor thread. To get there, position and width are expressed with a single `transform`.

```css
.indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 2px;
  background-color: #111;
  transform: translateX(0) scaleX(0);
  transform-origin: 0 0;
  transition: transform 200ms ease-out;
}
```

```js
useLayoutEffect(() => {
  const bar = barRef.current
  const tab = tabRefs.current[active]
  const left = tab.offsetLeft
  const width = tab.offsetWidth

  const center = left + width / 2 - bar.clientWidth / 2
  bar.scrollTo({left: center, behavior: 'smooth'})
  indicatorRef.current.style.transform = `translateX(${left}px) scaleX(${width})`
}, [active, tabs])
```

The indicator's width is fixed at 1px and stretched to the tab width with `scaleX()`. Because `transform-origin` is the left edge, it stretches to the right from the position it was moved to with `translateX()`.

The initial value is declared as `translateX(0) scaleX(0)` rather than just `scaleX(0)` so that the function lists before and after the transition match. The specification compares the two lists from the start. Functions that have the same name, or are derived from the same primitive function, are interpolated pair by pair. For example, `translateX()` and `translateY()` are both derived from `translate()`. When a pair does not meet this condition, the remaining functions are combined into matrices and interpolated.[^3]

With the function lists matched, `translateX()` and `scaleX()` are each interpolated, so the position and width in the intermediate frames are the same as when transitioning `left` and `width`.

<LiveDemo src="/demos/tab-indicator-transform-transition/index.html?v=transform&set=left-width,transform&hint=compare&lang=en" title="The transform transition and the left, width transition. With the transform transition the indicator arrives before the list changes" height={532} />

The frames measured with the same method are as follows. Frames were presented about every 16.5ms, and the table shows only some of them.

| After click | Left edge | Width |
| ----------- | --------- | ----- |
| 7.2ms       | 24px      | 31px  |
| 20.9ms      | 30px      | 38px  |
| 32.3ms      | 36px      | 43px  |
| 65.1ms      | 47px      | 54px  |
| 97.9ms      | 56px      | 63px  |
| 131.3ms     | 64px      | 70px  |
| 164.6ms     | 69px      | 76px  |
| 181.3ms     | 71px      | 77px  |
| 198ms       | 71px      | 78px  |

The main thread was again rendering the list from 32ms to 333ms, but frames kept being presented. The position and width in the first three frames were the same as with the `left`, `width` transition. No compositing failure was recorded for the `transform` transition, and the number of main thread layouts in the 700ms after the click went from 4 to 1. The remaining one was the layout needed for list rendering.

Across 3 measurements the indicator arrived at 179-188ms. Ten more measurements under the same conditions gave 178-192ms (median 187ms). The final position and width were 71px and 78px, the same as with the `left`, `width` transition.

Putting the timelines of the two implementations side by side makes the difference clearer.

<LiveDemo src="/demos/tab-indicator-transform-transition/timeline.html?v=both&lang=en" title="What the main thread and the compositor thread did with the left, width transition and with the transform transition" height={634} />

The work done by the main thread was almost the same in both implementations, and list rendering took the same 301ms. With the `transform` transition the compositor thread drew 11 frames during that time and no `DroppedFrame` was recorded. The new style and the transition had been handed to the compositor thread at 3.5ms, before the long task started, so the frames after that could be produced without going through the main thread. This step, where the main thread calculates the new style and hands it to the compositor thread, is called a commit.

### When the tab bar scrolls along

When the tab bar scrolls along, the symptom of the `left`, `width` transition is more noticeable. Selecting the sixth tab from the first scrolls the tab bar by 162px. I compared the horizontal positions of the selected tab's label and the indicator.

| After click   | Label of the selected tab | Left edge of the indicator |
| ------------- | ------------------------- | -------------------------- |
| 8.1ms         | 365px                     | 24px                       |
| 36ms          | 349px                     | 94px                       |
| 65.6ms        | 309px                     | 54px                       |
| 84.1ms        | 266px                     | 11px                       |
| 131.8-231.8ms | 220px → 203px             | off screen                 |
| 343.8ms       | 203px                     | 191px                      |

The scroll continued during list rendering, so the label kept moving left. But the indicator's transition, running on the main thread, was stopped. The indicator, having moved only a little, went off the left side of the screen together with the tab bar and then appeared under the new tab at 344ms.

The scroll of this tab bar did not stop because Chromium ran the scroll animation created by `scrollTo({behavior: 'smooth'})` on the compositor thread.[^4]

```cpp
    bool sent_to_compositor = false;
    if (!scrollable_area_->ShouldScrollOnMainThread()) {
      auto animation = cc::KeyframeModel::Create(
          animation_curve_->Clone(),
          cc::AnimationIdProvider::NextKeyframeModelId(),
          cc::AnimationIdProvider::NextGroupId(),
          cc::KeyframeModel::TargetPropertyId(
              cc::TargetProperty::SCROLL_OFFSET));
      if (AddAnimation(std::move(animation))) {
        sent_to_compositor = true;
        run_state_ = RunState::kRunningOnCompositor;
      }
    }
```

Unless the area has to scroll on the main thread, Chromium adds the animation that changes the scroll offset to the compositor thread. It runs on the main thread only when it could not be added. This tab bar is an area scrolled as a compositing layer, so it was handled on the compositor thread.

The two animations started by a single tab selection were running on different threads. While the scroll kept going on the compositor thread, the indicator had to wait for the main thread's work to finish. With the `transform` transition both run on the compositor thread. In all 3 measurements the indicator kept moving during the scroll and arrived under the new tab at 210-218ms. The final position and scroll offset were the same in both implementations.

## What layer hints cannot change

It is tempting to think that keeping the `left` and `width` transition and turning the indicator into a compositing layer would solve this. I added `will-change` and a 3D transform, two common ways of creating a layer, one at a time and measured.

### `will-change: left, width`

`will-change` tells the browser in advance what kind of change an element is going to have. The specification describes it as a rendering hint that has no direct effect on the element, apart from the cases where it creates a stacking context or a containing block.[^5] Properties that create a stacking context or a containing block depending on their value, like `transform`, fall under that exception. `width` and `left` do not. What to prepare in response to the hint is up to the browser.

Chromium creates a compositing layer in advance when it receives a hint for certain properties. Which properties those are can be seen in the following code.[^6]

```cpp
      case CSSPropertyID::kOffsetPath:
      case CSSPropertyID::kOffsetPosition:
      case CSSPropertyID::kTop:
      case CSSPropertyID::kLeft:
      case CSSPropertyID::kBottom:
      case CSSPropertyID::kRight:
        has_will_change_other = true;
        break;
      default:
        break;
    }
  }
  // kWillChangeOther is needed only when none of the explicit kWillChange*
  // reasons are set.
  if (reasons.empty() && has_will_change_other) {
    reasons.Put(CompositingReason::kWillChangeOther);
  }
```

The earlier part of this `switch` lists the compositing reasons for `opacity`, `transform`, `filter`, and so on. In the quoted part, `top`, `left`, `bottom`, and `right` use `kWillChangeOther` as their compositing reason. `width` is not in the list and falls through to `default`.

Applying each property to the indicator separately and checking the list of compositing layers gives the same result.

| Property applied to the indicator | Compositing layer for the indicator |
| --------------------------------- | ----------------------------------- |
| None                              | No                                  |
| `will-change: left, width`        | Yes (`WillChangeOther`)             |
| `will-change: width`              | No                                  |
| `will-change: left`               | Yes (`WillChangeOther`)             |
| `will-change: transform`          | Yes (`WillChangeTransform`)         |
| `transform: translate3d(0, 0, 0)` | Yes                                 |
| `transform: translateX(0)`        | No                                  |

In `will-change: left, width`, the property that triggered the layer was `left`. With `width` alone, no layer was created.

In the implementation with this hint added, `compositeFailed` for the two transitions went from 8224 to 8192. The reason that the target element has no compositing layer was gone, but the reason that the property is unsupported remained. The indicator arrived at 343-346ms in all 3 measurements. `will-change` only created a layer. It did not move the `left` and `width` transitions to the compositor thread.

### `transform: translate3d(0, 0, 0)`

Promoting an element to its own compositing layer with a 3D transform is a long-standing technique. Adding `translate3d(0, 0, 0)` makes the indicator a compositing layer. But the `left` and `width` transitions still failed to composite with 8192, and the indicator appeared at its target at 344-347ms in all 3 measurements.

<LiveDemo src="/demos/tab-indicator-transform-transition/index.html?v=left-width-will-change&set=left-width,left-width-will-change,left-width-translate3d&hint=hints_hint&lang=en" title="The left, width transition with layer hints added. With the hints the indicator still stalls at the same spot" height={532} />

Having a separate compositing layer does not mean that the element's animation also runs on the compositor thread. A layer is a unit that holds a painted result separately. If a layout property changes every frame, the main thread still has to calculate the values, layer or not.

### `will-change: transform`

Conversely, I checked whether the `transform` transition needs `will-change: transform`. As the table above showed, this value creates the indicator's compositing layer in advance.

Without `will-change: transform`, the `transform` transition still ran on the compositor thread. When there is a running `transform` animation, Chromium assigns `kActiveTransformAnimation` as a compositing reason and creates a layer.[^7]

I made a separate implementation that always sets `will-change: transform` and measured it 10 times. The arrival time was 176-192ms (median 187ms), in the same range as the 178-192ms (median 187ms) without it. What did change was the number of layers at rest. Without the hint, the indicator is a layer only during the transition. With the hint, the layer is kept while it is still. On this screen the total number of layers went from 7 to 8. Since the measurements showed no improvement, I concluded this setting does not need to be added.

## The commit that has to finish before the long task

The `transform` transition also needs the main thread at the moment it starts. If a long task starts before the commit that hands the transition to the compositor thread, the transition only starts after that task ends.

Under the default condition, where the list data arrives after 30ms, the commit finished first. I also measured with the delay reduced to 0ms. This is the case where the task handling the tab click schedules list rendering with a 0ms timer. One traced run of that case, in time order, looks like this.

| After click | Thread     | What happened                                 |
| ----------- | ---------- | --------------------------------------------- |
| 0ms         | Main       | Click handling (2.4ms). Schedules a 0ms timer |
| 2.7ms       | Main       | Frame starts                                  |
| 3.7ms       | Main       | Commit                                        |
| 3.9ms       | Main       | Timer runs. List rendering starts             |
| 4.5ms       | Compositor | Draws the first frame                         |
| 7ms         | Compositor | Next frame starts                             |

After click handling ended, the main thread handled the frame before the timer. The commit was 0.2ms ahead of the start of list rendering.

I measured a mouse click and a `click()` called inside a timer, 3 times each for the two implementations, 12 runs in total. In 11 runs the commit was 0.3-0.7ms ahead of the start of the long task. In the remaining run, list rendering started first and the first commit was pushed back to 312ms. That run happened while measuring the `left`, `width` transition, so it did not affect the result. But if the same order occurs with the `transform` transition, the indicator only departs after list rendering ends. In the 6 runs that measured the `transform` transition, the commit came first every time and the indicator arrived at 192-224ms. The margin is under 1ms, so the same order cannot be expected on every device or under every condition.

If the list is rendered right inside the same task as the click, the order is always reversed. This is the case where the data is already in a cache and the tab selection and the list update are rendered at once.

|                            | Long task      | First commit | Arrival   |
| -------------------------- | -------------- | ------------ | --------- |
| `left`, `width` transition | Click to 308ms | 309ms        | 486-497ms |
| `transform` transition     | Click to 308ms | 309ms        | 494-496ms |

In this case the indicator cannot move during list rendering even with the `transform` transition. In both implementations it started moving from the frame at 314ms, after list rendering ended, and moved for 200ms. You can turn on the switch in the demo below and compare the two implementations.

<LiveDemo src="/demos/tab-indicator-transform-transition/index.html?v=transform&set=left-width,transform&sync=1&hint=sync_hint&lang=en" title="When the list is rendered in the same task as the click, the transform transition also departs late" height={568} />

In this case the point where list rendering starts has to be adjusted so that the commit handing the transition to the compositor thread finishes first. For the `transform` transition to have an effect, the transition must already have been handed to the compositor thread before list rendering starts.

## When to read tab positions

The implementation above reads the `offsetLeft` and `offsetWidth` of the selected tab every time a tab is selected. Reading `offsetLeft` can make the browser run the style and layout calculations it had deferred, right away (forced synchronous layout). So it is tempting to measure the tab positions once, remember them, and use the remembered values on selection.

```js
// 탭 목록이 바뀔 때만 위치를 재서 기억해 둔다
const positions = useRef([])
useLayoutEffect(() => {
  positions.current = tabRefs.current.map((tab) => ({
    left: tab.offsetLeft,
    width: tab.offsetWidth,
  }))
}, [tabs])

useLayoutEffect(() => {
  const bar = barRef.current
  const {left, width} = positions.current[active]

  const center = left + width / 2 - bar.clientWidth / 2
  bar.scrollTo({left: center, behavior: 'smooth'})
  indicatorRef.current.style.transform = `translateX(${left}px) scaleX(${width})`
}, [active, tabs])
```

I measured the two implementations 10 times each with the same method.

In the implementation that reads on every selection, the calculation forced during click handling was one style calculation (0.22-0.36ms), and there was no layout calculation. The call stack showed that the line reading `tab.offsetLeft` caused it. In the implementation that remembers positions, one style calculation (0.21-0.30ms) still occurred. This time `bar.clientWidth`, which reads the width of the tab bar, caused it.

`clientWidth`, like `offsetLeft`, returns its value after finishing the necessary style and layout calculations. The two implementations in Chromium call the same function before calculating the value.[^8][^9]

```cpp
  GetDocument().UpdateStyleAndLayoutForNode(this,
                                            DocumentUpdateReason::kJavaScript);
  if (const auto* box = GetLayoutBox()) {
```

```cpp
int HTMLElement::OffsetTopOrLeft(bool top) {
  GetDocument().UpdateStyleAndLayoutForNode(this,
                                            DocumentUpdateReason::kJavaScript);
```

The first is `Element::clientWidth()` and the second is the implementation of `offsetLeft`. If there is a deferred calculation, the function called first handles it, and the function called after that uses the calculated values. The style calculation that became necessary when the selected state of the tabs changed has to run once in either implementation. Even without reading the tab position, the same calculation runs when the tab bar width is read, so the amount of calculation did not go down.

No difference showed up in the indicator's arrival time either. The implementation that reads on every selection arrived at 178-192ms (median 187ms), and the one that remembers positions at 175-194ms (median 181ms).

### When the font size changes

Remembering positions, on the other hand, leaves the indicator misaligned after the size of the tabs changes. With a tab selected, I grew the label font from 18px to 24px, then tapped the next tab and measured the difference in position and width.

|                          | Right after the font change | After tapping the next tab |
| ------------------------ | --------------------------- | -------------------------- |
| Reads on every selection | Left 10.5px, width 25.8px   | Left 0.3px, width 0.3px    |
| Remembers positions      | Left 10.5px, width 25.8px   | Left 36.3px, width 15.3px  |

Right after the font changed, the indicator was misaligned in both implementations. The implementation that reads on every selection realigned when the next tab was tapped, but the one that remembers positions stayed misaligned until the tab list changed. Remembering positions improved neither the amount of calculation nor the arrival time, and only made the behavior after a size change worse.

Positions do not change in every situation where the screen changes. When I selected a tab in portrait 390x844 and then rotated to landscape 844x390, the difference between the indicator and the tab was the same 0.4px as before, in every implementation. A tab's position is a coordinate inside the tab list, so it held even when the screen width changed. A font size change and a screen rotation need to be looked at separately.

### Staying aligned right after the change

Even in the implementation that reads on every selection, the indicator is 10.5px off the selected tab from right after the font change until the next tab is tapped. On a screen that follows the system font size setting, this can actually happen. Registering a `ResizeObserver` on each tab and realigning the indicator when a size changes solves it.

```js
const activeRef = useRef(active)
activeRef.current = active

// 탭의 크기가 바뀌면 인디케이터를 다시 맞춘다
useEffect(() => {
  const observer = new ResizeObserver(() => {
    const tab = tabRefs.current[activeRef.current]
    indicatorRef.current.style.transform = `translateX(${tab.offsetLeft}px) scaleX(${tab.offsetWidth})`
  })
  tabRefs.current.forEach((tab) => observer.observe(tab))
  return () => observer.disconnect()
}, [tabs])
```

With this, the difference right after the font change went down to 0.5px left and 0.2px in width. The arrival time across 10 measurements was 176-192ms (median 187ms), the same as the other implementations.

<LiveDemo src="/demos/tab-indicator-transform-transition/index.html?v=transform&set=transform,transform-cached,transform-observer&font=1&hint=font_hint&lang=en" title="The indicator after the font size changes. Pick a tab, grow the font, then tap another tab" height={568} />

`ResizeObserver` has nothing to do with movement during list rendering. Its purpose is to remove the misalignment from right after the font change until the next selection. Adding it means more behavior to check. `ResizeObserver` also calls its callback when observation starts. In this implementation the callback ran once right after the page opened. How to update the observed targets when tabs are added or removed, and how it looks if a size changes during a transition, also have to be checked separately.

## A difference that is hard to see from JavaScript in the page

How the result is verified matters too. If you record the position with `getBoundingClientRect()` on every `requestAnimationFrame` inside the page, you cannot see the difference between the two implementations under this condition. Here is the same click recorded with JavaScript and with screenshots at the same time. Positions are the left edge of the indicator.

|                            | Values read inside the page                          | Values read from screenshots                                                            |
| -------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `left`, `width` transition | 11.8ms 24px, 28.7ms 30px, 338.3ms 36px, 339.1ms 71px | 17ms 24px, 34ms 30px, 343.9ms 36px, 346.3ms 71px                                        |
| `transform` transition     | 16ms 24px, 339.9ms 30px, 341.1ms 71px                | 21ms 24px, 56.7ms 30px, 84.9ms 42px, 118ms 52px, 151.3ms 60px, 184.7ms 67px, 218ms 71px |

The positions recorded inside the page are similar for the two implementations. After moving a little there is no record for over 300ms, and then it becomes 71px. While the main thread is rendering the list, `requestAnimationFrame` callbacks cannot run. In the screenshots of the `transform` transition the indicator had already arrived at 218ms, but the position read with JavaScript at 339.9ms was 30px. The intermediate positions that the compositor thread put on the screen while the main thread could not run cannot be seen in this record.

That is why this post measures positions from the screenshots included in the trace. Frames output while the main thread is stopped cannot be sampled with JavaScript inside the page. The same constraint has to be considered when testing this behavior. Comparing only the positions before and after the long task cannot verify whether the indicator moved smoothly in between.

## The property you transition decides the thread it runs on

The indicator that transitions `left` and `width` stalled for 0.3 seconds because the calculation the transition needs runs on the main thread. For the 301ms it took to render the 200 rows, that calculation could not run and no intermediate frames were produced. Expressing position and width as a `transform` makes the transition run on the compositor thread. List rendering took the same 301ms, but the indicator's arrival time went from 345-346ms to 178-192ms.

Turning the indicator into a compositing layer with `will-change: left, width` or `translate3d(0, 0, 0)` left the `left` and `width` transitions on the main thread, and the arrival time stayed the same. Adding `will-change: transform` to the `transform` transition also gave the same arrival time and only added one layer.

The `transform` transition has a precondition. The transition must have been handed to the compositor thread by a commit before list rendering starts. If the list is rendered in the same task as the click, the `transform` transition also arrives at 494-496ms, so in that case the point where list rendering starts has to be adjusted.

Reading the tab position on selection was enough. Remembering positions still left the forced style calculation in place when the tab bar width was read, and after a font size change the indicator stayed misaligned. If even the 10.5px from right after the font change until the next selection has to be fixed, that is the time to add a `ResizeObserver`.

[^1]: [Chromium `f842f52e` `third_party/blink/renderer/core/animation/compositor_animations.cc` L78-L84](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/animation/compositor_animations.cc#L78-L84)

[^2]: [Chromium `f842f52e` `third_party/blink/renderer/core/animation/compositor_animations.h` L90-L105](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/animation/compositor_animations.h#L90-L105)

[^3]: [CSS Transforms Module Level 1, W3C Candidate Recommendation 2019-02-14, 11. Interpolation of Transforms](https://www.w3.org/TR/2019/CR-css-transforms-1-20190214/#interpolation-of-transforms)

[^4]: [Chromium `f842f52e` `third_party/blink/renderer/core/scroll/programmatic_scroll_animator.cc` L164-L177](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/scroll/programmatic_scroll_animator.cc#L164-L177)

[^5]: [CSS Will Change Module Level 1, W3C Candidate Recommendation Draft 2022-05-05, 2. Hinting at Future Behavior: the will-change property](https://www.w3.org/TR/2022/CRD-css-will-change-1-20220505/#will-change)

[^6]: [Chromium `f842f52e` `third_party/blink/renderer/core/paint/compositing/compositing_reason_finder.cc` L121-L138](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/paint/compositing/compositing_reason_finder.cc#L121-L138)

[^7]: [Chromium `f842f52e` `third_party/blink/renderer/core/paint/compositing/compositing_reason_finder.cc` L570-L572](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/paint/compositing/compositing_reason_finder.cc#L570-L572)

[^8]: [Chromium `f842f52e` `third_party/blink/renderer/core/dom/element.cc` L2651-L2653](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/dom/element.cc#L2651-L2653)

[^9]: [Chromium `f842f52e` `third_party/blink/renderer/core/html/html_element.cc` L4372-L4374](https://github.com/chromium/chromium/blob/f842f52ef39fd97b449eb27cff414bf05a98ddce/third_party/blink/renderer/core/html/html_element.cc#L4372-L4374)
