Tarik Al Hadethi Download CV

Verified on the wrong engine

I spent six rounds fixing the same bug because every measurement I took said it was already fixed. The measurements were honest. They were taken on the one browser that implements the property correctly.

The Clarus site has animated mockups of the app: a browser window scrolling itself, a recording desk, an editor with a timeline. They are DOM and CSS rather than video, and they are laid out for a desktop-width column. On a phone they have to shrink.

The obvious tool is CSS zoom, and it worked. Measured at a real 375 px viewport, each stage laid out at exactly its desktop width, no part was missing, and nothing overflowed. I checked repeatedly, because the report kept coming back.

The report was: the recording background looks zoomed in, the editor toolbar is out of place, text is cut off. On an iPhone.

What zoom actually does

zoom does not scale a finished picture. It re-runs layout at the scaled size, and it is a legacy property in WebKit rather than a first-class one. That leaves room for engines to disagree about backgrounds and about absolutely-positioned descendants, which is precisely what the report described.

So the situation was: correct on Chromium, wrong on WebKit, and every instrument I owned was Chromium. I have no Safari. Headless Chrome is Chromium. The browser tooling I drive is Chromium. Each check confirmed the engine that had never been broken.

A bug in a property one engine implements correctly cannot be verified on that engine. The measurement will be true and useless.

The primitive that has no opinion

transform: scale() is a pure paint operation. Layout happens once, at full size, and the finished result is scaled. There is nothing left for a second engine to interpret differently, which makes it the right tool whenever cross-engine agreement matters more than convenience.

Switching primitives surfaced four more problems, none of which any compiler could see:

  • The scale could not go on the element itself. Several stages carry an entrance animation that also uses transform, so my inline transform was simply overwritten. One came back as the entrance animation’s translate with no scale at all. The scale needs an element of its own with nothing else competing for that property.
  • zoom and transform compound. The old CSS was still in the sheet as a no-JS fallback, so the stages painted at 0.3025 × 0.52, about half the intended size. The new code has to cancel the thing it replaces.
  • A 1fr grid track is minmax(auto, 1fr), and that auto floor will not shrink below its content’s min-content width. The scaler is design-width wide, so the column grew to match and the page scrolled sideways by 162 px. Worse, the first scaling pass measured that inflated column, concluded no scaling was needed, and skipped those stages entirely.
  • clientWidth includes padding. Reading available space from a wrapper with 28 px of padding gave 390 where the content box was 334, so the stage came out 945 px against a 1104 px design and the text re-wrapped anyway.

Scaling and being 1:1 are different claims

The subtler mistake underneath all of this: a stage can be scaled and still not match. At zoom: 0.52 a 1104 px stage gets 613 px of internal room. Positions written as percentages scale with it. Text does not. 13 px stays 13 px in a narrower box, so it re-wraps: a chat line that fits on one row at desktop breaks onto two.

Same composition, different line breaks, and not 1:1. The fix is to give the stage its full design width and scale that down, so every line break is the desktop one.

The guard

There is now a checker that renders the page at four widths and asserts every stage lays out at exactly its design width, that none is nested inside another (the scales compound), and that the parts visible on desktop are visible on a phone. It runs three negative controls every time, and all three are caught.

Writing it taught me one more thing worth keeping: the guard needed the same fix twice. getBoundingClientRect is post-scale while currentCSSZoom stays 1, so a 20 px part reads as 6 px at scale 0.3 and every scaled stage looked like it had lost content. My first version reported failures that were entirely artifacts of the measurement.

Which is the same lesson as the browser, one level up. Before trusting what an instrument tells you about a bug, check what the instrument is actually able to see.

Written while building Clarus.  ·  More writing