fix(framework): prevent redundant invalidations #12994
Merged
+27
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
onInvalidatehook was triggered for slots without real changes due to a race condition in_updateSlots.This happened on Light DOM changes. The previous logic cached the current state, cleared the current state, processed the DOM, awaited upgrades, and then saved the new state. During this process, the state was temporarily empty, causing comparisons with the cached state to incorrectly detect changes.
Slot state does not depend on child upgrades, so the flow was updated to save the new state before awaiting upgrades. The comparison only needs to confirm that element references remain the same.
With this PR, state updates are extracted and made synchronous. This keeps the state in sync with the Light DOM even if another slot update is triggered, and ensures comparisons return correct results.
As a result,
onInvalidateis fired only when an actual slot change occurs and with accurate state data.Fixes: #10377