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

Avoid pinning JSInterop code when unused #36036

Closed
wants to merge 1 commit into from

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Sep 1, 2021

In our current usage, JSStreamReference and it's associated code gets pinned because the converter is registered by default
in the JSRuntime rooting the code. By moving the declaration to the type using a JsonConverterAttribute, we're able to trim this
code if it's not used by the application.

Numbers from trimming WebAssembly/testassets/StandaloneApp:

Size on disk before:
Microsoft.JSInterop.dll.br 14.0 KB (14,371 bytes)
Microsoft.AspNetCore.Components.WebAssembly.dll.br 16.7 KB (17,130 bytes)

Size on disk after:
Microsoft.JSInterop.dll.br 13.9 KB (14,327 bytes)
Microsoft.AspNetCore.Components.WebAssembly.dll.br 15.7 KB (16,151 bytes)

Fixes #35186

@Pilchie Pilchie added the area-blazor Includes: Blazor, Razor Components label Sep 1, 2021
@TanayParikh
Copy link
Contributor

@pranavkm
Copy link
Contributor Author

pranavkm commented Sep 2, 2021

@TanayParikh could I have you try the E2E tests run in Release with this change to verify they pass? I'm having some trouble running the e2e tests locally and I'm not sure if they run on the CI

@TanayParikh
Copy link
Contributor

@TanayParikh could I have you try the E2E tests run in Release with this change to verify they pass? I'm having some trouble running the e2e tests locally

Sure thing.

I'm not sure if they run on the CI

They don't anymore.

@TanayParikh
Copy link
Contributor

dotnet test --configuration Release --filter InteropTest Microsoft.AspNetCore.Components.E2ETests.csproj is failing with:

``` [xUnit.net 00:00:35.41] Microsoft.AspNetCore.Components.E2ETests: 22:09:24.049 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService) Failed Microsoft.AspNetCore.Components.E2ETest.Tests.InteropTest.CanInvokeDotNetMethods [1 ms] Error Message: OpenQA.Selenium.BrowserAssertFailedException : Xunit.Sdk.NotEmptyException: Assert.NotEmpty() Failure at Xunit.Assert.NotEmpty(IEnumerable collection) in C:\Dev\xunit\xunit\src\xunit.assert\Asserts\CollectionAsserts.cs:line 325 at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 70 at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_0`1.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 101 Screen shot captured at 'C:\aspnetcore\src\Components\test\E2ETest\bin\screenshots\803bc58461c94494830f4cf15fe8b89e.png' Encountered browser errors [2021-09-02T05:09:02Z] [Severe] http://127.0.0.1:59204/subdir - Failed to load resource: the server responded with a status of 404 (Not Found)Page content:

