Skip to content

Commit d22e707

Browse files
[DSC-1831] prevent rendering of context-menu during ssr
1 parent 63f5072 commit d22e707

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/app/shared/context-menu/context-menu.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="d-flex space-children-mr justify-content-end" *ngIf="contextMenuObject">
1+
<div class="d-flex space-children-mr justify-content-end" *ngIf="browserPlatform && contextMenuObject">
22
<ng-container *ngFor="let entry of (getStandAloneMenuEntries() | async)">
33
<ng-container *ngComponentOutlet="entry; injector: objectInjector;"></ng-container>
44
</ng-container>

src/app/shared/context-menu/context-menu.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ChangeDetectorRef, Component, Inject, Injector, Input, OnInit } from '@angular/core';
2-
import { DOCUMENT } from '@angular/common';
1+
import { ChangeDetectorRef, Component, Inject, Injector, Input, OnInit, PLATFORM_ID } from '@angular/core';
2+
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
33

44
import { from, Observable } from 'rxjs';
55
import { concatMap, filter, map, reduce, take } from 'rxjs/operators';
@@ -48,6 +48,11 @@ export class ContextMenuComponent implements OnInit {
4848
*/
4949
public optionCount = 0;
5050

51+
/**
52+
* Flag to check csr rendering
53+
*/
54+
browserPlatform = false;
55+
5156
/**
5257
* Initialize instance variables
5358
*
@@ -58,10 +63,12 @@ export class ContextMenuComponent implements OnInit {
5863
*/
5964
constructor(
6065
@Inject(DOCUMENT) private _document: Document,
66+
@Inject(PLATFORM_ID) protected platformId: Object,
6167
private cdr: ChangeDetectorRef,
6268
private configurationService: ConfigurationDataService,
6369
private injector: Injector
6470
) {
71+
this.browserPlatform = isPlatformBrowser(this.platformId);
6572
}
6673

6774
ngOnInit(): void {
@@ -91,7 +98,7 @@ export class ContextMenuComponent implements OnInit {
9198
private retrieveSelectedContextMenuEntries(isStandAlone: boolean): Observable<any[]> {
9299
const list = this.contextMenuObjectType ? getContextMenuEntriesForDSOType(this.contextMenuObjectType) : [];
93100
return from(list).pipe(
94-
filter((renderOptions: ContextMenuEntryRenderOptions) => isNotEmpty(renderOptions ?.componentRef) && renderOptions ?.isStandAlone === isStandAlone),
101+
filter((renderOptions: ContextMenuEntryRenderOptions) => isNotEmpty(renderOptions?.componentRef) && renderOptions?.isStandAlone === isStandAlone),
95102
map((renderOptions: ContextMenuEntryRenderOptions) => renderOptions.componentRef),
96103
concatMap((constructor: GenericConstructor<ContextMenuEntryComponent>) => {
97104
const entryComp: ContextMenuEntryComponent = new constructor();

0 commit comments

Comments
 (0)