SSR compatibility

#4 · closed · 4 comments

View on GitHub ↗

oyeanuj

Hi @Aprillion, thanks for creating this library! It seems that library uses `window` without checking for it which makes it break on the server. This is the build error that I get by importing the library. ``` ReferenceError: window is not defined at r (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:4550) at a (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:4638) at t.exports (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:7673) at Object.<anonymous> (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:3295) at n (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:124) at Module.<anonymous> (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:1082) at n (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:124) at /Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:923 at Object.<anonymous> (/Users/anuj/Code/shuffle-web-next/node_modules/react-auto-height/build/index.js:1:932) at Module._compile (internal/modules/cjs/loader.js:1151:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) at eval (webpack-internal:///react-auto-height:1:18 ``` Thoughts?

Comments

Aprillion

Thanks for reporting, I originally created it only for my own use case and I didn't take server side rendering into account... I should fix in next version (I will make a bug fix version just for this today, and more minor updates hopefully later this month). Can you recommend how to write a test case with mock SSR (without an actual SSR setup)?

Aprillion

uh, I don't use `window` in my source code, it was added by webpack using `style-loader`... if updating the dependencies won't help, I will have to use [isomorphic-style-loader](https://www.npmjs.com/package/isomorphic-style-loader)

Aprillion

@oyeanuj Version 1.0.4 is now published on [npm](https://www.npmjs.com/package/react-auto-height), the compiled code does not contain any `window` anymore (I also added to source code to make review possible: [/build/index.js](https://github.com/Aprillion/react-auto-height/blob/master/build/index.js)) And version 1.0.5, to reduce the package size using .npmignore for the `/docs` folder (a storybook published on github pages).

oyeanuj

@Aprillion Thank you for the quick response and fix!