fix(react-core): prevent Getter losing on Plugin adding #2002
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.
What happens
Plugin
,Getter
andTemplate
have internal objects (this.plugin
) which ordered withinPluginHost
internal object (this.plugins
) based on corresponding positions.Position originates from component index within its parent children.
For this tree
the list is the following
When tree changes to
PluginB
is created (internal object is created and added to list) andPluginC
is updated (index changes).During
PluginB
creation its internal object is created and has position(1)
. ButPluginC
is not updated by that moment and its internal object position is(1)
too.Such position collision is resolved in such a way that
B(1)
replacesC(1)
. The list isHere is a sample of React behavior.
Click the Change button and note that C2 and C3 are created C4 and C5 have outdated indexes.
What is done
key
property is used to force recreation all items going after newly addedunregisterPlugin
fixed so that it does not accidentally remove last list itemBecause of
key
PluginC
is destroyed (andC(1)
is remove from list) and created (andC(2)
is added to to list) afterPluginB
is created. So the list isSince
registerPlugin
allows the case when other list entry is removed (when there is position collision),unregisterPlugin
should allow the case when no entry is removed (because it could already be removed inregisterPlugin
).