mderrick/react-html5video

navigator is not defined

Opened this issue · 7 comments

when I go to the page with the video from the main page of the site it works well. but when I go to the page with the video on a direct link then such an error.
ReferenceError: navigator is not defined
at /var/www/dfor.ru/node_modules/react-html5video/dist/index.js:2496:61
at Video.render (/var/www/dfor.ru/node_modules/react-html5video/dist/index.js:259:35)

I get the same thing

Sounds like you're both server side rendering. A video can't be server side rendered. You should check and render a placeholder when rendering on the server.

Is there a solution to this problem? Hope reply

@Brightchild @romanown @mderrick
We encountered the same problem.
Is a typical issue with server side rendering and some libs that make use of things like navigator or window. So I implemented a simple fix and submitted a PR #142 with it.
Hope it'd help you guys as much as it helped us.

thank you. I deleted this line and it works for me. of course Your decision is more correct.

Anyone else finding themselves here: since there PR was never merged a different workaround I found was to use the react-no-ssr package and wrap the <video> tags within a <NoSSR> tag. Ugly but it stopped stuff from breaking.

Hope this helps someone.