react-infinite icon indicating copy to clipboard operation
react-infinite copied to clipboard

Universal rendering

Open mwildehahn opened this issue 9 years ago • 11 comments

If a component uses: useWindowAsScrollContainer then we have a dependency on the window object, which isn't available during server side rendering:

https://github.com/seatgeek/react-infinite/blob/a45928539cb275e9f7b9614996da917f589dd13b/src/react-infinite.jsx#L119

not sure if there is a way around this, right now i just define window globally and set window.innerHeight to 0.

mwildehahn avatar Dec 10 '15 22:12 mwildehahn

Yes, I think it's regrettable that that has a dependency on window.

I can't think of a solution that wouldn't involve either window or some object with the required properties of window in some way. What API do you think would help you with this?

garetht avatar Jan 21 '16 05:01 garetht

@mhahn forgot to mention you in that.

garetht avatar Jan 21 '16 05:01 garetht

I haven't read the code, but maybe we could fallback to rendering a static list with simple pagination buttons (prev, next) if we are on the server?

forabi avatar Jan 21 '16 19:01 forabi

An alternate fallback rendering method is not within the scope of this project.

garetht avatar Jan 21 '16 19:01 garetht

If there is just an option to pass in an object that simulates whatever is being pulled from window that would work for me. I want to avoid defining a global window object since that could leak into other requests.

On Thu, Jan 21, 2016 at 11:16 AM garetht [email protected] wrote:

An alternate fallback rendering method is not within the scope of this project.

— Reply to this email directly or view it on GitHub https://github.com/seatgeek/react-infinite/issues/117#issuecomment-173678691 .

mwildehahn avatar Jan 21 '16 22:01 mwildehahn

Sounds good, I'll make a note to try and add an option like useWindowAsScrollContainer={someObject}.

garetht avatar Jan 21 '16 22:01 garetht

thanks, that would be awesome!

On Thu, Jan 21, 2016 at 2:31 PM garetht [email protected] wrote:

Sounds good, I'll make a note to try and add an option like useWindowAsScrollContainer={someObject}.

— Reply to this email directly or view it on GitHub https://github.com/seatgeek/react-infinite/issues/117#issuecomment-173736032 .

mwildehahn avatar Jan 21 '16 22:01 mwildehahn

i actually went with something like this: https://github.com/erikras/react-redux-universal-hot-example/issues/769#issuecomment-169153596t. You can't reliably determine the window height from the request to the server, so i delay rendering this component until the client has mounted

mwildehahn avatar Feb 08 '16 22:02 mwildehahn

@garetht would it be possible to move recomputeInternalStateFromProps outside of getInitialState?

https://github.com/seatgeek/react-infinite/blob/master/src/react-infinite.jsx#L105

juhaelee avatar May 07 '16 14:05 juhaelee

Hi! Do you guys still plan to make react-infinite w/ useWindowAsScrollContainer compatible with server side rendering (or any work around)? Thanks

djcoin avatar Feb 21 '17 14:02 djcoin

Hi guys. Are you planning to provide SSR support with react-infinite? Or it would be awesome if anyone could provide a work-around. Thanks.

dsaket avatar Aug 24 '18 12:08 dsaket