fix: guard portal setState against React 19 Suspense disappearLayoutEffects#7474
fix: guard portal setState against React 19 Suspense disappearLayoutEffects#7474mixelburg wants to merge 1 commit into
Conversation
… disappearLayoutEffects Move setTooltipPortal and setLegendPortal calls inside the existing node != null check so they are not called with null during ref cleanup. React 19's disappearLayoutEffects phase calls ref callbacks with null during Suspense hiding, and unconditional setState in that phase causes infinite re-render loops.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIn ChangesPortal null guard in
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle ReportChanges will decrease total bundle size by 77.67kB (-1.39%) ⬇️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-sankeyAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-treeshaking-sunburstAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-treemapAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7474 +/- ##
==========================================
- Coverage 89.06% 88.25% -0.81%
==========================================
Files 539 607 +68
Lines 41011 14102 -26909
Branches 5553 3544 -2009
==========================================
- Hits 36527 12446 -24081
+ Misses 4476 1469 -3007
- Partials 8 187 +179 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Can we have a unit test for this? |
|
Good call, will add a unit test covering the Suspense disappearLayoutEffects scenario. Stay tuned! |
|
bumping this, would be great |
Fixes #7463
React 19's
disappearLayoutEffectsphase calls ref callbacks withnullwhen a Suspense boundary hides a subtree. TheinnerRefcallback inRechartsWrapperwas callingsetTooltipPortal(null)andsetLegendPortal(null)unconditionally, which triggered setState during ref cleanup and caused an infinite re-render loop.Moved both portal setters inside the existing
node != nullguard so they only fire on mount, not cleanup. This is a minimal 2-line change matching the fix direction suggested in the issue.Summary by CodeRabbit