Fixing React 19 cleanup when external ref returns cleanup function#3381
Fixing React 19 cleanup when external ref returns cleanup function#3381mattgperry merged 2 commits intomainfrom
Conversation
|
Thanks @mattgperry - this is blocking our nextjs upgrade! |
PR Review: React 19 Ref Cleanup SupportOverviewThis PR adds support for React 19's new ref cleanup function pattern while maintaining backward compatibility with React 18. The implementation correctly addresses issue #3360. ✅ Code Quality & Best PracticesStrengths:
Minor suggestions:
✅ Functionality & CorrectnessExcellent implementation:
Dependency array fix: [visualElement, visualState, externalRef] // ✅ CompletePreviously it was only ✅ Performance ConsiderationsPositive:
Note: ✅ Security ConcernsNo security issues identified. The code:
✅ Test CoverageExcellent test suite:
🤔 Minor Observations1. Cleanup handling comment clarity: In the unmount branch, the comment says "call ref with null" but passes 2. Ref change behavior: If 📋 RecommendationsRequired changes: None - the PR is production-ready ✅ Optional improvements:
✅ Final VerdictLGTM - Approve and merge. This is a well-implemented fix that:
The implementation correctly handles the React 19 cleanup pattern while gracefully degrading for React 18. The dependency array fix also resolves a potential stale closure bug. Bundle size impact: Minimal (estimated < 100 bytes) - well within existing budgets. Great work @mattgperry! This is a clean, well-tested solution to ensure forward compatibility with React 19. 🎉 |
Fixes #3360