Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove event listeners for Location on unmount #2489

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

jowlo
Copy link
Contributor

@jowlo jowlo commented Mar 31, 2023

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 via this.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 for href and pathname. 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

  • I have broken down my PR scope into the following TODO tasks
    • Remove event listeners for Location component if unmounted
  • I have run the tests locally and they passed. (refer to testing section in contributing)

@jowlo jowlo marked this pull request as ready for review March 31, 2023 11:27
@T4rk1n
Copy link
Contributor

T4rk1n commented Mar 31, 2023

Looks good, can you add a changelog entry?

@jowlo
Copy link
Contributor Author

jowlo commented Mar 31, 2023

Sure, done!

Currently, if the component is not mounted (e.g. because on a different page),
the component will still receive the change event and the `onLocationChange`
callback changes its props via `this.props.setProps` with the itempath from
('_dashprivate_path') in the DOM. The object, however, is
not on the dom and a random other DOM element is assigned the changed props.

The PR deregisters the event listeners of the component is unmounted. They will
be added again via `componentDidMount` anyways if the component is mounted again.

fixes plotly#1346
@jowlo jowlo force-pushed the fix/remove-location-listeners-on-unmount branch from be88385 to eda1a31 Compare April 11, 2023 07:06
Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@T4rk1n T4rk1n merged commit 151e05e into plotly:dev Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] dcc.Location not honoring refresh=False for dynamic layouts starting with dash v 1.13
2 participants