Skip to content

[MVUX] ListState<Uri>.AddAsync causes Selection/State.Empty.ForEach callback to fire with null before the actual selected value #2942

@DevTKSS

Description

@DevTKSS

Current behavior

When calling .AddAsync(uri,ct), where Uri has the value of https://platform.uno/studio/ at this time, on a ListState<Uri>.Async( ... .Selection(AnyUriState) the AnyUriState.Empty(this).ForEach( Operator callback handler should not get called with null AND THEN with the expected Value of https://platform.uno/studio/
seems a bit like the .Empty(this) might be resetting it? but should not be the case...

Expected behavior

The ForEach Operator Callback handler should only get called with the value that has been added + selected!

How to reproduce it (as minimally and precisely as possible)

Repro: UnoWebViewReproApp1.zip

  • Start the app, it will show you MainPage
  • If not preserved, go into MainModel and set Breakpoints on
    • HistorySelectionChanged Callback Handler 1. Line (logger)
    • CurrentUrlChanged in the AddAsync and TrySelectAsync Lines relativly on the bottom area of the method
  • now in the WebView2, which is showing the Uno Homepage, click on Platform in the Head Navigation (most likly you will need to use the Hamburger Icon before, since we are not able to Have the WebView2 Resized automatically on Window resizing) so you will get Navigated to this page
  • check out the Console, which should be containing this MainModel Log lines:
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          CurrentUrlChanged Adding https://platform.uno/platform/ to NavigationHistory
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          CurrentUrlChanged Selected https://platform.uno/platform/ in NavigationHistory
    warn: UnoWebViewReproApp1.Presentation.MainModel[0]
          HistorySelectionChanged Got parameter: https://platform.uno/platform/, this is type of: Uri
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          HistorySelectionChanged Selected Uri from CurrentUrl: https://platform.uno/platform/
    
    this output would be alright!
  • now click again on the Homepage on Studio to get navigated to this.
  • Inspecting the Console output now will show you the issued Behaviour in the third logged entry:
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          CurrentUrlChanged Adding https://platform.uno/studio/ to NavigationHistory
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          CurrentUrlChanged Selected https://platform.uno/studio/ in NavigationHistory
    warn: UnoWebViewReproApp1.Presentation.MainModel[0]
          HistorySelectionChanged Got parameter: (null), this is type of: (null)
    warn: UnoWebViewReproApp1.Presentation.MainModel[0]
          HistorySelectionChanged Got parameter: https://platform.uno/studio/, this is type of: Uri
    info: UnoWebViewReproApp1.Presentation.MainModel[0]
          HistorySelectionChanged Selected Uri from CurrentUrl: https://platform.uno/studio/
    
  • I added the mentioned Breakpoints and found out that we are getting the null value argument, even if its set to not nullable Uri type and on clicking continue, it gets a second call (we did only call Selection once if you inspect the code:
        public IListState<Uri> WebNavigationHistory => ListState<Uri>.Async(this,
                async ct =>
                {
                    var current = await CurrentUrl;
    
                    return current is not null
                        ? [current]
                        : [];
                })
                .Selection(SelectedNavigationHistoryItem);
        public IState<Uri> SelectedNavigationHistoryItem => State<Uri>.Empty(this)
                                                                      .ForEach(HistorySelectionChanged);

closely inspecting the logger lines producement order:

  • when we are calling AddAsync the value is not null then the valid url.
  • the HistorySelectionChanged gets called with null argument and loggs its initial line
  • Debugger steps to CurrentUrlChanged > TrySelectAsync
  • Debugger steps to HistorySelectionChanged >if statement with null value, so does not enter the statement and leaves the method
  • Now we seem to proceed reacting on TrySelectAsync and getting send to the HistorySelectionChanged with this call (again) and et voila, now we do have the value in the call and getting the appropriate reaction of logging with the url
  • UpdateAsync now gets called (and the debugger switches back and forth again) and our code proceedes as expected WITH the values instead of null.

Environment

For bug reports Check one or more of the following options with "x" (???)

VS 2026 Windows

Nuget Package (s):

Package Version(s):

Uno.Sdk first discovered as issue with MvuxListApp Repro using 6.3.28
still an issue with 6.4.13

Affected platform(s):

  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Desktop
  • Skia (Linux Framebuffer)
  • Build tasks

Visual Studio:

  • 2019 (version: )
  • 2022 (version: )
  • 2026 (version: 18.0.0)
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

mentioned this null value introduction in #2927 in which sample the connected TextBox to the Selected Item does NOT show any value and seems to stay on the null value instead of getting updated with the secondary call 🤔

Repro for this:
MvuxListApp.zip

hoping that anyone could have this fixed in the Reactive Packages of uno...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions