Skip to content

bug: [React] IonModal is not removed from DOM when parent component unmounts #26185

Closed

Description

@puopg

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

When a component rendering an IonModal is unmounted by React, the ion modal DOM node is not removed.

Expected Behavior

Expected similar/same behavior as Ionic v5, where when a React component unmounts, the corresponding components being rendered by that component are also cleaned up. Even if there is no animation, I believe the DOM should be cleaned up

Steps to Reproduce

  1. Have a component (Call it MyComponent) that renders an IonModal
  2. Conditionally mount that component somewhere.
  3. Toggle the modal to present by changing isOpen to true.
  4. Now, without toggling the modal's isOpen prop, simply toggle the mounting condition so React unmounts MyComponent.
  5. The Modal is not removed from the DOM

Code Reproduction URL

https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-0etb2k?file=/src/pages/Home.tsx
No response

Ionic Info

Ionic React: 6.3.3

Additional Information

Link to codesandox example: https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-0etb2k?file=/src/pages/Home.tsx

Activity

  1. sean-perkins commented on Oct 27, 2022

    @sean-perkins
    Contributor

    @puopg thanks for reporting this issue!

    I believe this may overlap with #25775, but we can track independently in the mean time.

    Now that #25590 has been resolved, I can port over the exploration fix for dismissing any presented overlay when it's react component is unmounted.

  2. added
    package: react
    type: bug
    on Oct 27, 2022
  3. puopg commented on Oct 27, 2022

    @puopg
    ContributorAuthor

    Ah I see, for some reason I thought #25775 was resolved with your fix and just not marked! Thanks for looking into this!

  4. sean-perkins commented on Nov 8, 2022

    @sean-perkins
    Contributor

    Hello @puopg can you test with this dev-build and let me know if you run into any issues?

    npm install @ionic/[email protected] @ionic/[email protected]

    I've additionally forked your reproduction here: https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-forked-dflgj8

  5. BenHen75 commented on Nov 9, 2022

    @BenHen75

    I had the same issue, your fix work perfectly @sean-perkins thx!!

  6. puopg commented on Nov 16, 2022

    @puopg
    ContributorAuthor

    Hey, sorry i haven't been around to get to this. Ill check this out when I can and update!

  7. puopg commented on Nov 18, 2022

    @puopg
    ContributorAuthor

    @sean-perkins Hey so far I think things looking good! Thanks!

  8. filip-dot-cube commented on Dec 12, 2022

    @filip-dot-cube

    Confirming, the issues seems to be fixed in

    // package.json
    
      "@ionic/react": "^6.4.0",
      "@ionic/react-router": "^6.4.0",
  9. filip-dot-cube commented on Dec 13, 2022

    @filip-dot-cube

    Confirming, the issues seems to be fixed in

    // package.json
    
      "@ionic/react": "^6.4.0",
      "@ionic/react-router": "^6.4.0",

    Actually it only works correctly with the

    // package.json
      "@ionic/react": "6.3.5-dev.11667931176.1678d34e",
      "@ionic/react-router": "6.3.5-dev.11667931176.1678d34e",

    The 6.4 doesn't show the warning, but the modal stays open.

  10. puopg commented on Dec 14, 2022

    @puopg
    ContributorAuthor

    @filip-dot-cube The PR is still open, so its not available on an official release to my understanding yet.

    #26245

  11. sean-perkins commented on Mar 3, 2023

    @sean-perkins
    Contributor

    The PR to resolve this issue has been merged 🎉 and will be available in the next patch release of Ionic v6.6.1.

    We appreciate the community's patience with this issue!

  12. ionitron-bot commented on Apr 2, 2023

    @ionitron-bot

    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.

  13. locked and limited conversation to collaborators on Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: reacttype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions