Repository navigation
Key cached layouts on the owner size a node's percentages resolve against - #2042
Merged
Merged
Conversation
…inst A clean node's cached layout and measurements are keyed on its available size and sizing modes. Its percentage padding, margin, width, min-width and max-width resolve against the owner's width (and its percentage height bounds against the owner's height), which the key does not record, so a node of fixed size keeps the layout its percentages produced under its owner's previous size. Each cache entry now records the owner size it was computed against, and a lookup for a node whose style resolves a percentage against the owner's width or height requires that size to match. Fixes react#1626
YevheniiKotyrlo
marked this pull request as ready for review
October 16, 2026 08:28
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D125706276. |
javache
approved these changes
Oct 19, 2026
tomekzaw
added a commit
to tomekzaw/yoga
that referenced
this pull request
Oct 19, 2026
…ment The lookup for unconstrained FitContent measurements skipped the owner size check that react#2042 added to the other cache lookups. A clean node with a fixed width and percentage padding, margin or width keeps the same available width when its owner's width changes, so a taller owner made it reuse a measurement whose percentages were resolved against the previous width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A node keeps its cached layout after its owner resizes, so its percentage padding, margins and min/max sizes stay resolved against the owner's old size (#1626).
calculateLayoutInternalkeyscachedLayoutandcachedMeasurementson the available size and the sizing modes only:A node with a definite size is given the same available size and modes whatever its owner's size, so the entry hits, while
padding-left: 50%ormin-width: 100%resolve againstownerWidth, which the entry does not record:mainwidth: 50; padding-left: 50%, root 100 → 60width: 50; min-width: 100%, root 100 → 200height: 50; min-height: 100%in a row, root 100 → 200Any node with a definite size and a percentage padding, margin or size bound is affected once its owner changes size and the node itself does not change.
Solution
Each cache entry records the owner width and height it was computed against. A lookup for a node whose style resolves a percentage against the owner's width (padding, margin, width, min-width, max-width) or height (height, min-height, max-height) also requires that size to match, so the sizing constraint and the percentage-resolution size are separate parts of the key, as suggested in #1626. A node with no such percentage hits the cache exactly as before.
Fixes #1626.
Tests
YGRelayoutTest:percent_padding_follows_owner_size_on_relayout,percent_min_width_follows_owner_size_on_relayoutandpercent_min_height_follows_owner_size_on_relayoutlay out the rows of the table above.YGMeasureCacheTest:remeasure_when_owner_resizes_with_percent_paddingasserts the measure function runs again and the padding follows;keep_cached_measurement_when_owner_resizes_without_percentagesasserts the measure count does not move when nothing resolves against the owner.On
mainthe four percentage tests fail with the values in the table (and padding 10 instead of 20); the cache-retention test passes before and after.Verification
Each CI job, run locally with the workflow's own commands:
ubuntu:24.04with Clang 18 (libc++) and GCC 13:./unit_testsDebug and Release, 864 passed in each of the four, 0 warnings ·./build_fuzz_testsDebug and Release ·benchmarkandcapturebuilt,benchmarkandbenchmarklegacyrunbenchmarkandcapturebuilt, both benchmarks run ·./gradlew assembleDebug assembleReleaseon Windows ·swift build -c debugand-c release(Xcode 27.0), 0 warningsnode:20image:yarn build,yarn test(573 passed),yarn benchmarkinjavascript/clang-format21.1.2: clean on every changed fileyarn gentest-validateand the website were not run; the change touches no fixture or doc.Median layout time over 7 interleaved
benchmarkrounds againstmain: chat-mac +1.8%, feed-android −0.7%, profile-ios +0.7%, rendering-sample-mac −3.2%.No open or closed PR addresses #1626; searched PRs for
percent padding cache,owner size cache,cachedLayout percent,percentage relayout,min-width percentandcache percentage.Base
mainat 6ac92f4.