Skip to content

Commit e360cc5

Browse files
committed
fix: check for connectedness before scheduling rehydration
1 parent 50e4ca1 commit e360cc5

File tree

1 file changed

+8
-1
lines changed
  • packages/@lwc/engine-core/src/framework

1 file changed

+8
-1
lines changed

packages/@lwc/engine-core/src/framework/vm.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)