Skip to content

Conversation

@MackinnonBuck
Copy link
Member

@MackinnonBuck MackinnonBuck commented May 9, 2022

Description of Change

Updated the Maui.Controls.Sample project to use the correct JSComponentConfigurationExtensions.RegisterForJavaScript() overload that permits adding root components via JavaScript in a linker-friendly manner.

Issues Fixed

Fixes #6965

@MackinnonBuck MackinnonBuck requested a review from a team as a code owner May 9, 2022 20:42
@MackinnonBuck MackinnonBuck requested review from Eilon and javiercn May 9, 2022 20:42
@MackinnonBuck MackinnonBuck added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label May 9, 2022
@MackinnonBuck MackinnonBuck changed the title Fix Blazor MAUI dynamic root components trimming problem. Fix Maui.Controls.Sample Blazor dynamic root components trimming problem. May 9, 2022
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Where does this "myDynamicRootComponentInitializer" value come from? Is it just app-specific and not used?

@mattleibow mattleibow added this to the 6.0.300 milestone May 10, 2022
@MackinnonBuck
Copy link
Member Author

MackinnonBuck commented May 10, 2022

@mattleibow Yes, it's just an identifier specific to the sample project. For this case, all we care about is that the correct overload of RegisterForJavaScript is called so the correct JS interop methods get linked in. That parameter generally represents an identifier of a JS function that gets invoked by Blazor to add the root component, but in this case, that function gets invoked by a button click. So we pass a unique dummy value instead so the root component doesn't get added when the page loads.

That said, I'm not completely sure what the original reasoning was for annotating this method overload for linker-friendliness, but not this one. If the latter were annotated, we wouldn't have to apply the change in this PR.

Offline, we've discussed annotating the TValue of DotNetObjectReference<TValue> with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)], which should also make the first overload work again.

Assuming this is in fact a Blazor issue and not a misuse of RegisterForJavaScript in this sample project, we could close this PR and track the issue in a separate PR.

cc: @SteveSandersonMS @javiercn in case you have any thoughts about this.

@javiercn
Copy link
Member

@eerhardt
Copy link
Member

@javiercn - DynamicDependency attributes should only be used when you can't make it work with restructuring the code, or using DynamicallyAccessedMembers. See the warning at https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#dynamicdependency.

I have a PR to fix the underlying issue in ASP.NET with dotnet/aspnetcore#41610.

@mkArtakMSFT
Copy link
Contributor

@eerhardt so no more concerns with this PR then ? Can we merge this ?

@MackinnonBuck
Copy link
Member Author

Closing because dotnet/aspnetcore#41610 should fix the issue without requiring this change.

@TanayParikh TanayParikh deleted the mbuck/fix-dynamic-root-components-trimming branch May 11, 2022 16:49
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-blazor Blazor Hybrid / Desktop, BlazorWebView

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor MAUI dynamic root components fail on iOS hardware

7 participants