-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix stale node references in projection stack during SPA navigations #3527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Clean up disconnected DOM instances from the layout stack lazily when new nodes are added. This prevents stale nodes from being used as resumeFrom targets during shared element transitions. The fix is minimal: 1. In add(): filter out members with disconnected instances and clear lead/prevLead if they were removed 2. In promote(): only use prevLead if its instance is still connected This addresses the same issue as #3516 but with ~15 lines instead of 190+. https://claude.ai/code/session_019kNt63LG4sBKvk5m87JVUb
Code ReviewSummaryThis PR provides a minimal, elegant fix for stale DOM node references in the projection stack during SPA navigations. The solution is significantly simpler than the alternative approach in #3516 (15 lines vs 190+ lines) while effectively addressing the core issue. ✅ Strengths
|
Tests that resumeFrom is not set to a disconnected instance when: 1. An element is removed without proper unmount (simulating SPA navigation) 2. A new element with the same layoutId is registered https://claude.ai/code/session_019kNt63LG4sBKvk5m87JVUb
Summary
This PR fixes issues with stale DOM node references remaining in the projection stack after single-page application (SPA) navigations. When DOM nodes are disconnected but still referenced in the stack, they can cause incorrect shared element transitions and memory leaks.
Closes: #3516
Key Changes
add(): Filter out members with disconnected DOM instances before adding new nodes to the stackprevLeadandleadpointers if they reference nodes that are no longer in the filtered members listprevLeadfor shared element transitions to prevent operations on disconnected DOM nodesImplementation Details
The fix leverages the DOM's
isConnectedproperty to detect when nodes have been removed from the document tree. This is particularly important in SPA scenarios where:The cleanup happens at the entry point (
add()) to ensure the stack remains consistent, and the transition guard prevents any operations on disconnected nodes during the render phase.https://claude.ai/code/session_019kNt63LG4sBKvk5m87JVUb