add-to-homescreen-react icon indicating copy to clipboard operation
add-to-homescreen-react copied to clipboard

Window is not defined

Open bigchamp opened this issue 4 years ago • 4 comments

After installation i tried to launch my project locally, but got error window is not defined

bigchamp avatar Sep 08 '20 10:09 bigchamp

Hm, that is unfortunately very little information - too little to be able to investigate the problem. Can you possibly give more information? E.g. How exactly do you integrate add-to-homescreen-react in your project? Can you provide the corresponding code snippet? Which module packer tool do you use? ...

BTW: You can find examples for integration and usage of the component within examples folder of the add-to-homescreen-react project. See https://github.com/as-ideas/add-to-homescreen-react#examples for details how to build and start them locally on your machine. Maybe these examples can help you with the integration of add-to-homescreen-react.

ltparis2018 avatar Sep 29 '20 16:09 ltparis2018

Most likely it's because of SSR, where window is not available.

mkontsek avatar Oct 19 '20 17:10 mkontsek

That's right. Currently, this React component is not designed for SSR. I guess rendering it server-side doesn't make much sense either. For example, it needs information about the current platform (i.e. iOS, Android) it is running on, and also uses the local storage of the browser.

ltparis2018 avatar Oct 20 '20 15:10 ltparis2018

I had this issue as well on a Gatsby.js implementation. Using the loadable-components package ensured that it would only load on the client-side (and not break on SSR compilation).

import loadable from "@loadable/component";
const AddToHomeScreen = loadable(() => import('@ideasio/add-to-homescreen-react')

acarnwath avatar Feb 23 '21 20:02 acarnwath