@@ -7,6 +7,7 @@ const selectValuePropname = '_blazorSelectValue';
7
7
const sharedTemplateElemForParsing = document . createElement ( 'template' ) ;
8
8
const sharedSvgElemForParsing = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' ) ;
9
9
const preventDefaultEvents : { [ eventType : string ] : boolean } = { submit : true } ;
10
+ const rootComponentsPendingFirstRender : { [ componentId : number ] : Element } = { } ;
10
11
11
12
export class BrowserRenderer {
12
13
private eventDelegator : EventDelegator ;
@@ -19,7 +20,9 @@ export class BrowserRenderer {
19
20
}
20
21
21
22
public attachRootComponentToElement ( componentId : number , element : Element ) {
22
- this . attachComponentToElement ( componentId , toLogicalElement ( element ) ) ;
23
+ // 'allowExistingContents' to keep any prerendered content until we do the first client-side render
24
+ this . attachComponentToElement ( componentId , toLogicalElement ( element , /* allowExistingContents */ true ) ) ;
25
+ rootComponentsPendingFirstRender [ componentId ] = element ;
23
26
}
24
27
25
28
public updateComponent ( batch : RenderBatch , componentId : number , edits : ArraySegment < RenderTreeEdit > , referenceFrames : ArrayValues < RenderTreeFrame > ) {
@@ -28,6 +31,13 @@ export class BrowserRenderer {
28
31
throw new Error ( `No element is currently associated with component ${ componentId } ` ) ;
29
32
}
30
33
34
+ // On the first render for each root component, clear any existing content (e.g., prerendered)
35
+ const rootElementToClear = rootComponentsPendingFirstRender [ componentId ] ;
36
+ if ( rootElementToClear ) {
37
+ delete rootComponentsPendingFirstRender [ componentId ] ;
38
+ clearElement ( rootElementToClear ) ;
39
+ }
40
+
31
41
this . applyEdits ( batch , element , 0 , edits , referenceFrames ) ;
32
42
}
33
43
@@ -368,3 +378,10 @@ function raiseEvent(event: Event, browserRendererId: number, eventHandlerId: num
368
378
eventDescriptor ,
369
379
JSON . stringify ( eventArgs . data ) ) ;
370
380
}
381
+
382
+ function clearElement ( element : Element ) {
383
+ let childNode : Node | null ;
384
+ while ( childNode = element . firstChild ) {
385
+ element . removeChild ( childNode ) ;
386
+ }
387
+ }
0 commit comments