# Tapping every button on a cheap phone: everything worked, the slow part was restyling the whole page

> I tapped through every button on my site on a Galaxy A21s with real touch events and ran dark mode too. All 23 steps worked; the slow parts were whole-page style recalculation, not JavaScript.

- Date: 2026-12-01
- Topics: Performance, Accessibility, Debugging
- Chinese original: https://kbs0830.com/blog/a21s-buttons-dark-mode

[The previous post](/en/blog/galaxy-a21s-real-phone-testing) turned the Galaxy A21s I had lying around into a test device, and measured page load and scrolling. This time I wanted to test two other things: dark mode, and the animation of every single button.

## How to "tap"

The script connects to Chrome on the phone over the Chrome DevTools Protocol and sends real touch events (`Input.dispatchTouchEvent`, touchStart then touchEnd), not `element.click()`. A tap on a phone takes its own path: touch first, then converted to pointer events, and only then a click. Testing with real touches exercises the same path a visitor's finger does.

Playwright has `locator.tap()`, but when you attach to a phone through `connectOverCDP` the default context does not have `hasTouch` enabled, so the call just throws. So I send the events myself.

There are 23 steps in total: opening and closing the home page menu, opening and closing the Ctrl+K quick jump, switching between light and dark, the About tabs and skill expanders, the project filter, back to top, going from a project card to its detail page, the blog topic and series expanders, search, the sub-page menu, the article table of contents, "next post", and the election map's dataset switch and bottom drawer.

Each step records four things:

- **Did the state really change**: `aria-expanded`, `<dialog open>`, `<details open>`, `data-theme`, the URL. If it did not change, it is broken
- **Response time**: measured with Event Timing, from finger-up to the next paint. It is the same kind of measurement as INP in the Core Web Vitals
- **Frames the screen actually received**: I ask Android's SurfaceFlinger for the longest gap between frames and how many gaps were over 50 ms
- **Long frames on the main thread**: the longest frame is split into script, forced style recalculation, and time no script claims

I do not look at "dropped frames" here. Chrome only sends a new frame when something on screen changed, and the home page background animation is fixed at 30 draws per second, so a 33 ms gap between two frames is normal and does not mean jank.

## Result: everything works

Two rounds in light mode and one in dark mode, all 23 steps passed. I looked at the dark mode screenshots one by one, and nothing was wrongly colored in the menu, dialogs, tabs, or the map.

I also ran axe (the automated accessibility checker) directly on the phone, on 6 pages each in dark and light: **zero contrast problems**. There was one problem unrelated to dark mode: a long code block in an article scrolls sideways at phone width, but cannot be focused with the keyboard, so you cannot scroll it with the arrow keys (`scrollable-region-focusable`). On a desktop the screen is wide enough for the code to fit, so the accessibility tests I had been running on the desktop never caught it. The fix is to make `<pre>` focusable (`tabIndex={0}`), and the accessibility test now includes an article page at phone width.

## None of the slow parts were JavaScript

Response times were mostly between 100 and 350 ms. On this phone, the slower ones were:

| Interaction | Tap to visual response | Where the time went |
|---|---|---|
| Quick jump opening | 544–656 ms | 138 ms of forced style recalculation |
| Quick jump closing | 360–464 ms | 193 ms not claimed by any script |
| Light/dark toggle | 112–240 ms | about 150 ms of whole-page style recalculation at the moment of the switch |
| Home page menu opening | 312–344 ms | no long frame on the main thread |

The most common pattern was **no long frame on the main thread, yet a 300 ms response**. Menus and expanders, where new content appears for the first time, all behave like this. Neither JavaScript nor style took much time. My guess is that the time goes into rasterizing the new content into pixels, the same as in [the home page scrolling post](/en/blog/galaxy-a21s-real-phone-testing): this phone does its rasterization on a single thread. I did not confirm this directly.

Quick jump is a different case. When it opens, script runs for 152 ms, 138 ms of which is "forced style and layout recalculation". The dialog is a native `<dialog>` opened with `showModal()`. While a modal dialog is open, everything outside it becomes inert (cannot be clicked or focused), so every element on the page has its style recomputed. The home page has over 3,400 elements, which costs 140 to 190 ms on this phone. Closing it does the same again, and this time the browser does it itself, so it is not counted against any script.

The light/dark toggle is the same story: change one attribute and every color on the page has to be recomputed.

## A fix along the way, and an A/B test I got wrong

While looking into quick jump I found that it rendered links to all 57 to 72 pages of the site **even while the dialog was closed**. In other words, every page's HTML carried an invisible list, and every page had to process those extra elements. I changed it to render only when opened, attached one beat later with `useDeferredValue`. Every page now has about 230 fewer elements; article pages went from 933 to 702.

At first I thought opening had also gotten faster: the old version on the live site measured 592 to 656 ms, and the new version on the test server 520 to 552 ms.

After deploying, I measured again on the live site: opening took 544 to 648 ms, overlapping the old range, so **it did not get faster**. The first set of numbers compared two environments, not two versions of the code: the test server uses temporary data and does not go through Cloudflare, while the live site has both. The home page element counts differed by only 21 between them, so page size is not the cause. Which of those factors made the test server faster, I did not investigate.

So an A/B comparison has to happen in a single environment: either both against the live site (before and after deploy), or both against the test server (same data, only the code differs).

I kept the change anyway: every page has 230 fewer unused elements, so there is less to process at load. It just did not make the dialog open faster. To make opening and closing faster, whole-page style recalculation has to get cheaper, for example by having fewer elements on the home page, or by letting off-screen sections skip style calculation. I have not done that yet.

## How to use it from now on

- `node scripts/phone-interact.mjs`: tap through all 23 steps. `--dark` uses dark mode, `--only menu,theme` runs only the steps whose names contain those words, `--base http://localhost:<port>` tests a version that is not deployed yet
- `node scripts/phone-check.mjs --dark --axe`: measure every page in dark mode and run axe on the phone

Both scripts switch to dark only inside the tab they open themselves, and never touch the theme saved on the phone. The theme toggle writes to localStorage; the scripts also intercept that write so it is only remembered in that tab.

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/a21s-buttons-dark-mode
