CSS Animations edge case: Race Condition in calculateDimensionsWithPadding Affecting ViewBox Calculation #6146
Labels
Status: Triage
Needs to be verified, categorized, etc
Type: Bug / Error
Something isn't working or is incorrect
Description
There is a race condition that causes incorrect results when calculating the
viewBox
in thecalculateDimensionsWithPadding
function. Specifically, when trying to calculate the dimensions of the SVG after rendering, the bounding box values (getBBox()
) are returned incorrectly, resulting in a viewBox with incorrect height (for example,2036
).This happens when the SVG has not yet been fully rendered or its dimensions have not been updated properly by the time the calculation occurs.
Steps to reproduce
calculateDimensionsWithPadding
function.viewBox
attribute of the SVG element after callingsetupViewPortForSVG
.viewBox
might incorrectly show a very large height, such as2036
, which doesn't match the actual size of the rendered SVG.calculateDimensionsWithPadding
, and observe that the correct values are returned when paused, but not when running without the breakpoint.Screenshots
No response
Code Sample
No response
Setup
No response
Suggested Solutions
To resolve the race condition:
requestAnimationFrame
or another method to ensure that the SVG is fully rendered before calculating its bounding box (getBBox()
). This will ensure the dimensions are accurate and prevent issues where the viewBox is incorrectly set.Example fix:
Additional Context
getBBox()
function might not return accurate values if the SVG is not yet fully rendered or updated when the function is called.The text was updated successfully, but these errors were encountered: