LearnNewsExamplesServices
Frontmatter
id18881
titleDomAccess.measure reads the wrong node back for em and rem lengths
stateClosed
labels
bugaicore
assigneesneo-opus-grace
createdAtSep 18, 2026, 2:59 PM
updatedAtSep 18, 2026, 5:34 PM
githubUrlhttps://github.com/neomjs/neo/issues/18881
authorneo-fable-clio
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 18, 2026, 5:34 PM

DomAccess.measure reads the wrong node back for em and rem lengths

neo-fable-clio
neo-fable-clio commented on Sep 18, 2026, 2:59 PM

Context

Found by reading while scoping #18874, where measure is the nearest sibling of the read that ticket adds. Verified at dev@b13719d1c1 by reading only: nothing in the repository exercises the branch, so there is no runtime sighting. Captured first as an A2A defect-note (2026-09-18), promoted here on the operator's escalation so it is not lost.

The Problem

Neo.main.DomAccess.measure({id, value}) converts one CSS length to px. For any unit other than px / % it sizes an off-screen measuring div and is meant to read that div's computed width back. It reads the original node's instead:

const elStyle = node.ownerDocument.defaultView.getComputedStyle(node);   // :788 — the node
…
d.style.width = value;                                                   // :806 — the measuring div
// Read back the resulting computed pixel width
value = elStyle.width;                                                   // :809 — the node again

So measure({id, value: '2em'}) answers the node's own width, as a String ('412px'), where its caller component.Base#measure documents Promise<number>. Unchanged since the method arrived in 16c9246418 (2023-09-10, floating auto-align, #4851).

The Architectural Reality

  • src/main/DomAccess.mjs:778 measure — a remote method (the remote.app list, :84).
  • Callers, repo-wide (grep -rnE "\bmeasure\(" over src apps examples test learn): two.
    • src/component/Base.mjs:1669 measure(value) forwards to the remote. Nothing calls it, today or at the introducing commit.
    • DomAccess#getBoundingClientRect (:498, :501) passes the computed min-width / min-height. A computed length is already px, so from here only the parseFloat branch runs; the comment above it ("in other units like em/rem etc") names a case the computed style has already resolved.
  • Both callers gate on lengthRE = /^\d+\w+$/ (DomAccess.mjs:9, component/Base.mjs:17). Measured with node -e: 14.4px, 1.5em and 50% all fail it. Consequences, by reading:
    • a computed min-width of 14.4px (0.9em at 16px) never lands on the rect, so Rectangle#constrainTo (src/util/Rectangle.mjs:357, me.minWidth || me.width) takes the current width as the minimum and answers false for any tighter constraint;
    • component.measure('1.5em') and component.measure('50%') return their input String unchanged;
    • the % branch (always the offsetParent's height, for a width too) is reachable only through a direct remote call.

Net: the unit branch is wrong and unreachable from engine code today; what IS reachable is the regex gap on fractional computed minimums.

The Fix

Recommended (A) — keep the documented contract and make it true:

  1. measure: read getComputedStyle(d).width, parseFloat it, return a Number on every branch.
  2. lengthRE at both sites: admit a fractional number. Decide % explicitly — axis-correct and reachable, or removed; the PR says which.
  3. Arms in the component tier (the defect IS which node's computed style is read, so it needs a real DOM): 2em on a node with a known font-size answers 2 × font-size as a Number, not the node's width — red first; a fractional computed min-width lands on the rect.

Alternative (B) — delete the unreachable surface: component.Base#measure plus the unit and % branches, leaving parseFloat for the rect's computed minimums. Falsifier for A over B: a public remote and a public component method can have workspace callers this repository cannot see, so B is a breaking removal and the operator's release call. Falsifier for B over A: if no consumer is ever named, A maintains code nothing runs.

Contract Ledger

Target surface Source of authority Proposed behaviour Fallback Docs Evidence
Neo.main.DomAccess.measure (remote) src/main/DomAccess.mjs:778 a Number of px for any CSS length; the unit branch reads the measuring div none method docblock, @returns {Number} red-first component arm
Neo.component.Base#measure src/component/Base.mjs:1669 signature unchanged; fractional lengths reach the remote none docblock arm
rect.minWidth / rect.minHeight from getBoundingClientRect src/main/DomAccess.mjs:497 fractional computed minimums are reported none — arm

Decision Record impact: none.

Acceptance Criteria

  • A red-first arm shows measure answering the node's width for an em length on dev, and 2 × font-size as a Number after the fix.
  • measure returns a Number on every branch.
  • A fractional computed min-width / min-height is reported on the rect (arm).
  • The % branch is either axis-correct and reachable, or removed — the PR says which and why.
  • If (B) is chosen instead: the operator's ruling is linked and the removal is listed as breaking.

Out of Scope

  • The natural-size read #18874 adds beside measure — a different question (an element's own height, batched across ids).
  • Floating / align behaviour beyond the min-size report.

Avoided Traps

  • Fixing only the readback: getComputedStyle(d).width still answers '32px', a String.
  • An arm in the unit tier over a stubbed DOM: a stub cannot tell which node's style was read.

Related

#18874 — scoped beside this method; found there.

Live latest-open sweep: latest 20 open issues read at 2026-09-18T12:58:15Z, no equivalent. A2A in-flight sweep: newest inbox rows to 12:57:16Z, no claim on this surface. Content grep (DomAccess[.#]measure|measuringDiv over resources/content/issues + discussions): no hit. MC sweep: DomAccess measure em rem length converted to px returns the node's own width as a String, measuring div, minWidth minHeight floating align, 6 results, no prior decision found (the one hit is this finding's own turn). Own-assignment sweep: 5 open, none overlapping (#18874 names measure as a sibling, not this defect).

unowned-rationale: latent — no engine caller reaches the wrong branch — small, and claimable by any seat; the filer's lane is #18874, the same file but a different method.

Origin Session ID: 1ef6c04a-10f6-4977-ad7d-0e2c7f343c59 Retrieval Hint: "DomAccess measure em readback wrong node String lengthRE fractional"