---- Assert.NotEmpty() Failure
Stack Trace:
at Microsoft.AspNetCore.E2ETesting.WaitAssert.WaitAssertCore[TResult](IWebDriver driver, Func1 assertion, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 129 at Microsoft.AspNetCore.E2ETesting.WaitAssert.Exists(IWebDriver driver, By finder, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 67 at Microsoft.AspNetCore.E2ETesting.WaitAssert.Exists(IWebDriver driver, By finder) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 54 at Microsoft.AspNetCore.Components.E2ETest.BasicTestAppWebDriverExtensions.WaitUntilTestSelectorReady(IWebDriver browser) in C:\aspnetcore\src\Components\test\E2ETest\Infrastructure\WebDriverExtensions\BasicTestAppWebDriverExtensions.cs:line 27 at Microsoft.AspNetCore.Components.E2ETest.BasicTestAppWebDriverExtensions.MountTestComponent[TComponent](IWebDriver browser) in C:\aspnetcore\src\Components\test\E2ETest\Infrastructure\WebDriverExtensions\BasicTestAppWebDriverExtensions.cs:line 18 at Microsoft.AspNetCore.Components.E2ETest.Tests.InteropTest.InitializeAsyncCore() in C:\aspnetcore\src\Components\test\E2ETest\Tests\InteropTest.cs:line 33 at Microsoft.AspNetCore.E2ETesting.BrowserTestBase.InitializeAsync(String isolationContext) in C:\aspnetcore\src\Shared\E2ETesting\BrowserTestBase.cs:line 70 ----- Inner Stack Trace ----- at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.<Exists>b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 70 at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_01.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 101
[xUnit.net 00:00:35.47] Microsoft.AspNetCore.Components.E2ETests: Starting ChromeDriver 91.0.4472.19 (1bf021f248676a0b2ab3ee0561d83a59e424c23e-refs/branch-heads/4472@{#288}) on port 39970
[xUnit.net 00:00:35.47] Microsoft.AspNetCore.Components.E2ETests: Only local connections are allowed.
[xUnit.net 00:00:35.47] Microsoft.AspNetCore.Components.E2ETests: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[xUnit.net 00:00:35.47] Microsoft.AspNetCore.Components.E2ETests: ChromeDriver was started successfully.
[xUnit.net 00:00:36.67] Microsoft.AspNetCore.Components.E2ETests: [1630559365.309][WARNING]: This version of ChromeDriver has not been tested with Chrome version 92.
[xUnit.net 00:00:36.68] Microsoft.AspNetCore.Components.E2ETests: 22:09:25.324 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
[xUnit.net 00:00:36.68] Microsoft.AspNetCore.Components.E2ETests: 22:09:25.325 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session bc6a4f57d147eace4cd266358d62be74 (org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:00:48.28] Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerInteropTestDefaultExceptionsBehavior.DotNetExceptionDetailsAreNotLoggedByDefault [FAIL]
[xUnit.net 00:00:48.30] Microsoft.AspNetCore.Components.E2ETests: 22:09:36.937 INFO [ActiveSessions$1.onStop] - Removing session bc6a4f57d147eace4cd266358d62be74 (org.openqa.selenium.chrome.ChromeDriverService)
Failed Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerInteropTestDefaultExceptionsBehavior.DotNetExceptionDetailsAreNotLoggedByDefault [10 s]
Error Message:
OpenQA.Selenium.BrowserAssertFailedException : Xunit.Sdk.NotEmptyException: Assert.NotEmpty() Failure
at Xunit.Assert.NotEmpty(IEnumerable collection) in C:\Dev\xunit\xunit\src\xunit.assert\Asserts\CollectionAsserts.cs:line 325
at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 70
at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_0`1.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 101
Screen shot captured at 'C:\aspnetcore\src\Components\test\E2ETest\bin\screenshots\8126e512b0da4e979bba2bd2bc785120.png'
Encountered browser errors
[2021-09-02T05:09:26Z] [Info] http://127.0.0.1:62421/subdir 47:16 "Blazor server-side"
[2021-09-02T05:09:26Z] [Info] http://127.0.0.1:62421/subdir/_framework/blazor.server.js 0:36018 "[2021-09-02T05:09:26.033Z] Information: Normalizing '_blazor' to 'http://127.0.0.1:62421/subdir/_blazor'."
[2021-09-02T05:09:26Z] [Info] http://127.0.0.1:62421/subdir/_framework/blazor.server.js 0:36018 "[2021-09-02T05:09:26.101Z] Information: WebSocket connected to ws://127.0.0.1:62421/subdir/_blazor?id=hhCoNlS7iNHhClAerd25Yw."
[2021-09-02T05:09:26Z] [Info] http://127.0.0.1:62421/subdir/js/jsinteroptests.js 68:10 "Invoking void async methods."
[2021-09-02T05:09:26Z] [Info] http://127.0.0.1:62421/subdir/js/jsinteroptests.js 80:10 "Invoking returning async methods."Page content:

<title>Basic test app</title>
<!-- Used by ExternalContentPackage -->
<link href="_content/TestContentPackage/styles.css" rel="stylesheet">
<link href="Components.TestServer.styles.css" rel="stylesheet">
Select test: Choose... Add/remove child components After-render interop component Async event handlers Auth cases Cascading authentication state bind cases Cascading values Component ref component Concurrent rendering Configuration Content-editable Counter Counter using child component Counter wrapped in parent Culture Picker data-* attribute rendering Dispatching to sync context Duplicate attributes DynamicComponent rendering Element focus component Element ref component Error throwing Error boundary cases Event bubbling EventCallback Event custom arguments Event disabling Event during batch rendering Event preventDefault External content package Focus events Input Focus INotifyPropertyChanged validation Simple validation Simple validation using experimental validator Typical validation Typical validation using experimental validator Input file Input range Inputs without EditForm Navigate to submit Globalization Bind Cases Graceful Termination Head Modification Imports statement ChildContent HTML Block ChildContent HTML Encoded Block ChildContent Mixed Block Binary HttpClient tester HttpClient cookies HttpClient tester Input events Interop component Interop on initialization JavaScript root components JSON serialization Key cases Key press event Laggy typing Limit counter component Localized Text Logical element insertion cases Logging Long running interop Markup blocks Mouse events Moving checkboxes diff case Multiple child content Navigation failure Parent component with child Parent component that changes parameters on child Protected browser storage usage Protected browser storage injection Razor Templates Reconnection server-side blazor Red text Server reliability component Render fragment renderer Render attributes before ConnectedCallback Reordering focus retention NavigationManager Test Router Router with OnNavigate Router with dynamic assembly Router with additional assembly Select with component options SignalR client StringComparison SVG SVG Focus component Plain text Toggle Event Touch events Virtualization Virtualization data changes Render on hot reload
<span id="runtime-info"><code><tt>.NET 7.0.0-alpha.1.21430.29</tt></code></span><span id="source-info"><code><tt>InteropComponent.razor</tt></code></span><!--!--><hr></div><!--!-->

Invoke interop!

Invocations

.NET to JS calls: passing .NET object by ref, receiving .NET object by ref

Return values and exceptions thrown from .NET

Exceptions thrown from JavaScript

ExceptionFromSyncMethod

SyncExceptionFromAsyncMethod

AsyncExceptionFromAsyncMethod

JSObjectReferenceInvokeNonFunctionException

<!-- Used for specific test cases -->
<script src="js/jsinteroptests.js"></script>
<script src="js/renderattributestest.js"></script>
<script src="js/webComponentPerformingJsInterop.js"></script>
<script src="js/customLinkElement.js"></script>
<script src="js/jsRootComponentInitializers.js"></script>

<div id="blazor-error-ui">
    An unhandled error has occurred.
    <a href="" class="reload">Reload</a>
    <a class="dismiss" style="cursor: pointer;">??</a>
</div>

<script>
    // Used by ElementRefComponent
    function setElementValue(element, newValue) {
        element.value = newValue;
        return element.value;
    }

    function navigationManagerNavigate() {
        Blazor.navigateTo('/subdir/some-path');
    }
</script>

<script src="_framework/blazor.server.js"></script>
<script src="js/jsRootComponentInitializers.js"></script>

<!-- Used by ExternalContentPackage -->
<script src="_content/TestContentPackage/prompt.js"></script>
<script>
    console.log('Blazor server-side');
</script>

---- Assert.NotEmpty() Failure
Stack Trace:
at Microsoft.AspNetCore.E2ETesting.WaitAssert.WaitAssertCore[TResult](IWebDriver driver, Func1 assertion, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 129 at Microsoft.AspNetCore.E2ETesting.WaitAssert.Exists(IWebDriver driver, By finder, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 67 at Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerInteropTestDefaultExceptionsBehavior.DotNetExceptionDetailsAreNotLoggedByDefault() in C:\aspnetcore\src\Components\test\E2ETest\ServerExecutionTests\ServerInteropTestDefaultExceptionsBehavior.cs:line 49 ----- Inner Stack Trace ----- at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.<Exists>b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 70 at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_01.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 101
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: 22:09:37.502 INFO [ActiveSessionFactory.apply] - Capabilities are: {
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "browserName": "chrome",
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "goog:chromeOptions": {
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "args": [
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "--headless",
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "--no-sandbox",
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "--ignore-certificate-errors"
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: ],
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "prefs": {
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "intl.accept_languages": "en"
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: },
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "goog:loggingPrefs": {
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "browser": "ALL",
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: "driver": "ALL"
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:00:48.86] Microsoft.AspNetCore.Components.E2ETests: 22:09:37.503 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:00:48.92] Microsoft.AspNetCore.Components.E2ETests: Starting ChromeDriver 91.0.4472.19 (1bf021f248676a0b2ab3ee0561d83a59e424c23e-refs/branch-heads/4472@{#288}) on port 15263
[xUnit.net 00:00:48.92] Microsoft.AspNetCore.Components.E2ETests: Only local connections are allowed.
[xUnit.net 00:00:48.92] Microsoft.AspNetCore.Components.E2ETests: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[xUnit.net 00:00:48.92] Microsoft.AspNetCore.Components.E2ETests: ChromeDriver was started successfully.
[xUnit.net 00:00:50.06] Microsoft.AspNetCore.Components.E2ETests: [1630559378.683][WARNING]: This version of ChromeDriver has not been tested with Chrome version 92.
[xUnit.net 00:00:50.07] Microsoft.AspNetCore.Components.E2ETests: 22:09:38.712 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
[xUnit.net 00:00:50.07] Microsoft.AspNetCore.Components.E2ETests: 22:09:38.712 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 26297b7533067872a0c02782ef51f2ea (org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:01:01.48] Microsoft.AspNetCore.Components.E2ETests: 22:09:50.118 INFO [ActiveSessions$1.onStop] - Removing session 26297b7533067872a0c02782ef51f2ea (org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: 22:09:50.669 INFO [ActiveSessionFactory.apply] - Capabilities are: {
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "browserName": "chrome",
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "goog:chromeOptions": {
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "args": [
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "--headless",
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "--no-sandbox",
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "--ignore-certificate-errors"
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: ],
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "prefs": {
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "intl.accept_languages": "en"
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: },
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "goog:loggingPrefs": {
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "browser": "ALL",
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: "driver": "ALL"
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: }
[xUnit.net 00:01:02.03] Microsoft.AspNetCore.Components.E2ETests: 22:09:50.669 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:01:02.09] Microsoft.AspNetCore.Components.E2ETests: Starting ChromeDriver 91.0.4472.19 (1bf021f248676a0b2ab3ee0561d83a59e424c23e-refs/branch-heads/4472@{#288}) on port 21921
[xUnit.net 00:01:02.09] Microsoft.AspNetCore.Components.E2ETests: Only local connections are allowed.
[xUnit.net 00:01:02.09] Microsoft.AspNetCore.Components.E2ETests: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[xUnit.net 00:01:02.09] Microsoft.AspNetCore.Components.E2ETests: ChromeDriver was started successfully.
[xUnit.net 00:01:03.28] Microsoft.AspNetCore.Components.E2ETests: [1630559391.919][WARNING]: This version of ChromeDriver has not been tested with Chrome version 92.
[xUnit.net 00:01:03.29] Microsoft.AspNetCore.Components.E2ETests: 22:09:51.933 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
[xUnit.net 00:01:03.29] Microsoft.AspNetCore.Components.E2ETests: 22:09:51.933 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session bda04afdd7f7d35442840f65bfe6e004 (org.openqa.selenium.chrome.ChromeDriverService)
[xUnit.net 00:01:13.99] Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerInteropTest.CanInvokeDotNetMethods [FAIL]
[xUnit.net 00:01:14.01] Microsoft.AspNetCore.Components.E2ETests: 22:10:02.641 INFO [ActiveSessions$1.onStop] - Removing session bda04afdd7f7d35442840f65bfe6e004 (org.openqa.selenium.chrome.ChromeDriverService)
Failed Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerInteropTest.CanInvokeDotNetMethods [10 s]
Error Message:
OpenQA.Selenium.BrowserAssertFailedException : Xunit.Sdk.NotEmptyException: Assert.NotEmpty() Failure
at Xunit.Assert.NotEmpty(IEnumerable collection) in C:\Dev\xunit\xunit\src\xunit.assert\Asserts\CollectionAsserts.cs:line 331
at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 72
at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_0`1.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 109
Screen shot captured at 'C:\aspnetcore\src\Components\test\E2ETest\bin\screenshots\4818e387fdbe45e38f87c213aa7b951e.png'
Encountered browser errors
[2021-09-02T05:09:52Z] [Info] http://127.0.0.1:56452/subdir 47:16 "Blazor server-side"
[2021-09-02T05:09:52Z] [Info] http://127.0.0.1:56452/subdir/_framework/blazor.server.js 0:36018 "[2021-09-02T05:09:52.042Z] Information: Normalizing '_blazor' to 'http://127.0.0.1:56452/subdir/_blazor'."
[2021-09-02T05:09:52Z] [Info] http://127.0.0.1:56452/subdir/_framework/blazor.server.js 0:36018 "[2021-09-02T05:09:52.053Z] Information: WebSocket connected to ws://127.0.0.1:56452/subdir/_blazor?id=uhcE9fweSI3r-ojyaePqDQ."
[2021-09-02T05:09:52Z] [Info] http://127.0.0.1:56452/subdir/js/jsinteroptests.js 68:10 "Invoking void async methods."
[2021-09-02T05:09:52Z] [Info] http://127.0.0.1:56452/subdir/js/jsinteroptests.js 80:10 "Invoking returning async methods."Page content:

<title>Basic test app</title>
<!-- Used by ExternalContentPackage -->
<link href="_content/TestContentPackage/styles.css" rel="stylesheet">
<link href="Components.TestServer.styles.css" rel="stylesheet">
Select test: Choose... Add/remove child components After-render interop component Async event handlers Auth cases Cascading authentication state bind cases Cascading values Component ref component Concurrent rendering Configuration Content-editable Counter Counter using child component Counter wrapped in parent Culture Picker data-* attribute rendering Dispatching to sync context Duplicate attributes DynamicComponent rendering Element focus component Element ref component Error throwing Error boundary cases Event bubbling EventCallback Event custom arguments Event disabling Event during batch rendering Event preventDefault External content package Focus events Input Focus INotifyPropertyChanged validation Simple validation Simple validation using experimental validator Typical validation Typical validation using experimental validator Input file Input range Inputs without EditForm Navigate to submit Globalization Bind Cases Graceful Termination Head Modification Imports statement ChildContent HTML Block ChildContent HTML Encoded Block ChildContent Mixed Block Binary HttpClient tester HttpClient cookies HttpClient tester Input events Interop component Interop on initialization JavaScript root components JSON serialization Key cases Key press event Laggy typing Limit counter component Localized Text Logical element insertion cases Logging Long running interop Markup blocks Mouse events Moving checkboxes diff case Multiple child content Navigation failure Parent component with child Parent component that changes parameters on child Protected browser storage usage Protected browser storage injection Razor Templates Reconnection server-side blazor Red text Server reliability component Render fragment renderer Render attributes before ConnectedCallback Reordering focus retention NavigationManager Test Router Router with OnNavigate Router with dynamic assembly Router with additional assembly Select with component options SignalR client StringComparison SVG SVG Focus component Plain text Toggle Event Touch events Virtualization Virtualization data changes Render on hot reload
<span id="runtime-info"><code><tt>.NET 7.0.0-alpha.1.21430.29</tt></code></span><span id="source-info"><code><tt>InteropComponent.razor</tt></code></span><!--!--><hr></div><!--!-->

Invoke interop!

Invocations

.NET to JS calls: passing .NET object by ref, receiving .NET object by ref

Return values and exceptions thrown from .NET

Exceptions thrown from JavaScript

ExceptionFromSyncMethod

SyncExceptionFromAsyncMethod

AsyncExceptionFromAsyncMethod

JSObjectReferenceInvokeNonFunctionException

<!-- Used for specific test cases -->
<script src="js/jsinteroptests.js"></script>
<script src="js/renderattributestest.js"></script>
<script src="js/webComponentPerformingJsInterop.js"></script>
<script src="js/customLinkElement.js"></script>
<script src="js/jsRootComponentInitializers.js"></script>

<div id="blazor-error-ui">
    An unhandled error has occurred.
    <a href="" class="reload">Reload</a>
    <a class="dismiss" style="cursor: pointer;">??</a>
</div>

<script>
    // Used by ElementRefComponent
    function setElementValue(element, newValue) {
        element.value = newValue;
        return element.value;
    }

    function navigationManagerNavigate() {
        Blazor.navigateTo('/subdir/some-path');
    }
</script>

<script src="_framework/blazor.server.js"></script>
<script src="js/jsRootComponentInitializers.js"></script>

<!-- Used by ExternalContentPackage -->
<script src="_content/TestContentPackage/prompt.js"></script>
<script>
    console.log('Blazor server-side');
</script>

---- Assert.NotEmpty() Failure
Stack Trace:
at Microsoft.AspNetCore.E2ETesting.WaitAssert.WaitAssertCore[TResult](IWebDriver driver, Func1 assertion, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 129 at Microsoft.AspNetCore.E2ETesting.WaitAssert.Exists(IWebDriver driver, By finder, TimeSpan timeout) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 67 at Microsoft.AspNetCore.Components.E2ETest.Tests.InteropTest.CanInvokeDotNetMethods() in C:\aspnetcore\src\Components\test\E2ETest\Tests\InteropTest.cs:line 160 ----- Inner Stack Trace ----- at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass15_0.<Exists>b__0() in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 72 at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass18_01.b__0(IWebDriver _) in C:\aspnetcore\src\Shared\E2ETesting\WaitAssert.cs:line 109
[xUnit.net 00:01:14.69] Microsoft.AspNetCore.Components.E2ETests:
[xUnit.net 00:01:14.70] Microsoft.AspNetCore.Components.E2ETests:

Failed! - Failed: 3, Passed: 1, Skipped: 0, Total: 4, Duration: 39 s - Microsoft.AspNetCore.Components.E2ETests.dll (net6.0)

</details>

In our current usage, JSStreamReference and it's associated code gets pinned because the converter is registered by default
in the JSRuntime rooting the code. By moving the declaration to the type using a JsonConverterAttribute, we're able to trim this
code if it's not used by the application.

Numbers from trimming WebAssembly/testassets/StandaloneApp:

Size on disk before:
Microsoft.JSInterop.dll.br 14.0 KB (14,371 bytes)
Microsoft.AspNetCore.Components.WebAssembly.dll.br 16.7 KB (17,130 bytes)

Size on disk after:
Microsoft.JSInterop.dll.br 13.9 KB (14,327 bytes)
Microsoft.AspNetCore.Components.WebAssembly.dll.br 15.7 KB (16,151 bytes)

Fixes #35186
@pranavkm
Copy link
Contributor Author

pranavkm commented Sep 9, 2021

I spent a bit of time updating and unfortunately this doesn't work in the current state. JsonConverterAttribute work on exact types so the attribute on IJSStreamReference would only apply if the type it was working with was of that type and not for any derived type e.g. the PullFromJSDataStream in JSInterop.WebAssembly. We could do some things (e.g. move the pull stream in to M.JSInterop.Implementations and annotate it), but that's not an option for 6.0. Closing this for now, we can reconsider the issue for 7.0.

@javiercn
Copy link
Member

Looks good

@pranavkm pranavkm deleted the prkrishn/size-reduction branch October 8, 2021 20:30
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Perf] SoD Regression in Microsoft.AspNetCore.Components.WebAssembly.dll
4 participants