Data: Avoid lingering listeners from stringified data-bound components #11819
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.
This pull request seeks to explore a resolution to an issue raised by @jsnajdr at #11777 (comment) in that our current approach to subscribing to store updates from
withSelect
is problematic in leaving lingering subscribers to a registry if the component doesn't complete the full mounting lifecycle (e.g.renderToString
only constructs, nevercomponentDidMount
norcomponentWillUnmount
).Status:
In its current form, this pull request only includes a failing test case illuminating the issue.
In experimenting toward a resolution, a few challenges have surfaced:
react-redux
, we do not require a top-level context provider, which introduces challenges in the direction of subscribing to an ancestor instance of the component rather than to the registry directlycomponentDidMount
.componentDidMount
will actually be called, this introduces a very similar issue with lingering subscribersThe two general angles I've tried taking here include some combination of:
subscribe
(whether to the registry or some context-provided ancestor proxy) intocomponentDidMount
mergeProps
being calculated in constructor and thecomponentDidMount
withSelect
manages subscriptions for all descendent instances, to assure proper ordering of callbacks, to manage changes in registry, and to help in limiting the total number of store subscribers (rather than eachwithSelect
subscribing to registry, it just receives new context when registry updates).componentDidMount
(presumably the latter is where the registry subscription is attached), how is this known?cc @jsnajdr @youknowriad @Tug