Skip to content

bug: Consecutive Pages with Swipe-able Segments causes the pages after the first to bug out #30413

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

Open
3 tasks done
anjildhamalabriebug opened this issue May 15, 2025 · 2 comments
Labels

Comments

@anjildhamalabriebug
Copy link

anjildhamalabriebug commented May 15, 2025

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

I am on Page One and have a Swipeable Segment setup. I can swipe or tap between the segments and my segment content correctly reflects my selection.
Once I navigate to Page Two which also has Swipeable Segment, I can tab between the values but my segment content does not update to show the correct one.

Expected Behavior

All consecutive pages should be able to support their own implementation of swipe-able segments.

Steps to Reproduce

  1. Create a page with Swipeable Segments and some content to distinguish between the segments
  2. Create another page with similar setup but change the segment names and content values so it appears distinct from first page. (Edit: Keep the contentIds the same for both page's segment button and segment content)
  3. Navigate from the first page to second and observe how the the second page's segment does not work correctly. If you refresh and stay on the page, the segments do work because Page One is no longer in the stack.

Code Reproduction URL

https://stackblitz.com/edit/s2qn88ad?file=src%2Fapp%2FexampleTwo.component.ts,src%2Fapp%2FexampleTwo.component.html,src%2Fapp%2Fapp.routes.ts,src%2Fapp%2Fexample.component.ts,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fexample.component.html

Ionic Info

Ionic:

Ionic CLI : 7.2.0 (/Users/anjildhamala/.nvm/versions/node/v22.11.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 8.5.7
@angular-devkit/build-angular : 19.2.12
@angular-devkit/schematics : 19.2.12
@angular/cli : 19.2.12
@ionic/angular-toolkit : 12.2.0

Capacitor:

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

Utility:

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

System:

NodeJS : v22.11.0 (/Users/anjildhamala/.nvm/versions/node/v22.11.0/bin/node)
npm : 10.9.0
OS : macOS Unknown

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label May 15, 2025
@anjildhamalabriebug
Copy link
Author

anjildhamalabriebug commented May 16, 2025

I found a workaround in the meantime. I switched to different contentIds for the consecutive pages ion-segment-button+ion-segment-content compared to the first page.

@HappyKnuckles
Copy link

HappyKnuckles commented May 26, 2025

Your issue is expected behavior, as navigating in Angular does not automatically remove DOM elements with ids if the components aren’t destroyed. In HTML, ids must always be unique.

If you don’t follow that rule, you’ll run into issues like the one you described. So your 'workaround' isn’t really a workaround - it’s the correct and necessary way to implement your use-case.

As shown in the image, in your StackBlitz example, the segment-contents elements (with ids) from example-one are not destroyed upon navigation. Therefore, the DOM still contains those IDs, which leads to duplication problems.

EDIT: You can also check this with logging in ngOnDestroy that the component is not destroyed (lifecycle hook not called) on navigation.
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants