Skip to content

Enabling JS root components breaks circuit reinitialization #64523

@ilonatommy

Description

@ilonatommy

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

#64159 surfaced an issue: enabling RegisterForJavaScript causes several circuit lifecycle scenarios to fail. When a circuit shuts down and a new one is created, the JS runtime calls enableJSRootComponents again, but JSRootComponents.ts still holds the previous manager instance and throws Dynamic root components have already been enabled:

throw new Error('Dynamic root components have already been enabled.');

This prevents a new circuit from rehydrating dynamic roots and breaks the reconnection flow that previously passed. For more details, see the discussion on the PR mentioned.

Expected Behavior

Circuit_CanShutDownAndReInitializeMultipleTimes, DotNetObjectReference_CannotBeUsed_AfterCircuitShutsDown_AndANewCircuitIsInitialized, StateIsProvidedEveryTimeACircuitGetsCreated
pass regardless of RegisterForJavaScript presence.

Steps To Reproduce

Add RegisterForJavaScript in src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs unconditionally:

builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents(options =>
    {
        options.RootComponents.RegisterForJavaScript<TestContentPackage.PersistentComponents.ComponentWithPersistentState>("dynamic-js-root-counter"
    });

run E2E tests:

.\.dotnet\dotnet test src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj --filter "FullyQualifiedName~Circuit_CanShutDownAndReInitializeMultipleTimes|FullyQualifiedName~DotNetObjectReference_CannotBeUsed_AfterCircuitShutsDown_AndANewCircuitIsInitialized|FullyQualifiedName~StateIsProvidedEveryTimeACircuitGetsCreated"

The 2nd iteration never gets interactive.

Exceptions (if any)

   at Microsoft.AspNetCore.E2ETesting.WaitAssert.WaitAssertCore[TResult](IWebDriver driver, Func`1 assertion, TimeSpan timeout) in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 137
   at Microsoft.AspNetCore.E2ETesting.WaitAssert.Equal[T](IWebDriver driver, T expected, Func`1 actual) in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 27
   at Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.InteractivityTest.Circuit_CanShutDownAndReInitializeMultipleTimes() in /home/vsts/work/1/s/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs:line 951
   at InvokeStub_InteractivityTest.Circuit_CanShutDownAndReInitializeMultipleTimes(Object, Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
----- Inner Stack Trace -----
   at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass20_0.<WaitAssertCore>b__0() in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 91
   at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass21_0`1.<WaitAssertCore>b__0(IWebDriver _) in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 109

.NET Version

main branch

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions