Skip to content

fix(react): route with redirect will mount page - #28961

Merged
sean-perkins merged 1 commit into
mainfrom
sp/FW-5897
Feb 6, 2024
Merged

fix(react): route with redirect will mount page#28961
sean-perkins merged 1 commit into
mainfrom
sp/FW-5897

Conversation

@sean-perkins

Copy link
Copy Markdown
Contributor

Issue number: resolves #28838


What is the current behavior?

In #28316 we resolved a longstanding misconfiguration where event listeners being added to the page were not removed. This was due to incorrect usage of .bind creating a new instance of the callback functions.

By removing the event listener for ionViewDidLeave, before the component has actually unmounted in react, resulted in the registered destroy callback to not fire:

ionViewDidLeave() {
this.ionViewDidLeaveCallbacks.forEach((cb) => {
const destructor = cb();
if (cb.id) {
this.ionViewDidLeaveDestructorCallbacks.push({ id: cb.id, destructor });
}
});
this.componentCanBeDestroyed();
}
and
this.ionLifeCycleContext.onComponentCanBeDestroyed(() => {
if (!this.props.mount) {
if (this._isMounted) {
this.setState(
{
show: false,
},
() => this.props.removeView()
);
}
}
});

This resulted in a scenario that using a Redirect could cause the wrong view to be unmounted (the entering view) and leave the user on an empty screen.

What is the new behavior?

  • ionViewDidEnter event listener is not removed while the component is unmounting. The browser will naturally remove the event listener when the element node is detached from the DOM.
  • Users are no longer presented with a white screen after clicking a route that uses a redirect.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev-build: 7.6.7-dev.11706567011.11e782a9

@github-actions github-actions Bot added the package: react @ionic/react package label Feb 2, 2024
@sean-perkins
sean-perkins marked this pull request as ready for review February 2, 2024 05:23
@sean-perkins
sean-perkins added this pull request to the merge queue Feb 6, 2024
Merged via the queue into main with commit 5777ce2 Feb 6, 2024
@sean-perkins
sean-perkins deleted the sp/FW-5897 branch February 6, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: react @ionic/react package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: React Router renders white page with Redirect

2 participants