-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[charts] Fix LineChart
animation being stuck with initial drawing area value
#14553
Merged
JCQuintas
merged 6 commits into
mui:master
from
JCQuintas:improve-unknown-width-behaviour
Sep 16, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
365ab9f
Fix animation stuck with initial drawing area value
JCQuintas c644426
Improve initial render behavior when size is unknown
JCQuintas 681f0dd
Merge commit 'dd98382e7b1657235c12c1334e44a68fa003bd4a' into improve-…
JCQuintas 82f2aff
Merge commit '149cecda61c257795d56fa323d56e10cc1d93e21' into improve-…
JCQuintas e426eec
Add prop to control resolve size
JCQuintas cb7058e
scripts
JCQuintas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe the behavior with for example what is currently happening step by step, and how this PR modify it?
I don't huderstand how adding a
useEnhancedEffect
could help to prevent inifint loop.If you want a nice reproduction of an infinit loop there is one here:
#12263 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This useEffect doesn't prevent an infinite loop. Only
computeRun > 20
does. It serves as a circuit breaker in case the layout never settles into a defined size, which would mean this useEffect would run indefinitely.This useEffect only happens
before/during
the first render, when the page layout is figuring out what size the components need. Hence it is different from the issues in your example, where the loop in on the render side.To fix the loop in your example, we can try to handle it on the
useEnhancedEffect
that has theResizeObserver
inside. Though I'm not sure how useful it would be, since my current fix is only for layouts that will definitely settle into a defined width/height, but your example will never settle 😓Explanation of what it does
The main idea of this
useEnhancedEffect
is that everything in it will happen before we see anything, since it is running on the layout effect and committing changes to the state, the state will update synchronously.The state updates until it settles on a size (new size is the same as last one) or it runs more than 20 times (usually it only requires 5-6 runs from what I tested).
Once one of these two conditions are met, the hook stops looping (width/height stop changing), and the first actual react render happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the solution. But this will silently delay the painting without warning the developers about the improvement they could bring. We should add at least a warning if
computeRun > 2
We can not do
computeRun > 0
because the react strict mode trigger twice the useLayoutEffect. Si theref
is updated twice before the state get updated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had added a warning at first but thought it could be unnecessary and removed it 😅
Will add it back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, I actually removed it because it is an actual valid behaviour that wouldn't require a warning. 🤔
Like, if the user uses this inside a grid, this will always warn, even though a grid's width would eventually settle in the screen's width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree on this point. For me the valid behavior is "The container has a defined size". This PR is adding a nice fallback
I tried with Recharts and they have the same behavior as us currently.
Capture.video.du.2024-09-16.10-02-01.mp4
From my point of view it would be bad to have such loop without informing user since it silently fix something the developers could potentially do better.
In addition to a warning, it could be a warning plus a prop to silence the warning. Or no warning and a prop to activate the feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As "valid behaviour" I mean it is something the browser does on its own. Not that our behaviour is valid 😅
I would agree with a prop for this though.
Something like: