Verified Solution[facebook/react] Bug: ViewTransition onExit cleanup not called on unmount
Sponsored Content
### ROOT CAUSE
The issue arises because the `onExit` cleanup function is not called immediately during unmount, unlike `onEnter`. This is due to the way `onExit` is handled in the `ViewTransition` component, where the cleanup is tied to the completion of the exit animation rather than the unmount event. This asymmetry in cleanup timing leads to animations not being canceled properly if the component unmounts prematurely.
### CODE FIX
To address this, modify the `ViewTransition` component to ensure the `onExit` cleanup is called immediately upon unmount, similar to `onEnter`. This can be achieved by explicitly triggering the cleanup during the unmount phase:
```js
// Inside ViewTransition component (pseudocode)
const ViewTransition = ({ children }) => {
const [cleanupFunctions, setCleanupFunctions] = useState([]);
// Register cleanup functions
useEffect(() => {
const cleanup = () => {
// Call all cleanup functions immediately
cleanupFunctions.forEach(fn => fn());
};
// Add onExit cleanup
if (onExit) {
const exitCleanup = onExit(instance);
setCleanupFunctions(prev => [...prev, exitCleanup]);
}
return () => {
cleanup(); // Call cleanup on unmount
};
}, [onExit, instance]);
// ... rest of the component
};
```
This change ensures that the `onExit` cleanup is called immediately when the component unmounts, preventing pending animations from running unnecessarily.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[StackOverflow/reactjs] change Emmet abbreviation ".." from 'styleName' to 'className'
[golang/go] cmd/internal/testdir:4_10: Test/escape2.go failures
[tensorflow/tensorflow] Integer overflow in Detection PostProcess max_detections * max_classes_per_detection causes heap buffer overflow