question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSR and responsive mode

See original GitHub issue

I already open this issue on the nextjs repo but it seems to be a problem with react-slick.

Describe the bug When I use next.js with react-slick and responsive options, there is a bug during the rehydration phase, the src attribute of the images are mixed between the slides.

The error message is Warning: Prop src did not match. Server: "http://via.placeholder.com/350x150?text=7" Client: "http://via.placeholder.com/350x150?text=8"

To Reproduce I made an example from examples folder : https://github.com/padupuy/next.js/tree/feature/with-react-slick

The code is right here : https://github.com/padupuy/next.js/blob/feature/with-react-slick/examples/with-react-slick/pages/index.js

Expected behavior The image sources must not be mixed

Screenshots capture d ecran 2018-05-16 a 18 29 07 capture d ecran 2018-05-16 a 18 31 01

System information

  • OS: macOS High Sierra 10.13.4
  • Browser (if applies) : at least chrome and safari
  • Version of Next.js: at least 5.1 and 6.0.2

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:24
  • Comments:30

github_iconTop GitHub Comments

36reactions
isBatakcommented, Feb 13, 2019

This is my solution:

import React, { PureComponent } from 'react';
import SlickSlider from 'react-slick';

class Slider extends PureComponent {
  state = {
    isClient: false
  };

  componentDidMount() {
    this.setState((state) =>  { isClient: true });
  }

  render() {
    const {
        children,
        responsive,
        ...rest
    } = this.props;
    const { isClient } = this.state;

    return (
      <SlickSlider 
          key={isClient ? 'client' : 'server'}
          responsive={isClient ? responsive : null}
          {...rest}
      >
        {children}
      </SlickSlider>
    );
  }
}

export default Slider;
34reactions
davidsanchez96commented, Jun 26, 2018

I don’t know if is the best approach but I solved this problem by using dynamic import

import dynamic from 'next/dynamic'

const SliderComponentWithNoSSR = dynamic(import('../components/SliderComponent'), {
  ssr: false
})

export default () =>
  <div>
    <SliderComponentWithNoSSR />
  </div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React 02 - SSR vs Responsive Design | by Brian Shen - Medium
1. What happens when we combine SSR and responsive design. If we mix SSR with responsive design, there are lots of challenges. Why?...
Read more >
Combining Server-Side Rendering and Responsive Design
Let's explain the challenge that comes up when mixing SSR and responsive design, and introduce a couple of possible strategies to approach ...
Read more >
Server-Rendering Responsively - Artsy Engineering
Combining SSR and responsive design is a non-trivial problem. There are many concerns to manage, and they are sometimes in conflict with each ......
Read more >
What is SSR - Quasar Framework
quasar/app-webpack) Introduction on server-side rendered apps with Quasar CLI.
Read more >
How to combine React Native Web + responsivity + NextJS ...
How to get SEO on the web by combining: React Native Web (RNW); Responsive styles (media queries); NextJS Server-Side Rendering (SSR).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found