Skip to content

bug: Crash removing/adding ion-input start/end slot #30380

Closed

Description

@aeharding

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

If the ion-input start/end slots are dynamically removed (for example, in response to user typing) then there is a crash

Expected Behavior

Does not crash

Steps to Reproduce

  1. Visit https://stackblitz.com/edit/yrmxeg-uodqah?file=src%2Fmain.tsx
  2. Type anything
  3. Crash

Code Reproduction URL

https://stackblitz.com/edit/yrmxeg-uodqah

Ionic Info

Ionic:

Ionic CLI : 7.1.1 (/Users/aeharding/.nvm/versions/node/v20.8.1/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 7.6.3

Capacitor:

Capacitor CLI : 5.6.0
@capacitor/android : 5.6.0
@capacitor/core : 5.6.0
@capacitor/ios : 5.6.0

Utility:

cordova-res : not installed globally
native-run : not installed globally

System:

NodeJS : v20.8.1 (/Users/aeharding/.nvm/versions/node/v20.8.1/bin/node)
npm : 10.1.0
OS : macOS Unknown

Additional Information

The bot closed #28855

Thank you for the issue, and apologies for the delay. I can replicate this, but I need to dig into why exactly it's happening. It's possible this is related to the simulated slots feature that we use for components like ion-input and ion-textarea, since the bug doesn't replicate with non-simulated slots like the ones on ion-button.

Activity

  1. dev-charles15531 commented on May 3, 2025

    @dev-charles15531

    This is not a bug if you understand how ionic components work internally. You slotted the button with slot="end" and the dom was manipulated internally so that button can get placed at the end, hence react can't find that component.

    Try removing the slot="end" to see what i'm talking about.

    To solve this, consider moving the IonButton one level up the DOM tree, so it can be a direct child of the IonItem component.

  2. added
    needs: investigationThis issue is waiting on more investigation from the engineering team.
    and removed on May 7, 2025
  3. thetaPC commented on Oct 26, 2026

    @thetaPC
    Contributor

    Thanks for the report, and sorry for the delay.

    Verified on 9.0.9: typing into the input removes the Autofill button and clearing it brings the button back, with no crash. This was fixed by #30958 in v8.7.18, so upgrading to 8.7.18 or later fixes it with no changes to your component.

    The cause was the simulated slots in ion-input and ion-textarea. Ionic moves anything with slot="start" or slot="end" into an internal wrapper, so when React removed the button with removeChild on the ion-input, the browser threw because the button was no longer a direct child. Ionic's build has a patch that handles this, but before 8.7.18 it never reached the build that @ionic/react uses. #30958 is titled for ion-radio-group, but its fix was a build setting that turned that patch on for every component in that build, ion-input included.

    If you can't upgrade yet, keep the button rendered and hide it with an inline style instead of removing it, which works on 8.7.17:

    <IonButton slot="end" style={email ? { display: 'none' } : undefined}>
      Autofill
    </IonButton>

    The earlier comment suggesting this isn't a bug and moving the IonButton to be a direct child of IonItem avoids the crash, but the button then sits outside the input instead of in its end slot, so it doesn't render the same.

    Closing this as completed since it's fixed in 8.7.18.

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

    needs: investigationThis issue is waiting on more investigation from the engineering team.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions