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

[blazor] Use JSImport for loading satellite assemblies #46477

Merged
merged 7 commits into from
Feb 7, 2023

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Feb 6, 2023

Motivation

  • The current getSatelliteAssemblies is implemented using legacy/obsolete JS interop.
  • legacy interop has problems with multi-threading and uses unsupported API.
  • legacy interop is not CSP compliant

Contributes to #37787

Description

  • use new generated JavaScript interop with [JSImport]
  • drops unit test with mocked IJSUnmarshalledRuntime as that is no longer a dependency.
    • Also logically the JS code is part of the component, not a "dependency"

@pavelsavara pavelsavara added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Feb 6, 2023
@pavelsavara pavelsavara added this to the 8.0 milestone Feb 6, 2023
@pavelsavara pavelsavara self-assigned this Feb 6, 2023
Copy link
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@pavelsavara pavelsavara marked this pull request as ready for review February 6, 2023 13:05
@pavelsavara pavelsavara requested a review from a team as a code owner February 6, 2023 13:05
@@ -27,54 +24,6 @@ public void GetCultures_ReturnsCultureClosure(string cultureName, string[] expec
Assert.Equal(expected, actual);
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

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

I agree that it's fine to remove these tests since they were tied to the old implementation of LoadCurrentCultureResourcesAsync().

Thankfully, it looks like this was one of the only cases where we were mocking IJSUnmarshalledRuntime for test purposes, so I think it should be unlikely that switching to the new JSImport/JSExport interop model will force us to remove a bunch of similar tests in the future.

The one exception to this is WebAssemblyHostBuilder, which relies heavily on IJSUnmarshalledRuntime. Tests currently use TestJSUnmarshalledRuntime to mock JS interop functionality. I would imagine that in this case, we could create an IWebAssemblyHostInterop interface to provide strongly-typed interop, and we could have a "test" interop class along with the "real" one whose implementation invokes the static [JSImport] methods. The same pattern could be applied in other cases, if they arise.

This isn't really a PR suggestion, just some ideas about the future.

…CultureProvider.cs

Co-authored-by: Mackinnon Buck <mackinnon.buck@gmail.com>
…CultureProvider.cs

Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
# Conflicts:
#	src/Components/Web.JS/src/GlobalExports.ts
#	src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
@pavelsavara pavelsavara merged commit cec7fbf into dotnet:main Feb 7, 2023
@ghost ghost modified the milestones: 8.0, 8.0-preview2 Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants