maoberlehner / vue-lazy-hydration

Lazy Hydration of Server-Side Rendered Vue.js Components
MIT License
1.18k stars 52 forks source link

Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'. #19

Closed mauxtin closed 4 years ago

mauxtin commented 5 years ago

Recently got two error messages on sentry. Both are from an Android 4.4.4 device on a Chrome browser (Chrome 73.0.3683)

Not sure if I can help in any way or if they are related (let me know if it's better to create a separate issue for the second one). 1)

TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.
  at call(./node_modules/vue-lazy-hydration/dist/LazyHydrate.esm.js:364:1)
  at invokeWithErrorHandling(./node_modules/vue/dist/vue.runtime.esm.js:1854:1)
  at callHook(./node_modules/vue/dist/vue.runtime.esm.js:4213:1)
  at insert(./node_modules/vue/dist/vue.runtime.esm.js:3139:1)
  at invokeInsertHook(./node_modules/vue/dist/vue.runtime.esm.js:6340:1)
  at __patch__(./node_modules/vue/dist/vue.runtime.esm.js:6559:1)
  at _update(./node_modules/vue/dist/vue.runtime.esm.js:3939:1)
  at call(./node_modules/vue/dist/vue.runtime.esm.js:4060:1)
  at get(./node_modules/vue/dist/vue.runtime.esm.js:4473:1)
  at new xn(./node_modules/vue/dist/vue.runtime.esm.js:4462:1)
  at vm(./node_modules/vue/dist/vue.runtime.esm.js:4067:1)
  at $mount(./node_modules/vue/dist/vue.runtime.esm.js:8409:1)
  at i(./node_modules/vue/dist/vue.runtime.esm.js:3118:1)
  at hydrate(./node_modules/vue/dist/vue.runtime.esm.js:6372:55)
  at hydrate(./node_modules/vue/dist/vue.runtime.esm.js:6405:1)
  at __patch__(./node_modules/vue/dist/vue.runtime.esm.js:6487:1)
  at _update(./node_modules/vue/dist/vue.runtime.esm.js:3939:1)
  at call(./node_modules/vue/dist/vue.runtime.esm.js:4060:1)
  at get(./node_modules/vue/dist/vue.runtime.esm.js:4473:1)
  at new xn(./node_modules/vue/dist/vue.runtime.esm.js:4462:1)
  at vm(./node_modules/vue/dist/vue.runtime.esm.js:4067:1)
  at $mount(./node_modules/vue/dist/vue.runtime.esm.js:8409:1)
  at i(./node_modules/vue/dist/vue.runtime.esm.js:3118:1)
  at hydrate(./node_modules/vue/dist/vue.runtime.esm.js:6372:55)
  at hydrate(./node_modules/vue/dist/vue.runtime.esm.js:6405:1)
  at __patch__(./node_modules/vue/dist/vue.runtime.esm.js:6487:1)
  at _update(./node_modules/vue/dist/vue.runtime.esm.js:3939:1)
  at call(./node_modules/vue/dist/vue.runtime.esm.js:4060:1)
  at get(./node_modules/vue/dist/vue.runtime.esm.js:4473:1)
  at new xn(./node_modules/vue/dist/vue.runtime.esm.js:4462:1)
  at vm(./node_modules/vue/dist/vue.runtime.esm.js:4067:1)
  at $mount(./node_modules/vue/dist/vue.runtime.esm.js:8409:1)
  at mount(./.nuxt/client.js:495:10)
  at call(./.nuxt/client.js:525:5)
  at tryCatch(./node_modules/regenerator-runtime/runtime.js:45:15)
  at _invoke(./node_modules/regenerator-runtime/runtime.js:271:1)
  at key(./node_modules/regenerator-runtime/runtime.js:97:1)
  at asyncGeneratorStep(./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1)
  at _next(./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:25:1)

2)

