Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Snackbar and Toast on iOS release builds #1767

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

mjo151
Copy link
Contributor

@mjo151 mjo151 commented Mar 20, 2024

Description of Change

Fixes Snackbar and Toast on iOS release builds

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Removed the use of FrozenSet in the iOS AlertView. FrozenSet was causing the crash on iOS release builds, and it also adds unnecessary overhead when initializing the AlertView.

@mjo151
Copy link
Contributor Author

mjo151 commented Mar 20, 2024 via email

@brminnick
Copy link
Collaborator

brminnick commented Mar 20, 2024

Thanks @mjo151.

However, this doesn't fix the the two root causes:

  1. <MtouchInterpreter>-all</MtouchInterpreter> fails to include the System.Collections.Immutable assembly: [BUG] Toast.Show crashing on iOS Release builds #1752 (comment)
  2. The Mono Interpreter is currently required for Release builds: Consider enabling the interpreter by default for release builds dotnet/maui#13019 (comment)

I think the best path forward for us on the Toolkit team is the following:

  1. Update our documentation to include the following code as a requirement to use Snackbar + Toast as discussed with @bijington: [BUG] Toast.Show crashing on iOS Release builds #1752 (comment)
    <PropertyGroup Condition="$(Configuration.Contains('Release')) And $(TargetFramework.Contains('ios'))">
        <MtouchInterpreter>-all,System.Collections.Immutable</MtouchInterpreter>
    </PropertyGroup>
  2. Monitor the .NET MAUI / .NET iOS teams progress on the Mono Interpreter: Consider enabling the interpreter by default for release builds dotnet/maui#13019 (comment)

@mjo151
Copy link
Contributor Author

mjo151 commented Mar 20, 2024

Thanks @mjo151.

However, this doesn't fix the the two root causes:

  1. <MtouchInterpreter>-all</MtouchInterpreter> fails to include the System.Collections.Immutable namespace: [BUG] Toast.Show crashing on iOS Release builds #1752 (comment)
  2. The Mono Interpreter is currently required for Release builds: Consider enabling the interpreter by default for release builds dotnet/maui#13019 (comment)

I think the best path forward for us on the Toolkit team is the following:

  1. Update our documentation to include the following code as a requirement to use Snackbar + Toast as discussed with @bijington: [BUG] Toast.Show crashing on iOS Release builds #1752 (comment)
    <PropertyGroup Condition="$(Configuration.Contains('Release')) And $(TargetFramework.Contains('ios'))">
        <MtouchInterpreter>-all,System.Collections.Immutable</MtouchInterpreter>
    </PropertyGroup>
  2. Monitor the .NET MAUI / .NET iOS teams progress on the Mono Interpreter: Consider enabling the interpreter by default for release builds dotnet/maui#13019 (comment)

@brminnick

This PR does fix the root cause of the crash on iOS, which is the use of FrozenSet in the AlertView. The AlertView is used by Snackback and Toast. As you can see from the changes in my PR, the use of FrozenSet is completely unnecessary in this case. I don't think it makes sense to force users to enable the interpreter, which has other implications, when this problem can simply be fixed by removing the use of FrozenSet.

@brminnick
Copy link
Collaborator

brminnick commented Mar 20, 2024

I understand that. This is a workaround to a bug in the .NET Runtime and in the Mono Interpreter.

It also includes a breaking change to our public API surface.

@brminnick brminnick added the breaking change This label is used for PRs that include a breaking change label Mar 20, 2024
@mjo151
Copy link
Contributor Author

mjo151 commented Mar 20, 2024

I understand that. This is a workaround to a bug in the .NET Runtime and in the Mono Interpreter.

I agree that not being able to use System.Collections.Immutable appears to be a bug in the .NET Runtime and/or the mono AOT compiler. This PR does "workaround" that bug by not using System.Collections.Immutable. However, use of System.Collections.Immutable here was unnecessary anyway and also had negative performance implications on the code.

For various reasons, I am not able to enable the Mono Interpreter for my project. It's very unfortunate if that will be the stance for fixing issues moving forward, especially when there are other options. I really hope you review and consider this PR for integration into the community toolkit. I've been very happy with the toolkit so far, but if using Snackbar and Toast will require enabling the interpreter (e.g. this PR doesn't get approved), I will have to migrate away from using the toolkit.

@mjo151
Copy link
Contributor Author

mjo151 commented Mar 20, 2024

OK, I understand the issue with breaking the public API. I just pushed another commit that reverts the breaking change to the public API. It still resolves the crash when displaying Snackbar and Toast.

@VladislavAntonyuk VladislavAntonyuk added needs discussion Discuss it on the next Monthly standup and removed breaking change This label is used for PRs that include a breaking change labels Mar 20, 2024
@brminnick brminnick enabled auto-merge (squash) April 4, 2024 19:42
@brminnick brminnick merged commit a6e0b59 into CommunityToolkit:main Apr 4, 2024
7 checks passed
@brminnick brminnick removed the needs discussion Discuss it on the next Monthly standup label Apr 4, 2024
foreach (var view in Children)
foreach (var view in children)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause issues if the collection changes during this loop? Before it was a copy, now it is the actual collection and IEnumerable throws if you change it while it is iterating.

Copy link
Collaborator

@brminnick brminnick Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a possibility, but the likelihood is slim.

As Vlad pointed out in our standup today, Snackbar + Toast typically only contain 2-3 children, so enumerating through the list should be very quick. The odds of the List being modified during enumeration are very low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to this change, the foreach loop accessed the Children property, which calls children.ToFrozenSet(). ToFrozenSet() has to iterate over the collection.

In either case, AlertView is a UI control and should only ever be modified on the UI thread. If another thread is adding children to the view, that's a bug in the consumer of AlertView.

@RobertStefancic
Copy link

Is there a chance we get a hotfix release for this soon? Or maybe a preview release?

@plppp2001
Copy link

Is there a chance we get a hotfix release for this soon? Or maybe a preview release?

I would like this also, and when could it be released? I can't use pre releases in production env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Toast.Show crashing on iOS Release builds
6 participants