Does this work with server side rendering? no 'window' or 'document' dependencies?
I've been trying out too many carousel react components that assume they are running on the client and have 'window' and 'document' dependencies all over the place. This breaks the code trying to integrate it on an isomorphic app...
Nope, it doesn't, also depends on mounted DOM for measurement.
@Ajar-Ajar did you ever find a solution for isomorphic rendering?
Isomorphic / universal React web-apps are becoming the standard
To avoid a ReferenceError: window is not defined
I'd suggest to wrap all dependencies to window with
var canUseDOM = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
)
if(canUseDOM ){
// use window dependency...
}else{
//have an alternative that wouldn't break functionality...
}
This should be fixed in [email protected]
I'm having the same problem with a universal setup. The carousel mostly works when I use via stylesheet tags, but on first load (server-side render) there are visual bugs with the slider that disappear by clicking through links (client-side render).
When I try with the npm package instead of stylesheet tags it doesn't work at all.
Ran into this issue as well. Current solution is as @Ganasist mentioned, if working with a universal setup, it will only work properly if you include both the stylesheet and the npm package.
@ypyang237 I'm having this issue as well. When you say "include both the stylesheet and the npm package", do you mean you are including the CDN for slick-carousel, while using npm for react-slick? Or are you importing the slick-carousel stylesheets to a separate stylesheet? None of the css is being applied on my isomorphic app.
Thanks in advance!
@alexanthony813
Yes, you understood correctly. I included the two CDN stylesheets for slick-carousel and had react-slick installed with npm as well to get it working. Hope this helps you!
I have react-slick working with server-side rendering, however I get the following error when using certain responsive settings. I believe it has to do with features only available in my "responsive" breakpoint (i.e. dots):
Settings:
const settings = {
dots: false,
draggable: false,
fade: true,
infinite: true,
swipe: false,
responsive: [
{
breakpoint: 767,
settings: {
dots: true,
draggable: true,
fade: false,
swipe: true,
},
},
],
};
Error:
Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
Not sure if anything can be done about this, since the server-side rendered component doesn't know the browser width and the dots will always render client-side, but maybe there's a way to make this error disappear?
I'm having the same issue that @coreyleelarson. It even shows the difference between server and client rendering:
(client) "><div class="slick-arrow slick-prev"
(server) "><div class="slick-list" data-reactid="
This enquire.js require breaks again server rendering:
https://github.com/akiran/react-slick/commit/b798b1fbd0aa50c73b3c0a2b506b7a27a3f40f31#diff-e8eaa42a1b8ab4981d9272be425c03dfR8
node_modules/enquire.js/src/MediaQueryDispatch.js:14
if(!window.matchMedia) {
^
ReferenceError: window is not defined
at new MediaQueryDispatch (node_modules/enquire.js/src/MediaQueryDispatch.js:14:9)
at Object.<anonymous> (node_modules/enquire.js/src/index.js:2:18)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/react-slick/lib/slider.js:25:16)
getting the same error as @paradoxxxzero
having same error as @paradoxxxzero too hard downgrading react-slick to 0.14.6 solved this issue. I hate to downgrade like this but hopefully it gets resolved soon.
Same error as @paradoxxxzero within a universal app has popped up in the last 48 hours using v0.14.5.
@jdmswong @rtmalone Can you try 0.14.11
0.14.11 seems to fix the server rendering :+1:
@paradoxxxzero @akiran indeed. upgrading to 0.14.11 solved the issue. thanks, all.
I am using the latest build 0.15.0 but still while rendering on server side getting visual issues.Included the stylesheets too as mentioned in above comments but still not able to work out.Anyone has any working examples?
All the issues that are related to server-side rendering, are supposed to be handled in the third release (maybe the third week) from now.
@laveesingh Wanted to check in on this. I have been trying to find a way around this (can't just only render it Client side as we need the HTML for SEO), and am wondering if I should just wait for the official solution or keep plugging away.