Skip to content

Commit 28a0a53

Browse files
authored
Remove Entrypoint Invoker (#31769)
* Remove Entrypoint Invoker * Ignore Samples .vscode config * PR Feedback * Update src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts * Await callEntryPoint * Check culture equality and display error * Remove unnecessary comment
1 parent 9ac1a7a commit 28a0a53

File tree

11 files changed

+28
-271
lines changed

11 files changed

+28
-271
lines changed

src/Components/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/Samples/**/.vscode/*

src/Components/Web.JS/src/Boot.WebAssembly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
119119
}
120120

121121
// Start up the application
122-
platform.callEntryPoint(resourceLoader.bootConfig.entryAssembly);
122+
await platform.callEntryPoint(resourceLoader.bootConfig.entryAssembly);
123123
}
124124

125125
function invokeJSFromDotNet(callInfo: Pointer, arg0: any, arg1: any, arg2: any): any {

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,15 @@ export const monoPlatform: Platform = {
5454
});
5555
},
5656

57-
callEntryPoint: function callEntryPoint(assemblyName: string) {
58-
// Instead of using Module.mono_call_assembly_entry_point, we have our own logic for invoking
59-
// the entrypoint which adds support for async main.
60-
// Currently we disregard the return value from the entrypoint, whether it's sync or async.
61-
// In the future, we might want Blazor.start to return a Promise<Promise<value>>, where the
62-
// outer promise reflects the startup process, and the inner one reflects the possibly-async
63-
// .NET entrypoint method.
64-
const invokeEntrypoint = bindStaticMethod('Microsoft.AspNetCore.Components.WebAssembly', 'Microsoft.AspNetCore.Components.WebAssembly.Hosting.EntrypointInvoker', 'InvokeEntrypoint');
65-
// Note we're passing in null because passing arrays is problematic until https://github.com/mono/mono/issues/18245 is resolved.
66-
invokeEntrypoint(assemblyName, null);
57+
callEntryPoint: async function callEntryPoint(assemblyName: string) : Promise<any> {
58+
const emptyArray = [ [ ] ];
59+
60+
try {
61+
await BINDING.call_assembly_entry_point(assemblyName, emptyArray, "m")
62+
} catch (error) {
63+
console.error(error);
64+
showErrorNotification();
65+
}
6766
},
6867

6968
toUint8Array: function toUint8Array(array: System_Array<any>): Uint8Array {

src/Components/Web.JS/src/Platform/Mono/MonoTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ declare interface BINDING {
2121
mono_array_to_js_array<TInput, TOutput>(array: System_Array<TInput>) : Array<TOutput>;
2222
conv_string(dotnetString: System_String | null): string | null;
2323
bind_static_method(fqn: string, signature?: string): Function;
24+
call_assembly_entry_point(assemblyName: string, args: any[], signature: any): Promise<any>;
2425
unbox_mono_obj(object: System_Object): any;
2526
}
2627

src/Components/Web.JS/src/Platform/Platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { WebAssemblyResourceLoader } from './WebAssemblyResourceLoader';
33
export interface Platform {
44
start(resourceLoader: WebAssemblyResourceLoader): Promise<void>;
55

6-
callEntryPoint(assemblyName: string): void;
6+
callEntryPoint(assemblyName: string): Promise<any>;
77

88
toUint8Array(array: System_Array<any>): Uint8Array;
99

src/Components/WebAssembly/WebAssembly/src/Hosting/EntrypointInvoker.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ public void ThrowIfCultureChangeIsUnsupported()
5050
// incomplete icu data for their culture. We would like to flag this as an error and notify the author to
5151
// use the combined icu data file instead.
5252
//
53-
// The Initialize method is invoked as one of the first steps bootstrapping the app prior to any user code running.
53+
// The Initialize method is invoked as one of the first steps bootstrapping the app within WebAssemblyHostBuilder.CreateDefault.
5454
// It allows us to capture the initial .NET culture that is configured based on the browser language.
5555
// The current method is invoked as part of WebAssemblyHost.RunAsync i.e. after user code in Program.MainAsync has run
5656
// thus allows us to detect if the culture was changed by user code.
5757
if (Environment.GetEnvironmentVariable("__BLAZOR_SHARDED_ICU") == "1" &&
58-
((CultureInfo.CurrentCulture != InitialCulture) || (CultureInfo.CurrentUICulture != InitialUICulture)))
58+
((!CultureInfo.CurrentCulture.Name.Equals(InitialCulture.Name, StringComparison.Ordinal) ||
59+
!CultureInfo.CurrentUICulture.Name.Equals(InitialUICulture.Name, StringComparison.Ordinal))))
5960
{
6061
throw new InvalidOperationException("Blazor detected a change in the application's culture that is not supported with the current project configuration. " +
6162
"To change culture dynamically during startup, set <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData> in the application's project file.");

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ internal WebAssemblyHost(
4747
string? persistedState)
4848
{
4949
// To ensure JS-invoked methods don't get linked out, have a reference to their enclosing types
50-
GC.KeepAlive(typeof(EntrypointInvoker));
5150
GC.KeepAlive(typeof(JSInteropMethods));
5251

5352
_services = services;
@@ -67,8 +66,6 @@ internal WebAssemblyHost(
6766
/// </summary>
6867
public IServiceProvider Services => _scope.ServiceProvider;
6968

70-
internal WebAssemblyCultureProvider CultureProvider { get; set; } = WebAssemblyCultureProvider.Instance!;
71-
7269
/// <summary>
7370
/// Disposes the host asynchronously.
7471
/// </summary>
@@ -123,7 +120,7 @@ public Task RunAsync()
123120
}
124121

125122
// Internal for testing.
126-
internal async Task RunAsyncCore(CancellationToken cancellationToken)
123+
internal async Task RunAsyncCore(CancellationToken cancellationToken, WebAssemblyCultureProvider? cultureProvider = null)
127124
{
128125
if (_started)
129126
{
@@ -132,13 +129,13 @@ internal async Task RunAsyncCore(CancellationToken cancellationToken)
132129

133130
_started = true;
134131

135-
CultureProvider.ThrowIfCultureChangeIsUnsupported();
132+
cultureProvider ??= WebAssemblyCultureProvider.Instance!;
133+
cultureProvider.ThrowIfCultureChangeIsUnsupported();
136134

137-
// EntryPointInvoker loads satellite assemblies for the application default culture.
138135
// Application developers might have configured the culture based on some ambient state
139136
// such as local storage, url etc as part of their Program.Main(Async).
140137
// This is the earliest opportunity to fetch satellite assemblies for this selection.
141-
await CultureProvider.LoadCurrentCultureResourcesAsync();
138+
await cultureProvider.LoadCurrentCultureResourcesAsync();
142139

143140
var manager = Services.GetRequiredService<ComponentApplicationLifetime>();
144141
var store = !string.IsNullOrEmpty(_persistedState) ?

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public sealed class WebAssemblyHostBuilder
3636
/// </summary>
3737
/// <param name="args">The argument passed to the application's main method.</param>
3838
/// <returns>A <see cref="WebAssemblyHostBuilder"/>.</returns>
39-
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(EntrypointInvoker))]
4039
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(JSInteropMethods))]
4140
[DynamicDependency(JsonSerialized, typeof(WebEventDescriptor))]
4241
public static WebAssemblyHostBuilder CreateDefault(string[]? args = default)
@@ -46,6 +45,8 @@ public static WebAssemblyHostBuilder CreateDefault(string[]? args = default)
4645
args ??= Array.Empty<string>();
4746
var builder = new WebAssemblyHostBuilder(DefaultWebAssemblyJSRuntime.Instance);
4847

48+
WebAssemblyCultureProvider.Initialize();
49+
4950
// Right now we don't have conventions or behaviors that are specific to this method
5051
// however, making this the default for the template allows us to add things like that
5152
// in the future, while giving `new WebAssemblyHostBuilder` as an opt-out of opinionated

src/Components/WebAssembly/WebAssembly/test/Hosting/EntrypointInvokerTest.cs

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)