File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
packages/@lwc/engine-core/src/framework Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -673,7 +673,14 @@ function flushRehydrationQueue() {
673673 for ( let i = 0 , len = vms . length ; i < len ; i += 1 ) {
674674 const vm = vms [ i ] ;
675675 try {
676- rehydrate ( vm ) ;
676+ // We want to prevent rehydration from occurring when nodes are detached from the DOM as this can trigger
677+ // unintended side effects, like lifecycle methods being called multiple times.
678+ // For backwards compatibility, we use a flag to control the check.
679+ // 1. When flag is disabled always rehydrate (legacy behavior)
680+ // 2. When flag is enabled only rehydrate when the VM state is connected (fixed behavior)
681+ if ( ! lwcRuntimeFlags . DISABLE_DETACHED_REHYDRATION || vm . state === VMState . connected ) {
682+ rehydrate ( vm ) ;
683+ }
677684 } catch ( error ) {
678685 if ( i + 1 < len ) {
679686 // pieces of the queue are still pending to be rehydrated, those should have priority
You can’t perform that action at this time.
0 commit comments