-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: React Router renders white page with Redirect #28838
Comments
Hello @lorenzo-bonatti thanks for reporting this issue! I can confirm this behavior regressed in v7.5.1 from this change: #28316 (specifically the change to I will need to do additional discovery to see why the |
Hello @lorenzo-bonatti, I've done some additional investigation and I think we can leave the removal of the event listener when the element node is detached and garbage collected. If you would to test with this dev-build and let me know if you experience any unexpected issues:
You will need to delete the Thanks! |
Hello @sean-perkins I tried your code versions with my my-ionic-app project, and it works properly. Can I use this version for my production project, or is it better wait for the release? Thanks for you support! |
Hello @lorenzo-bonatti, thank for verifying the dev-build! I would recommend staying with your current version (< 7.5.1) in a production environment. Once this fix is officially reviewed and merged by the team, it would be acceptable to use in production. I want to investigate a few more techniques before moving forward with removing the event listener: 1e782a9. |
FWIW, I ran into this bug and I've been testing your patch @sean-perkins, and it's working well so far! |
Issue number: resolves #28838 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> 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: https://github.com/ionic-team/ionic-framework/blob/51c729eafc3b290a5daddf7f0ccffd0a2a9fe2aa/packages/react/src/contexts/IonLifeCycleContext.tsx#L208-L216 and https://github.com/ionic-team/ionic-framework/blob/51c729eafc3b290a5daddf7f0ccffd0a2a9fe2aa/packages/react/src/routing/ViewLifeCycleManager.tsx#L21-L32 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? <!-- Please describe the behavior or changes that are being added by this PR. --> - `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 - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev-build: `7.6.7-dev.11706567011.11e782a9`
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
v7.x
Current Behavior
From the version v7.5.1, there is a bug with the Redirect component.
Let's suppose that we want to manage our routes with authentication and that the routes redirect to the login or home page depending on a context (ex. Redux state)
A possible route definition can be like this:
If I'm on the login page and the state changes, the component Redirect works correctly and it redirects me to the home page.
The problem occurs if I come back to the login page (for example with the logout): the page will be blank.
Expected Behavior
The page renders correctly as in previous versions. (
<= v7.5.0
)Steps to Reproduce
Code Reproduction URL
https://github.com/lorenzo-bonatti/my-ionic-app
Ionic Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: