Skip to content
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

SSR nuxt #13

Open
merijnponzo opened this issue Oct 26, 2020 · 11 comments
Open

SSR nuxt #13

merijnponzo opened this issue Oct 26, 2020 · 11 comments
Labels
bug Something isn't working need more info

Comments

@merijnponzo
Copy link

Hi does this work with nuxt / ssr?
I've got

document is not defined 

Not sure if I implemented the virtual grid in the right way

  return styleElement
}

function addStyle (obj /* StyleObjectPart */) {
  var update, remove
  var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]')

  if (styleElement) {
    if (isProduction) {
      // has SSR styles and in production mode.
      // simply do nothing.
@Mikescops Mikescops added bug Something isn't working need more info labels Oct 26, 2020
@Mikescops
Copy link
Owner

Hello,

Do you mind sending full debug log from your console and the part of the code where you use the grid, thanks 😄

@merijnponzo
Copy link
Author

Hi,
I added virtual grid to my nuxt config

{ src: '~/plugins/vue-virtualgrid'}

within plugins:
vue-virtualgrid.js

import Vue from 'vue'
import VirtualGrid from 'vue-virtual-grid'
Vue.use(VirtualGrid)

then within any nuxt page

<template>
<div>
  <VirtualGrid :items="{}" />
</div>
</template>
<script>
import VirtualGrid from 'vue-virtual-grid'

export default {
  components: { VirtualGrid },

I'm aware i should pass the renderdata as an object but passing an empty object should work for a starter ;-)
this directly results into:

Screenshot 2020-10-27 at 09 18 53

thanks!

And may i ask, will it be possible to add slot content in the future, it would be a lot easier if i could use the item component just within the virtual grid component

@Mikescops
Copy link
Owner

Mikescops commented Oct 27, 2020

First of all, it should be an array of object, so passing [] should work indeed.

But from the error you get, it seems unrelated...

And may i ask, will it be possible to add slot content in the future, it would be a lot easier if i could use the item component just within the virtual grid component

Not sure what you are asking, can you rephrase?

@Mikescops
Copy link
Owner

So after some searches.

This plugin do not support SSR as of now. You can use it with:

{ src: '~/plugins/vue-virtualgrid', ssr: false}

There is maybe an answer here: https://stackoverflow.com/questions/61409902/vue-how-to-build-bundle-for-nuxt-with-vue-cli-service

Let me know if that helps.

@MentalGear
Copy link

MentalGear commented Nov 26, 2020

@merijnponzo Were you able to get this working with nuxt? If so, would really appreciate if you could let us know the solution.

Screenshot 2020-11-26 at 16 09 09

@MentalGear
Copy link

MentalGear commented Nov 26, 2020

Alright, got it figured out. I still imported the component in the page I was using it, which doesn't work when it is already imported with Vue.use(VirtualGrid) in the /plugins directory.

Here's the complete solution for nuxt:

plugin file virtualgrid.js (in /plugins)

import VirtualGrid from 'vue-virtual-grid'

import Vue from 'vue'
Vue.use('VirtualGrid', VirtualGrid) // MUST match the name you use when calling the component, e.g. <VirtualGrid ...>

Where you want to use the component.

  • DO NOT use import 'VirtualGrid from ...' again
  • DO NOT define VirtualGrid under 'components: []'

Just use <VirtualGrid ... > on your page.

@merijnponzo
Copy link
Author

Hi, i switched to vue-virtual-scroll-list due the lack of time for a deadline :-)

And i prefer using slots.

Best!

@MentalGear
Copy link

Hi, i switched to vue-virtual-scroll-list due the lack of time for a deadline :-)

And i prefer using slots.

Best!

Thanks man for the reply. Mh, I would need Grid Layout support - I guess vue-virtual-scroll-list doesn't support that, or does it? Yeah, slots are pretty sweet. :)

@MentalGear
Copy link

Seems like I spoke too soon. Even though I don't get a fatal nuxt error now, I get this in the debug console:

[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 < /p/ >, or missing . Bailing hydration and performing full client-side render.
warn @ vue.runtime.esm.js?2b0e:619
patch @ vue.runtime.esm.js?2b0e:6497
Vue._update @ vue.runtime.esm.js?2b0e:3945

vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

@MentalGear
Copy link

MentalGear commented Nov 26, 2020

Alright, got rid of the "not registered" error. Apparently, one has to use Vue.component to register pure components, while Vue.use registers plugins that themselves internally register components.

Updated virtualgrid.js (/plugins folder)

import VirtualGrid from 'vue-virtual-grid'

import Vue from 'vue'
Vue.component('VirtualGrid', VirtualGrid) // instead of Vue.use

Source: https://stackoverflow.com/a/61163860

@Mikescops
Copy link
Owner

I'm not sure I follow you @MentalGear , did you manage to make it work with SSR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need more info
Projects
None yet
Development

No branches or pull requests

3 participants