Remove event listeners for Location on unmount #2489
Merged
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.
Currently, if the
Location
component is not mounted anymore after it had been mounted (e.g. because it is on a different page), the component will have it's event handler for the custom_dashprivate_pushstate
event registered.When changing pages, this triggers the
onLocationChange
callback which changes its props viathis.props.setProps
with the itempath (from_dashprivate_path
) in the DOM. The object, however, is not on the DOM and the path may lead to some other DOM element which is assigned the changed props forhref
andpathname
. This leads to the error described in #1346 and breaks subsequent navigation with Links because of the error in the event handler.The PR deregisters the event listeners if the component is unmounted. They will be added again via
componentDidMount
anyways if the component is mounted again.In #2068 (comment) one of the limitations of using the pages feature is that none of the pages can contain a
Location
component. This limitation is lifted with the PR.Fixes #1346 (all the way at the bottom)
Contributor Checklist