TypeError: Cannot read property '0' of undefined
  at call(./node_modules/vue-lazy-hydration/dist/LazyHydrate.esm.js:397:6)
  at _render(./node_modules/vue/dist/vue.runtime.esm.js:3542:1)
  at call(./node_modules/vue/dist/vue.runtime.esm.js:4060:1)
  at get(./node_modules/vue/dist/vue.runtime.esm.js:4473:1)
  at run(./node_modules/vue/dist/vue.runtime.esm.js:4548:1)
  at flushSchedulerQueue(./node_modules/vue/dist/vue.runtime.esm.js:4304:1)
  at i(./node_modules/vue/dist/vue.runtime.esm.js:1980:1)
  at flushCallbacks(./node_modules/vue/dist/vue.runtime.esm.js:1906:1)
maoberlehner commented 5 years ago

Hey @mauxtin! Could you post a reproduction link via CodeSandbox? Thx!

rcpires commented 5 years ago

Same error to me (just error 1) on chrome Version 74.0.3729.157 (Official Build) (64-bit). Example (just code, not codesandbox):

<template>
  <div class="homepage">
    <section-welcome section-name="welcome"/>

    <LazyHydrate v-slot="{ hydrated }" when-visible>
      <section-themes-carousel v-if="hydrated"
        section-name="themes"
        :show-link-to-all-features="true"
        :hasThemeFinalSlide="true"
      >
        <template slot="header">
          <header>
            <h2 class="title is-2">
              Deixe
              <span class="has-text-primary">seu site</span> com sua cara
              <br>São mais de
              <span class="has-text-primary">30 modelos para você personalizar</span>
            </h2>
          </header>
        </template>
      </section-themes-carousel>
    </LazyHydrate>

    <LazyHydrate v-slot="{ hydrated }" when-visible>
      <section-gifts-intro v-if="hydrated" section-name="presentes-introducao">
        <template slot="header">
          <header style="margin-bottom: 2em" v-animate="'fadeInUp'" class="animated">
            <h2 class="title is-2">
              E o melhor:
              <br>Sua
              <span class="has-text-primary">lista de presentes</span> é
              <span class="has-text-primary">convertida em dinheiro</span>,
              <br class="is-hidden-mobile">para você
              <span class="has-text-primary">gastar como quiser</span>
            </h2>
          </header>
        </template>
        <template slot="footer">
          <footer v-animate="'fadeInUp'" class="animated section-gifts-intro-footer">
            <p class="hero-body p-top-0">
              Tudo isso com a
              <strong class="has-text-primary">melhor taxa do mercado</strong> e em até
              <strong class="has-text-primary">3 dias o dinheiro</strong> estará em
              <strong class="has-text-primary">sua conta PayPal</strong>
            </p>
            <a
              href="/lista-de-casamento"
              class="button is-primary is-medium"
            >Vantagens da lista de casamento</a>
          </footer>
        </template>
      </section-gifts-intro>
    </LazyHydrate>
  </div>
</template>

<script>
import LazyHydrate from "vue-lazy-hydration";

export default {
   // other props hidden,
   components: {
    LazyHydrate,
    SectionWelcome: () => import("~/components/home/SectionWelcome.vue"),
    SectionThemesCarousel: () => import("~/components/SectionThemesCarousel.vue"),
    SectionGiftsIntro: () => import("~/components/home/SectionGiftsIntro.vue"),
  }
};
</script>
maoberlehner commented 5 years ago

Would be great to know more about your setup, especially how you do SSR: Nuxt.js, Gridsome, custom webpack config (but reproduction links are much preferred if you want to get help fast!)? Thx!

maoberlehner commented 5 years ago

Generally speaking, I know there can be problems in certain circumstances with using v-if="hydrated" in new versions of Vue.js (I'm working on it).

But reproduction links would be very helpful!

maoberlehner commented 5 years ago

Additional info: it seems to have to do with the changes regarding scoped slots in Vue.js 2.6.0+ I'm working on it. For now you can simply remove v-slot and v-if="hydrated".

maxxcs commented 4 years ago

I had the same issue when I used with <component :is="someComponent" />

Example:

<LazyHydrate v-slot="{ hydrated }" on-interaction>
  <component :is="someComponent" v-if="hydrated" />
</LazyHydrate>
mfrascati commented 4 years ago

I had the same issue, but the issue happened lazy loading a component having a v-if.

In my case I had the error on route leave, because in the beforeRouteLeave I was cleaning the object, making the v-if false, so on LazyHydrate self cleaning the object was not present. Easily fixed by wrapping my component in a div.

Maybe this solution can be helpful for somebody else!