unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.51k stars 690 forks source link

`DeferLoadStrategy` not working in Uno.UI 5.* #15625

Open queequac opened 3 months ago

queequac commented 3 months ago

Current behavior

I am heavily relying on DeferLoadStrategy="Lazy" in my XAML code to improve startup time (and to exclude platform-specific UI). After upgrading from version 4.10.26 to 5.1.69, I realized that portions of the UI have been visible that should not have been.

So I downgraded to 5.0.156 and other versions, but with the same effect. Only the last 4. version (being 4.10.34) works as expected. All 5. versions load, process and show the XAML that is encapsulated within DeferLoadStrategy="Lazy" immediately.

Expected behavior

The code within a DeferLoadStrategy="Lazy" block should not be loaded and stay invisible until it was found via "FindName".

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

<Grid DeferLoadStrategy="Lazy" x:Name="lazyGrid">
   <TextBlock>Hallo</TextBlock>
</Grid>

Hallo is shown, but should not (yet)

Workaround

No response

Works on UWP/WinUI

None

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

5.1.69 and any other verison of Uno.UI >= 5.0

Affected platforms

Android

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

Tested under Android only.

queequac commented 3 months ago

Seems to affect x:Load="False" in the same way. Works until 4.10.36 and broken within 5.0 and 5.1

jeromelaban commented 3 months ago

Thanks for the report.

Using 5.1.65, the behavior of x:Load="False" is as expected. It may be that you're in a scenario we have have not tested explicitly and regressed, DeferLoadStrategy="Lazy" seems to not be working properly.

We'll be taking a look, but it's best to migrate to x:Load="False".

If you can make a repro with x:Load="False" it would be interesting.

queequac commented 3 months ago

If you can make a repro with x:Load="False" it would be interesting.

I already suspected this looking at my XAML, but seems to have same reason as mentioned in @ramezgerges PR.

<Grid x:Load="False" Visibility="Visible">
   <TextBlock AutomationProperties.AutomationId="HelloTextBlock"
        Text="Hello Uno Platform"
        HorizontalAlignment="Center" />
</Grid>

As soon as I add a visibility to my grid, the grid is shown even if x:Load is set to false.

queequac commented 3 months ago

To sum things up, x:DeferLoadStrategy="Lazy" does not work at all for me, x:Load="False" works only if Visibilityis not set (at all or just with value "Collapsed").

Since x:Load is only supported on 1703 and later, this workaround won't work for one of my Windows UWP packages targeting older windows builds. :(