Skip to content

fix(react): nav will remove components from the DOM - #25763

Merged
sean-perkins merged 15 commits into
mainfrom
FW-2052
Apr 19, 2023
Merged

sean-perkins merged 15 commits into
mainfrom
FW-2052

Conversation

@sean-perkins

@sean-perkins sean-perkins commented Aug 16, 2022 •

Copy link
Copy Markdown
Contributor

Issue #: resolves #25753


Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

When IonNav performs a pop operation (navigating to root, back, etc.) the views are not removed from the DOM.

What is the new behavior?

  • IonNav removes pages from the DOM when they are popped (navigate back, navigate to root, etc.)
  • Memoized constructing React delegate (was reconstructing on each render)

Does this introduce a breaking change?

  • Yes
  • No

Other information

@github-actions github-actions Bot added the package: react @ionic/react package label Aug 16, 2022
@sean-perkins
sean-perkins marked this pull request as ready for review August 18, 2022 02:04
@sean-perkins
sean-perkins requested a review from a team August 18, 2022 02:04
@liamdebeasi liamdebeasi changed the title fix(react): Nav will remove components from the DOM fix(react): nav will remove components from the DOM Aug 23, 2022
const hostComponent = refMap.get(component);
hostComponent && removeView(hostComponent);

component.remove();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there any considerations we need to make with conditionally rendering pages similar to #25663?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do not believe the same considerations apply for IonNav. With IonModal the React node is relocated in the DOM and this causes potential issues when the surrounding React nodes are added or removed (causing React to incorrect remove the modal reference - which is why we render the template buffer elements). With IonNav the React node is stable and the components are added/removed as children of the IonNav.

@sean-perkins
sean-perkins requested a review from a team as a code owner December 1, 2022 04:45

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sean-perkins

Copy link
Copy Markdown
Contributor Author

@liamdebeasi I additionally verified with conditionally rendering a modal with an ion-nav used inside and conditionally rendering an ion-nav with a modal, both cases work as expected:

  • Nav is unmounted and inner components are removed from the DOM
  • When conditionally rendered, the root component is mounted for ion-nav.

@sean-perkins
sean-perkins added this pull request to the merge queue Apr 19, 2023
Merged via the queue into main with commit beb46bf Apr 19, 2023
@sean-perkins
sean-perkins deleted the FW-2052 branch April 19, 2023 17:26
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: ion-nav does not remove component in DOM or update state correctly

3 participants