-
Notifications
You must be signed in to change notification settings - Fork 178
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
Animations: Unnecessary re-renders caused by WAAPIWrapper
#9742
Comments
Ahh great find. I'll look into this |
Alright, so did a little recon on this today to try and figure out some possible solutions. Want to do a little brain dump so we don't lose any context while I'm out on vacation. React's diffing algorithm with our animation patterns, look to be the primary culprit. Basically if the parent is different, react will destroy the old tree and build up a new one (we're essentially opting out of one of the heuristics react relies on with this pattern): The WAAPI implementation used to only hold pure data in provider state and not actually hold components. I believe we originally altered it to hold components just to mirror our AMP implementation. I see no reason why we can't revert the underlying generated WAAPI animations to just be pure data and keep all the markup in our To update the provider state to only hold pure data for WAAPI animations, we'll need to go through our animation parts and effects to essentially only return these attributes for the WAAPIAnimation property:
Most of this should be taken care of by simply updating Lastly we'll need to update Alternative Approaches The term for this scenario is called This thread has two propositions to get around this.
Conclusion |
Tested against https://stories-qa-wordpress-amp.pantheonsite.io/wp-admin, using PR #10024. Added videos to the canvas and moved them, changing their position. No new requests found on Network > Media tab. |
Bug Description
This finding was kindly shared with us by rtCamp engineers:
Issue: Any element wrapped by
StoryAnimation.WAAPIWrapper
/StoryAnimation.Provider
get's re-rendered whenever an element gets moved to another place. This also causes videos or images to be loaded again due to the re-renders, resulting in tons of HTTP requests.Cause: currently, all the animation properties of display elements are being stored in a
Map
, so whenever the (x, y) position of an element changes, thatMap
gets updated and all of those elements depending on animations get re-rendered.Relevant code:
https://github.com/google/web-stories-wp/blob/31776678fb986ad1f11461ca9febf900ec4f7c3d/packages/animation/src/components/provider.js#L81-L118
Expected Behaviour
No unexpected re-renders
Steps to Reproduce
Check renders in React dev tools, see also video below showing the HTTP requests
Screenshots
https://share.vidyard.com/watch/PTXDn2R1L7XqPyX57Y3tg4?
Additional Context
The text was updated successfully, but these errors were encountered: