Uh oh!
There was an error while loading. Please reload this page.
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/src/features/ui/util/safe-auto-update.ts (1)
50-53: Consider the performance implications of broad MutationObserver scope.Observing the entire document with
{ childList: true, subtree: true }triggers the callback on every DOM mutation. While the callback is lightweight, this could add overhead on pages with frequent DOM updates.An alternative approach would be to observe only the ancestors of the floating element up to the body, which would reduce the callback frequency while still detecting removal.
🔎 Alternative approach using ancestor observation
// Instead of observing the entire document, observe ancestor chainconstobserveAncestors=(element: Element): MutationObserver=>{constobserver=newMutationObserver(()=>{if(!element.isConnected){cleanup?.();observer.disconnect();cleanup=null;}});letcurrent: Node|null=element.parentNode;while(current&¤t!==document){observer.observe(current,{childList: true});current=current.parentNode;}returnobserver;};That said, the current implementation is correct and acceptable if performance isn't a concern for your use case.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/src/features/ui/util/safe-auto-update.ts
🔇 Additional comments (4)
apps/web/src/features/ui/util/safe-auto-update.ts (4)
3-15: LGTM!The JSDoc clearly documents the purpose and the existing null checks correctly return a no-op function early when elements are missing.
17-23: Good defensive check for virtual elements.The
instanceof Nodecheck correctly handles virtual reference elements (non-DOM objects) that don't haveisConnected. This appropriately treats them as "always connected" since they have no DOM parentage.
33-48: LGTM!The MutationObserver callback correctly:
- Uses consistent
instanceof Nodecheck for reference- Safely cleans up and nullifies references to prevent double-cleanup
- Logs errors without throwing to avoid breaking the application
61-69: LGTM!The cleanup function correctly:
- Uses optional chaining to handle cases where cleanup already occurred via the MutationObserver
- Wraps in try-catch to prevent cleanup errors from propagating
- Logs errors for debugging without breaking the application
The order (disconnect before cleanup) is intentional and safe—stopping observation before stopping autoUpdate prevents potential race conditions where the observer callback fires during cleanup.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.