Skip to content
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: tabs do not work correctly when using pages outside tab routes #27847

Closed
3 tasks done
darrylnoakes opened this issue Jul 24, 2023 · 14 comments
Closed
3 tasks done

bug: tabs do not work correctly when using pages outside tab routes #27847

darrylnoakes opened this issue Jul 24, 2023 · 14 comments
Labels

Comments

@darrylnoakes
Copy link

darrylnoakes commented Jul 24, 2023

Prerequisites

Ionic Framework Version

v6.x

Current Behavior

I am using Vue and Ionic 6.7.5.
Tabs do not work correctly when using pages outside tab routes.

This is the relevant route config:

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: { name: "Index" },
  },
  {
    path: "/",
    component: MainPages,
    children: [
      {
        path: "",
        redirect: { name: "Index" },
      },
      {
        path: "index",
        name: "Index",
        component: IndexPage,
      },
      {
        path: "playlists",
        name: "Playlists",
        component: PlaylistsPage,
      },
      {
        path: "playlists/:id",
        name: "Playlist",
        component: PlaylistViewerPage,
      },
    ],
  },
  {
    path: "/settings",
    name: "Settings",
    component: SettingsPage,
  },
  {
    path: "/song/:id",
    name: "Song",
    component: SongViewerPage,
  },
];

The structure is:

Tabs
  Song Index
  Playlist Index
    Playlist Viewer
Song viewer
Settings

The playlists page has a list of playlists which can be viewed using the shared-route view. This view has a list of songs that can be pushed to. The song-viewing view is external to the tabs.

Page lifecycle events

The app starts on the index page. Navigating to the playlists page, a playlist, a song, and back (any method) does not trigger the playlist-viewing page's view entering event.
Index -> Playlists -> Playlist [nested] -> Song [external to tabs] -> (back) Playlist
The paths are:

  • /index
  • /playlists
  • /playlists/xxx
  • /song/yyy
  • /playlists/xxx

After leaving the nested view (going back to the root view of the playlist tab), it works fine. Switching to the other tab and back also fixes it.
Leaving the nested view and coming back -- before doing anything else -- prevents the issue.
Starting on the playlists tab does not manifest the issue; however, going to the index tab sets the stage for it.
A complex orchestration of history state.

A button that navigates to the settings page is present on all the pages. This exhibits the same behavior when using it from the nested view.

The behavior does not appear to manifest when navigating to and from the external views directly from the root tab views; only from the nested view in the playlist tab.

Also, view leaving events are never triggered when navigating to a view external to tabs.

Tab navigation state

Navigating to a nested view in a tab, switching tabs, navigating to an "external" view, and going back clears the state of the first tab.

In this case:

  • Go to playlist tab.
  • Go to playlist viewer (in playlist tab).
  • Switch to index tab.
  • Go to song viewer (external-to-tabs view).
  • Go back.
  • Switch to the playlists tab.

The playlist tab shows the playlist index instead of the playlist viewer.

Expected Behavior

I expect to be able to use pages external to the tab routes.

Specifically:

  • I expect page lifecycle events to always fire.
  • I expect tabs to maintain their individual navigation state.

Steps to Reproduce

  1. Create a tabbed Vue application with the route structure like the one described above. Include logging of the page lifecycle events.

  2. Load the app on the index page. Navigate to the playlists page, a playlist, a song, and back (any method).
    Index -> Playlists -> Playlist [nested] -> Song [external to tabs] -> (back) Playlist
    The paths are:

    • /index
    • /playlists
    • /playlists/xxx
    • /song/yyy
    • /playlists/xxx

Code Reproduction URL

darrylnoakes/ionic-27847

Ionic Info

