primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Tabmenu: Error on SSR

Open Jonnyprof opened this issue 4 years ago • 6 comments

Describe the bug

Tabmenu throws an error in Server Side Rendering, when calling updateInkBar method in ngAfterViewInit hook. https://github.com/primefaces/primeng/blob/085a6040181e6a2c4091c56ff7b9be79111dbb71/src/app/components/tabmenu/tabmenu.ts#L110-L114

The error is ReferenceError: getComputedStyle is not defined. IMHO ngAfterViewInit methods (updateInkBar, initAutoScrollForActiveItem, initButtonState) should be executed only in browser side.

Environment

Any environment

Reproducer

No response

Angular version

14.1.3

PrimeNG version

14.0.2

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

16.17.0

Browser(s)

No response

Steps to reproduce the behavior

In a project with SSR, place an tabmenu component and visit the page.

Expected behavior

Tabmenu component should work properly on SSR.

Jonnyprof avatar Aug 25 '22 10:08 Jonnyprof

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!

Best Regards,

mertsincan avatar Nov 09 '22 22:11 mertsincan

This is still happening in v14.2.1, so updateInkBar method still has manipulating DOM and this method is still being called from ngAfterViewInit hook.

@mertsincan please, reopen it.

Jonnyprof avatar Nov 10 '22 09:11 Jonnyprof

same method updateInkBar also fails in TabView on SSR with the same error

MaksymShchukin avatar Nov 16 '22 14:11 MaksymShchukin

Yep many components throw errors when using Angular Universal. I guess my company has to switch to another Framework.

Angular version 15.2.1

PrimeNG version 15.2.0

Tabview:

ERROR ReferenceError: getComputedStyle is not defined at getWidth (./node_modules/primeng/fesm2020/primeng-dom.mjs:342:21) at updateInkBar (./node_modules/primeng/fesm2020/primeng-tabview.mjs:287:53) at ngAfterViewChecked (./node_modules/primeng/fesm2020/primeng-tabview.mjs:163:18)

Mediagallery:

ReferenceError: document is not defined at ngOnDestroy (./node_modules/primeng/fesm2020/primeng-galleria.mjs:124:36) at executeOnDestroys (./node_modules/@angular/core/fesm2020/core.mjs:5982:32) at cleanUpView (./node_modules/@angular/core/fesm2020/core.mjs:5892:9) at destroyViewTree (./node_modules/@angular/core/fesm2020/core.mjs:5718:21) at destroyLView (./node_modules/@angular/core/fesm2020/core.mjs:5870:9) at destroy (./node_modules/@angular/core/fesm2020/core.mjs:11797:9) at view (./node_modules/@angular/core/fesm2020/core.mjs:25337:56)

and many more

D-Biela avatar Mar 10 '23 14:03 D-Biela

still getting this error in v16.0.0-rc.2 Angular v16

SOG-web avatar Jun 12 '23 00:06 SOG-web

this errors still happend in angular 16.2.10 and Primeng 16.5.1

alvarocastillop avatar Nov 17 '23 13:11 alvarocastillop