You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a ReactiveController removes itself or adds another controller during a lifecycle method like hostUpdate or hostUpdated, this can prevent other controllers from properly running.
Reproduction
The initial text of the button in this repro should be the following and then clicking the button should not change the text.
Expected:
controller1.count: 1
controller2.count: 1
Actual:
controller1.count: 1
controller2.count: 0
(after clicking once)
controller1.count: 1
controller2.count: 1
Workaround
The issue is that the controllers are stored in an Array and to process the controllers' lifecycle, that array is forEach'd. Mutating the array while it's iterating unexpectedly alters the iteration.
The only workaround is not to alter the controllers list inside a controller lifecycle method.
This could possibly be addressed by (1) copying the controllers array before iterating, or (2) making the controllers a Set.
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
All
Browser/OS/Node environment
Browser: All
The text was updated successfully, but these errors were encountered:
…callbacks (#4388)
Fixes#4266. Controllers are maintained via a Set
instead of an Array, allowing them to be iterated
stably while being modified.
Co-authored-by: Augustine Kim <augustinekim@google.com>
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
If a
ReactiveController
removes itself or adds another controller during a lifecycle method likehostUpdate
orhostUpdated
, this can prevent other controllers from properly running.Reproduction
The initial text of the button in this repro should be the following and then clicking the button should not change the text.
Expected:
Actual:
(after clicking once)
Workaround
The issue is that the controllers are stored in an Array and to process the controllers' lifecycle, that array is
forEach
'd. Mutating the array while it's iterating unexpectedly alters the iteration.The only workaround is not to alter the controllers list inside a controller lifecycle method.
This could possibly be addressed by (1) copying the controllers array before iterating, or (2) making the controllers a
Set
.Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
All
Browser/OS/Node environment
Browser: All
The text was updated successfully, but these errors were encountered: