JedWatson / react-input-autosize

Auto-resizing input field for React
https://jedwatson.github.io/react-input-autosize
MIT License
769 stars 178 forks source link

window is undefined on server side #123

Closed kandebr closed 6 years ago

kandebr commented 6 years ago

https://github.com/JedWatson/react-input-autosize/blob/18842d386f5fbad23c888bf45cb2b9e1f29e0010/src/AutosizeInput.js#L39

Unfortunately it leads to error on server-side..

epozsh commented 6 years ago

Any solution to this?

ivoba commented 6 years ago

sorry guys, sorry @JedWatson i reverted this in https://github.com/JedWatson/react-input-autosize/pull/125

michaelwhelehan commented 6 years ago

Breaking my builds :( any ETA on PR?

moersoy commented 6 years ago

the problem continues #124

JedWatson commented 6 years ago

@moersoy are you reporting that this is still an issue, or just linking #124? this was closed automatically when that PR was merged, and should be fixed with 2.2.1

moersoy commented 6 years ago

I made the 2.2.1 update, the problem continues. Since the window is undefined it will not provide the next condition.

const isIE = (typeof window !== 'undefined' && window.navigator) ? /MSIE |Trident\/|Edge\//.test(window.navigator.userAgent) : false;

I think it should be this way

(typeof window !== 'undefined') && ((typeof window.navigator !== 'undefined') ? /MSIE |Trident\/|Edge\//.test(window.navigator.userAgent) : false )

clearjs commented 6 years ago

@moersoy are you using react-select release candidate, or some other package that has react-input-autosize as a dependency? The code which you quoted above is correct, but your npm/yarn lockfile could specify an older version of react-input-autosize. If that is the situation, you can try removing the lockfile and reinstalling dependencies again, or simply reinstalling react-select.

moersoy commented 6 years ago

@clearjs I am using React-select on Nextjs (with ssr). I use on Azure Services. Every time I deploy it, I delete everything and reinstaling it. So always has the latest version. I am taking this error on azure.My project is not working properly due to this error on Azure

clearjs commented 6 years ago

@moersoy You may want to try checking which version is actually installed. If you'd like to ensure that the code above is correct, just execute typeof window !== 'undefined' && window.navigator ? "browser" : "server" and typeof xxx !== 'undefined' && xxx.navigator ? "browser" : "server" (xxx here emulates the undefined window on server) in any browser console (or node).

clearjs commented 6 years ago

Your lockfile may be included with your source code, still pointing to an older version.

moersoy commented 6 years ago

Yes, both have the same result. react-select has not been updated.

clearjs commented 6 years ago

@moersoy ^2.1.2 matches any minor version updates (including 2.2.1). Only lockfile may prevent installing a newer version.