motion
motion copied to clipboard
Remove random from PresenceChild
Next.js is experimenting with a mode called dynamicIO that interprets IO which introduces non-determinism as un-prerenderable. Generally this is a fine thing to do but there are sync sources of IO like reading random sources and system clocks which are ambiguous. If you use the output of these reads in the realm of introspection and logging there really isn't an imperative need to interpret them as dynamic. But if they affect the rendered output then they clearly communicate their inherent dynamism (i.e I want to see a random order of items every time I load this page).
During a test migration to dynamicIO we discovered that PresenceChild uses Math.random() to achieve an object identity trick guarantee some rendering behavior in the browser. However since all browser code in React (except effects) run in SSR too this trips up the dynamicIO heuristic and Next.js interprets this PresenceChild-using-component as dynamic when it doesn't need to be.
This change updates the implementation of PresenceChild to achieve the desired goal without reading from a random source.
Awesome PR, thanks! I'll try and get it merged and released this week.