shlomiassaf / ngrid

A angular grid for the enterprise
https://shlomiassaf.github.io/ngrid
MIT License
241 stars 41 forks source link

TargetEvents breaks on SSR #206

Open adrian-marcelo-gallardo opened 3 years ago

adrian-marcelo-gallardo commented 3 years ago

What is the expected behavior?

I can compile my SSR/Universal app when using TargetEvents and DetailRow built-in plugins.

What is the current behavior?

navigator is used in this file without checking if the app is running in browser or server.

The problematic line is this: const isOsx = /^mac/.test(navigator.platform.toLowerCase())

It is at the root of the file, so as soon as the module is referenced it starts giving errors (so, this is not something that I can fix from my app with conditional logic).

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: stackblitz.com/edit/pebula-ngrid-starter

In mi case, I have a grid which is using a detail-row. As soon as I add PblNgridDetailRowModule to the imports list of the module, the error is thrown (when running on SSR).

Which versions of Angular, CDK, Material, NGrid, OS, TypeScript, browsers are affected?

Angular 12.1.1 CDK 12.1.1 NGrid 4.0.0-alpha.3 Typescript 4.2.4

Is there anything else we should know?

If I modify node_modules and change the problematic line to something like const isOsx = false; then the application runs OK.

adrian-marcelo-gallardo commented 3 years ago

A simple solution could be replacing the problematic line with something like this:

const isOsx = /^mac/.test((typeof navigator !== "undefined" ? navigator.platform : "").toLowerCase());