ngneat / helipopper

🚁 A Powerful Tooltip and Popover for Angular Applications

Home Page:https://ngneat.github.io/helipopper/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error for window and document not defined on SSR apps

johnvarv opened this issue · comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Having helipopper on code that's also server-side rendered generates this error:

const hasSupport = 'IntersectionObserver' in window;
                                             ^

ReferenceError: window is not defined

Expected behavior

It should run with no errors

Minimal reproduction of the problem with instructions

Have an app with helipopper that is SSRed.

Environment


Angular version:9.1.12
nguniversal: 9.1.1

Additional Info

I think the lib should have checks for undefined window and document in order for these errors to be surpassed. You don't have to do anyting special for SSR since, the tooltip it self won't be used on the SS rendered page. It's just that, since the code is running from the import itself, it simply unusable on SSR apps.
Providing "dummy" window and document via webpack.ProvidePlugin, as a workaround, does not work either, since it creates implications on other libs also.

You are right. Do you like to open a PR?

Sure, I will.