Skip to content
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 not properly animating when hydrating #14355

Merged
merged 14 commits into from
Aug 29, 2024

Conversation

JCQuintas
Copy link
Member

@JCQuintas JCQuintas commented Aug 26, 2024

Fixes #14291

To the best of my knowledge, this doesn't seem to be an issue on react-spring itself, but an odd interaction with our lib.

Other solutions I've tried

  • Rewriting our useReducedMotion (no effect)
  • use useSpring with a dependency array (no effect)
  • pass animatedWidth as style={{width:animatedWidth}} (no effect)
  • have a prop that updates the component on client (is rendered fully on server, but re-plays animation on hydration)
    const [skipAnimation, setSkipAnimation] = React.useState(true)
    
    React.useEffect(() => setSkipAnimation(false), [])
    
    const { animatedWidth } = useSpring({
      from: { animatedWidth: left },
      to: { animatedWidth: width + left + right },
      reset: false,
      immediate: skipAnimation,
    });

@JCQuintas JCQuintas added bug 🐛 Something doesn't work component: charts This is the name of the generic UI component, not the React module! labels Aug 26, 2024
@JCQuintas JCQuintas self-assigned this Aug 26, 2024
@mui-bot
Copy link

mui-bot commented Aug 26, 2024

Deploy preview: https://deploy-preview-14355--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against dc35204

Copy link

codspeed-hq bot commented Aug 26, 2024

CodSpeed Performance Report

Merging #14355 will not alter performance

Comparing JCQuintas:fix-linechart-client-side-render-issue (dc35204) with master (cf441ec)

Summary

✅ 3 untouched benchmarks

@JCQuintas JCQuintas marked this pull request as draft August 26, 2024 18:26
@JCQuintas JCQuintas force-pushed the fix-linechart-client-side-render-issue branch from c2101de to 6b8a457 Compare August 26, 2024 20:25
@JCQuintas JCQuintas marked this pull request as ready for review August 27, 2024 13:48
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 27, 2024
@JCQuintas
Copy link
Member Author

It seems that the only way to test this is in a different repository, since our nextjs setup prevents the issues from appearing 😓

@alexfauquette do you think this requires a custom test to prevent regression? We could have a ci step that build/serve a ssr app on playwright, then we could try to detect if the animation played 🤔, though it might be too much work 😅

@alexfauquette
Copy link
Member

We could have a ci step that build/serve a ssr app on playwright, then we could try to detect if the animation played 🤔, though it might be too much work 😅

For sure it's to much work since we nearly never touch those animation

pnpm-lock.yaml Outdated
Comment on lines 3059 to 3061
peerDependencies:
'@types/react': ^17.0.0 || ^18.0.0
'@types/react': 18.3.3
react: ^17.0.0 || ^18.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite strange. Could it be a modification from another work that leaked in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result of pnpm dedupe 🤔
happens on master as well

I'm not sure why the ci check pnpm dedupe --check doesn't pick it up, it also doesn't pick up locally. I guess because it is a peer dep? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran dedupe to try to fix the netlify build, just in case 😓

@JCQuintas
Copy link
Member Author

#14366 introduced an issue on hydration that further made the current behaviour worse for hydrated line charts 😓

The current solution is to use useTransition instead of useSpring, reason in unknown...

Long term we should move into animating all lines and areas at once if we want smoother enter/exit animations I think

@JCQuintas
Copy link
Member Author

This PR now has some issues in development mode where the animation reverts when a new bundle is sent to the page 🙃 (save a file in dev mode)

I'll try rendering all lines together using useTransition instead T_T

@JCQuintas
Copy link
Member Author

I spent a lot of time trying to figure out how to use useTransition for all lines, when simply memoing the plotted data seemed to be enough 😢

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that this useMemo change something.

Maybe adding a comments explaining what does it solves such that we do not remove it in a year without noticing the regression it would create

@JCQuintas
Copy link
Member Author

I'm surprised that this useMemo change something.

Maybe adding a comments explaining what does it solves such that we do not remove it in a year without noticing the regression it would create

Me too 🙃

I added it when copying the behaviour of BarPlot in order to add useTransition for all the lines, and I noticed the chart stopped re-rendering on mouse-over. So there might be an issue with the context that handles highligh or mouse movement.

At one point I thought it had fixed #13450 but I just wasn't moving my mouse fast enough 😭

@JCQuintas JCQuintas enabled auto-merge (squash) August 29, 2024 13:49
@JCQuintas JCQuintas merged commit 4d28c05 into mui:master Aug 29, 2024
17 checks passed
@JCQuintas JCQuintas deleted the fix-linechart-client-side-render-issue branch August 29, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: charts This is the name of the generic UI component, not the React module! size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[charts] line charts not rendering on page load, only on mouse over
3 participants