Skip to content

ApplyQueryAttributes gets called for not activated (navigated to) page on back #35183

Description

@LaoR-UA

Description

The issue may be similar to ApplyQueryAttributes gets called with empty Dictionary on back, but the concern is more about the View Model that is being invoked to handle query attributes, rather than the empty state of the query.

The case is following.

  • The application has 3 pages: main, second and third.
  • Each has its own view model (either unique or inherited from a shared base one - does not matter) that implements IQueryAttributable (again - separately in each view model or in base one does not matter).
  • Navigation can be from the main to the second, from the second to the third, and from the third back to the second, then back to the main.
  • Each page on the navigation (back and forth) passes its query parameter.

On navigation like that: main -> second -> third -> second, and when the main page is still alive, its implementation of ApplyQueryAttributes gets called as well after the implementation of ApplyQueryAttributes for the second page view model. So, both view models are being invoked, despite only one being activated (navigated to).

Sample project

Added a sample project to BackNavigationQueryHandling branch.
The issue happens on navigation back from the third page to the second, and two invocations are displayed:

Image

Yes, the main page receives an empty query, and not much harm is done, except that some checks were executed if query params are present.
That is why I believe #33451 may fix it, but the root cause of the described issue may be deeper, and I have created a new issue.

Installed Workload Id Manifest Version Installation Source

android 36.1.43/10.0.100 SDK 10.0.200, VS 18.5.11716.220
ios 26.2.10217/10.0.100 SDK 10.0.200, VS 18.5.11716.220
maccatalyst 26.2.10217/10.0.100 SDK 10.0.200, VS 18.5.11716.220
maui-windows 10.0.20/10.0.100 SDK 10.0.200, VS 18.5.11716.220

Steps to Reproduce

  1. Download code from the provided repository/branch.
  2. Run
  3. Navigate from main -> second -> third -> back to second -> back to main.
  4. Observe the invocations list - everything may be correct:
Image
  1. Try again: main -> second -> third -> back to second -> back to main.
  2. Observe redundant invocation of main view model:
Image

Link to public reproduction project repository

https://github.com/LaoR-UA/MAUI_bugs/tree/BackNavigationQueryHandling

Version with bug

10.0.20

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, Android, I was not able test on other platforms

Affected platform versions

Android 7 and up, net10.0-windows10.0.19041.0, cannot test others

Did you find any workaround?

No. An inactive view model is always invoked after 2nd navigation.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions