slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
582 stars 128 forks source link

Nested router resets (?) causes "flickering" (not found tab appearing) #621

Open matanshukry opened 1 year ago

matanshukry commented 1 year ago

Describe the bug

tl&dr: I'm seeing a "not found" tab for a quick second, for the 1st time, instead of the expected route.

In the reproducible app that follow, ther are 2 flows:

  1. initialPath is /articles -> go to /article/:id -> click back
  2. initialPath is /books -> go to /articles -> go to /article/:id -> click back

On the 1st everything seems fine. On the 2nd, we can see there's a "not found" page in between, probably for the nested. It only happens in this flow, and only for the 1st time.

Flow #1 / Articles start - which works well:

https://github.com/slovnicki/beamer/assets/5613042/86f75d4e-f0f8-4b07-b4cc-960958f8381d

Flow #2 / books start - where we can see the issue:

https://github.com/slovnicki/beamer/assets/5613042/5a809872-fce6-4fdd-b0c4-ec14b143de31

Beamer version: (e.g. v0.14.1, master, ...) v1.5.5

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/matanshukry/case325 , and clone the repo
  2. Go to my_app.dart, and change initialPath to /books (Flow #2).
  3. Start the app
  4. Click on the "books" tab (the right one)
  5. Click on one of the items
  6. Issue: at this point while transitioning, if you use time dilation for example, you should see a "not found" page for a brief second.
  7. Click back (android back button)
  8. Issue: at this point while transitioning, if you use time dilation for example, you should see a "not found" page for a brief second.

To clarify, if you do the same flow without restarting the app - there is no "not found" page. It seems to only happen for the 1st time.

Expected behavior The routes should be shown without a "not found" in betweem them.

Screenshots Added videos before, should be enough.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

fieryboa commented 1 year ago

I'm facing a similar issue too. It looks like this happens when you nest beamers. When try to navigate to a route which is handled by a BeamLocation in the parent beamer from the inner beamer, the inner beamer's BeamLocations also try to resolve the route, which ends up failing.

example:

  1. RootLocation consists of two paths, /books and /articles
  2. BooksLocation consists of a path, /books/:id

There are two nested beamers, where the outer beamer uses RootLocation and the inner beamer uses BooksLocation. When you are in, say, /books/123 and try to navigate to /articles, both BooksLocation and RootLocation try to resolve /articles. It succeeds in RootLocation but fails in BooksLocation.

In my case, this happens all the time when i try to navigate from an inner beamer, not just once. For now, I managed to side step the issue by returning a BeamPage whose child is a SizedBox.shrink in the inner BeamLocation. There are no errors (or the not found page) and the widget tree as seen via the dev tools seems to be fine too.