New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add slick-initialized
on client-side only
#560
Conversation
There is a problem about the style, when From Here |
@kimown : This works fine for us, even in infinite mode. Server render will not render the Could you give an example where it doesn't work for you? |
@mkreidenweis sorry too late to reply you, in my project, |
@kimown |
No updates? :( |
I have manually included these changes in my fork of react-slick, followed by running the build script and trying to link them in my app. Behavior is the same when the page loads: content for each carousel is stacked vertically before the paging mechanism kicks in and re-renders without the hidden pages, as you can see on brandonarnold.com. |
Hey, I am new to react-slick and am seeing this issue in my isomorphic app. The pictures stack up one below the other, before the carousel kicks in. |
@brandon-arnold @Jaikant guys, you'd have to manually include the mentioned CSS styles into your app's stylesheet. |
@eliseumds I don't know what I'm missing; the |
I couldn't wait on this to be accepted so I forked the project, included these changes (which BTW work great) and published on npm as react-slick-ssr (to avoid having to commit the lib folder into the repo). |
@simoneb thanks will try this out. |
@akiran : It would be great to get some feedback on this PR from you. Do you have any concerns that prevent you from merging this? |
@mkreidenweis even though I'm using this approach there's still the issue that if you try to display the initial slide immediately with .slick-slide.slick-active {
display: block;
} then you'll get a duplicate copy as mentioned before by @kimown. Not sure if this happens only under certain circumstances though. |
@simoneb You're right. I was able to reproduce your issue now. There's actually another CSS style in our code that makes it work properly: .slick-track {
width: 9000px;
} I didn't realize till now that this is essential for this server side rendering to work properly with the standard |
@mkreidenweis @eliseumds the changes don't work for me. I am injecting the css on the server as well as included these changes |
@mkreidenweis as @Jaikant mentioned this fix doesn't work for me either, still get the same duplicate slide |
Ok so, what seems to work is this (ugly) fix: .slick-slide.slick-active[data-index="0"] {
display: block;
width: 100%;
} This gets rid of the duplicate slide by only selecting the first one and sets a correct width for it. This seems to work fine when applied on top of this PR and with this configuration: {
centerMode: true,
centerPadding: '170px'
} |
@simoneb I happened to use the slider for content with fixed width only, so I guess that's the reason I didn't notice so far. Makes sense now. |
@mkreidenweis I also am using a flex-based width and am seeing the same results. You can observe behavior at brandonarnold.com. |
@mkreidenweis sorry for the delay in responding as I was not at work for the whole of last week. I worked around this by not rendering the component on the server as described here. I uploaded the behaviour I am seeing here. |
@akiran any updates? It would be great if you could accept this PR. |
I’m migrating my app to nextjs, does the SSR works now? Or should I use the fork https://www.npmjs.com/package/react-slick-ssr or something else? Any feedback? |
Set `slideCount` and `currentSlide` during server-side rendering in order to get the dots/pagers rendered.
So that CSS can distinguish between server-rendered state and client-javascript-initialized state.
5e6703c
to
c855ae3
Compare
typeof window === 'undefined' is not the guarantee that it is server rendering. Often people add fake window in ssr. |
So is there a better way to detect SSR than checking for presence of |
Smth like typeof window !== 'undefined' && window.document && window.document.createElement |
after adding the code ,the initial slider is coming fine with images ,css and dots ,but the slider functionality is not working and i cant able to move the slider in server side rendering. |
@rajatjasuja23 I'm not sure what you're trying to do. For the slider to become interactive it still needs React on the client side, even if the initial slide view is rendered on the server. So if you only render on the server, it won't give you an actual working slider. |
@mkreidenweis yes,my slider is working fine in client side but its taking 3-4 secs to load the actual working slider.My performance went down ,when i am doing ssr with react slick,i just want to improve the performance on server side,so is there any way to load the actual working slider in ssr ??,because there is a hyperlink on each slick slider item and in slow networks i cant able to redirect it to the next page in ssr it is only working when the actual working slider loads in client side |
@laveesingh Was this fixed? |
@brandon-arnold all the ssr related issues are to be considered for release 0.19. |
(This PR builds on the changes of #559; thus those changes are included in the diff as well.)
When using
react-slick
in isomorphic apps, the slider will be rendered before any client-side JavaScript has been run, leading to issues like #254, #508, or #537.This PR provides a simple solution based on the
initialized
state that's already included ininitial-state.js
. It's a more React-like solution compared to #256.By calling the
setState
incomponentWillMount
we prevent unnecessary re-rendering on pure client-side apps.Compared to #288 this change implicitly takes the
slidesToShow
into account, as theslick-active
class already handles that correctly.After applying those changes, users will be able to optionally add the following styles in order to display the active slide while javascript has not been initialized yet:
Edit: It's actually also necessary to add something like the following. Otherwise you end up with the active slide being shown twice.