Skip to content

ApplyQueryAttributes gets called with empty Dictionary on back #33415

@lionelmennig

Description

@lionelmennig

Description

Trusting Microsoft's doc:

  • Calling query.Clear() (in case of Dictionary<string, object>)
  • Using a ShellNavigationQueryParameters as a navigation params holder

... should avoid ApplyQueryAttributes(query) to be called when we re-navigate to the existing page (for example with a GoToAsync("..") from a page we'd have opened afterwards).

The issue is: it seems it gets called in both cases with an empty Dictionary.

Steps to Reproduce

  1. Shell.Current.GoToAsync(PageA, new Dictionary<string, object> { { "MyKey", "MyValue" } });
  2. On PageA's ViewModel ApplyQueryAttributes, do query.Clear();
  3. From PageA -> Shell.Current.GoToAsync(PageB);
  4. From PageB -> Either you can press the back button in the title bar or call Shell.Current.GoToAsync("..");
  5. You get back on PageA, and its ViewModel's ApplyQueryAttributes method get called with an empty Dictionary

Link to public reproduction project repository

No response

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

iOS, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Returning from the method at the start of ApplyQueryParameters if query is empty basically fixes the issue, but the documentation from Microsoft is driving people wrong.

Also, and as far as I personally think, ApplyQueryParameters(query) should always get called, no matter there are arguments or not, so we could ensure we can initialize the ViewModel from there. Currently, we have to jungle with ApplyQueryParameters and OnAppearing (which gets called earlier so it misses the parameters) depending there are parameters or not, and it's pretty painful.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions