fix(css): resolve em against the element font-size - #221
Merged
Merged
Conversation
LeadcodeDev
force-pushed
the
fix/em-font-size
branch
2 times, most recently
from
September 21, 2026 23:43
9ad0f9d to
95ffad7
Compare
53 tasks
LeadcodeDev
force-pushed
the
fix/em-font-size
branch
2 times, most recently
from
September 22, 2026 08:36
3b3111e to
5b5c226
Compare
build() (layout_pass.rs:122-154) hands the *same* ConversionContext to to_taffy_style for every node in the tree and never re-derives it from the node's own (cascaded) font-size, and the only production builder keeps ..LengthContext::default() → font_size: 16.0 (scene.rs:29-37). So padding: "1em", gap: "0.5em", width: "10em", top: "2em" all resolve against 16px regardless of the element's actual font size: on a 48px-font card, padding: "1em" reserves 16px instead of 48px. Unlike the context-free .px() accessors — which were deliberately made to warn loudly for exactly this class of drop (units.rs:240-256) — this path is silent, so the wrong geometry reaches both the renderer and the validator with no signal. Fix: Derive a per-node LengthContext while building the taffy tree: resolve the node's own font-size (post-cascade) to px and pass it as ctx.length.font_size to its own to_taffy_style call and to its children's. Until that exists, emit the same one-shot warning order already uses (taffy_bridge.rs:142-151) whenever an em reaches this bridge. Refs #220
LeadcodeDev
force-pushed
the
fix/em-font-size
branch
from
September 22, 2026 08:46
5b5c226 to
498b1bc
Compare
LeadcodeDev
added a commit
that referenced
this pull request
Sep 22, 2026
build() (layout_pass.rs:122-154) hands the *same* ConversionContext to to_taffy_style for every node in the tree and never re-derives it from the node's own (cascaded) font-size, and the only production builder keeps ..LengthContext::default() → font_size: 16.0 (scene.rs:29-37). So padding: "1em", gap: "0.5em", width: "10em", top: "2em" all resolve against 16px regardless of the element's actual font size: on a 48px-font card, padding: "1em" reserves 16px instead of 48px. Unlike the context-free .px() accessors — which were deliberately made to warn loudly for exactly this class of drop (units.rs:240-256) — this path is silent, so the wrong geometry reaches both the renderer and the validator with no signal. Fix: Derive a per-node LengthContext while building the taffy tree: resolve the node's own font-size (post-cascade) to px and pass it as ctx.length.font_size to its own to_taffy_style call and to its children's. Until that exists, emit the same one-shot warning order already uses (taffy_bridge.rs:142-151) whenever an em reaches this bridge. Refs #220
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Severity Low, category correctness. Location:
crates/rustmotion-core/src/css/taffy_bridge.rs:292Impact
build()(layout_pass.rs:122-154) hands the sameConversionContexttoto_taffy_stylefor every node in the tree and never re-derives it from the node's own (cascaded) font-size, and the only production builder keeps..LengthContext::default()→font_size: 16.0(scene.rs:29-37). Sopadding: "1em",gap: "0.5em",width: "10em",top: "2em"all resolve against 16px regardless of the element's actual font size: on a 48px-font card,padding: "1em"reserves 16px instead of 48px. Unlike the context-free.px()accessors — which were deliberately made to warn loudly for exactly this class of drop (units.rs:240-256) — this path is silent, so the wrong geometry reaches both the renderer and the validator with no signal.Fix
Derive a per-node
LengthContextwhile building the taffy tree: resolve the node's own font-size (post-cascade) to px and pass it asctx.length.font_sizeto its ownto_taffy_stylecall and to its children's. Until that exists, emit the same one-shot warningorderalready uses (taffy_bridge.rs:142-151) whenever anemreaches this bridge.Evidence the audit read
Part of the September 2026 audit remediation chantier. Refs #220 (RM-26).