Ionic:

   Ionic CLI       : 6.16.3 (C:\Users\Darryl\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework : @ionic/vue 6.7.5

Utility:

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

System:

   NodeJS : v18.15.0 (C:\Users\Darryl\AppData\Local\Volta\tools\image\node\18.15.0\node.exe)
   npm    : 9.5.0
   OS     : Windows 10

Actually Windows 11.

Additional Information

Is this the correct behavior or a bug? Is it a known or unknown issue?
I do not know if this is an issue in Ionic 7.


Related issues:

Possibly related:


Video of reproducing the lifecycle events issue:

Repro.mp4
@ionitron-bot ionitron-bot bot added the triage label Jul 24, 2023
@darrylnoakes darrylnoakes changed the title bug: page lifecycle events do not work not working when using pages outside tabs router bug: page lifecycle events do not work correctly when using pages outside tabs router Jul 25, 2023
@liamdebeasi liamdebeasi added the ionitron: needs reproduction a code reproduction is needed from the issue author label Jul 25, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Jul 25, 2023

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@ionitron-bot ionitron-bot bot removed the triage label Jul 25, 2023
@darrylnoakes
Copy link
Author

I have added (in the initial report) a link to a reproduction repo: darrylnoakes/ionic-27847. I have left in almost the full route structure, to allow for testing of all the different flows I stated.

@averyjohnston averyjohnston added triage and removed ionitron: needs reproduction a code reproduction is needed from the issue author labels Jul 26, 2023
@darrylnoakes
Copy link
Author

I have added a screen recording.

@darrylnoakes
Copy link
Author

Also:

Navigating to a nested view in a tab, switching tabs, navigating to an "external" view, and going back clears the state of the first tab.

In this case:

  • Go to playlist tab.
  • Go to playlist viewer (in playlist tab).
  • Switch to index tab.
  • Go to song viewer (external-to-tabs view).
  • Go back.
  • Switch to the playlists tab.

The playlist tab shows the playlist index instead of the playlist viewer.

@darrylnoakes darrylnoakes changed the title bug: page lifecycle events do not work correctly when using pages outside tabs router bug: tabs do not work correctly when using pages outside tab routes Jul 26, 2023
@darrylnoakes
Copy link
Author

darrylnoakes commented Jul 26, 2023

Currently, the only options I can see for now are as follows:

Don't use tabs, and figure out an alternative UI.
Not really what I feel like doing.

Present everything else in modals.
Fraught with more difficulties.
At the very least, I would need to implement some sort of modal state control based on the route, so that the hardware back button can be used to close the modal (something I need to do for some other modals...).
On a more semantics note, the semantics of a modal don't align with all the pages. The settings and login pages, maybe, but the song viewer is a full page in its own right, and a modal just doesn't feel "right". The navigation I can deal with, by setting it manually to the same as a normal page navigation (I hope).
Additionally, it would have to be styled to appear as a full page on desktop. Just another thing that has to be done.

@liamdebeasi liamdebeasi self-assigned this Jul 27, 2023
@liamdebeasi
Copy link
Contributor

Can you check your reproduction? I am getting a Can't resolve './src/main.js' error when I try to run it.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Jul 27, 2023
@liamdebeasi liamdebeasi removed their assignment Jul 27, 2023
@ionitron-bot ionitron-bot bot removed the triage label Jul 27, 2023
@darrylnoakes
Copy link
Author

I did a fresh clone and ran yarn and then both yarn dev and yarn build + yarn preview. Everything ran fine and the app was served without issue. What specifically gave that error?

It also worked fine for me when opening the repo in StackBlitz Codeflow.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jul 27, 2023
@liamdebeasi

This comment was marked as outdated.

@liamdebeasi
Copy link
Contributor

I can reproduce this issue after using yarn instead of npm. You can ignore my previous comment about not being able to reproduce the issue. I missed a step which is why I could not reproduce the issue the first time.

This looks to be another instance of #25213, so I am going to merge the two threads.

@liamdebeasi liamdebeasi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2023
@darrylnoakes
Copy link
Author

darrylnoakes commented Jul 28, 2023

Hmm. So, basically, you can't really used child views in tabs with Vue (#25213)? And tabs seem to have other issues (#24594).

Does that issue also account for the behavior with tab-external routes and page lifecycle events? Or is a route structure with routes external to tabs not actually supported? E.g., if I changed the child view to a modal, would the issue with lifecycle events persist?

@liamdebeasi
Copy link
Contributor

This issue is unique to tabs with child routes, so using a modal as a child view within a tab should be fine.

@darrylnoakes
Copy link
Author

For anyone who's interested: I have settled for making the playlist viewer also external to the tabs.
The route structure has been changed from

Tabs
  Song Index
  Playlist Index
    Playlist Viewer
Song viewer
Settings

to

Tabs
  Song Index
  Playlist Index
Playlist Viewer
Song viewer
Settings

This means that it overlays the tabs router view (and you therefore cannot easily switch between viewing the song index and viewing a playlist), but I'll settle for that over having to implement something complicated.

@ionitron-bot
Copy link

ionitron-bot bot commented Aug 27, 2023

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Aug 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants