Skip to content

Commit 73ce504

Browse files
authored
[Blazor] JS root component registration (#37180)
* Change to trigger callbacks only after the renderer has been attached * Update Blazor JS files
1 parent 4515ffa commit 73ce504

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Components/Web.JS/src/JSInitializers/JSInitializers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import { Blazor } from '../GlobalExports';
5+
import { rendererAttached } from "../Rendering/WebRendererInteropMethods";
56

67
type BeforeBlazorStartedCallback = (...args: unknown[]) => Promise<void>;
78
export type AfterBlazorStartedCallback = (blazor: typeof Blazor) => Promise<void>;
@@ -38,6 +39,7 @@ export class JSInitializer {
3839
}
3940

4041
async invokeAfterStartedCallbacks(blazor: typeof Blazor): Promise<void> {
42+
await rendererAttached;
4143
await Promise.all(this.afterStartedCallbacks.map(callback => callback(blazor)));
4244
}
4345
}

src/Components/Web.JS/src/Rendering/WebRendererInteropMethods.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { enableJSRootComponents, JSComponentParametersByIdentifier, JSComponentI
77

88
const interopMethodsByRenderer = new Map<number, DotNet.DotNetObject>();
99

10+
let resolveRendererAttached : () => void;
11+
12+
export const rendererAttached = new Promise<void>((resolve) => {
13+
resolveRendererAttached = resolve;
14+
});
15+
1016
export function attachWebRendererInterop(
1117
rendererId: number,
1218
interopMethods: DotNet.DotNetObject,
@@ -23,6 +29,8 @@ export function attachWebRendererInterop(
2329
const manager = getInteropMethods(rendererId);
2430
enableJSRootComponents(manager, jsComponentParameters, jsComponentInitializers);
2531
}
32+
33+
resolveRendererAttached();
2634
}
2735

2836
export function dispatchEvent(browserRendererId: number, eventDescriptor: EventDescriptor, eventArgs: any): void {

0 commit comments

Comments
 (0)