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.

Question: How can I use the carousel with server side rendering?

See original GitHub issue

Please suggest how to use with Vue SSR. I am trying to integrate this with VueJS’s framework Nuxt.js

import Vue from 'vue'
if(process.BROWSER_BUILD) {
    const VueCarousel = require('vue-carousel');
    VueCarousel.default.install(Vue)
}

I am getting this

vue.runtime.common.js:521 [Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside

, or missing . Bailing hydration and performing full client-side render.

Although I am able to make it work in dev mode, regardless of the warning. On production mode vue-carousel doesn’t work and doesn’t show images at all. image

Please suggest.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
dieguezzcommented, Aug 2, 2017

I solved it by:

// nuxt.config.js

plugins: [{ src: '~/plugins/carousel', ssr: false }],

// plugins/carousel.js

import Vue from 'vue'
import { Carousel, Slide } from 'vue-carousel'

Vue.component('carousel', Carousel)
Vue.component('slide', Slide)

Hope it helps!

20reactions
dfeecommented, Mar 5, 2018

I initially missed @sainf’s recommendation, but indeed the answer to this thread appears to be the following:

// plugins/vue-carousel.js
import Vue from 'vue';
import VueCarousel from 'vue-carousel';

Vue.use(VueCarousel);
// nuxt.config.js
{
...
  plugins: [ '~/plugins/vue-carousel' ],
...
}
// e.g. pages/index.vue
<template>
<no-ssr>
  <carousel>
    <slide v-for='i in 10' :key='i'>Slide {{ i }}</slide>
  </carousel>
</no-ssr>
</template>

A couple points – I didn’t specify ssr: false in nuxt.config.js and that’s because while it’s true that vue-carousel should not be used in SSR mode, it actually needs to be wrapped in a no-ssr component which appears to take a higher precedence.

** note that no-ssr is bundled into nuxt.js at this point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a React Carousel component that rocks with Server ...
... I am going to show you how you can create your own Carousel component using React that supports multiple items and server-side...
Read more >
Server Side Rendering Carousels in Vue.js - HackerNoon
The server renders blank inside client-only. The browser will render the carousel after it evaluates the necessary javascript. Performance ...
Read more >
React Multiple Items Carousel with Server Side Rendering ...
With this article I am going to show you how you can create your own Carousel component using React that supports multiple items...
Read more >
Owl Carousel 2 server side rendering in Reactjs
I used loadable to be able to import the library and it worked fine with SSR. First install loadable: npm install @loadable/component.
Read more >
SSR for multiple breakpoints using React - DEV Community ‍ ‍
However, in my case, the server would SSR the carousel for the different theme (breakpoint) and then re-render it on the client-side using...
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