mrcrmn / docc

A starter documentation theme for Gridsome. Featuring instant search, great navigation and a dark mode!
https://docc-theme.netlify.com
MIT License
125 stars 32 forks source link

TypeError when build #27

Closed kuleyu closed 4 years ago

kuleyu commented 4 years ago

Hello, there is an error happened when building.

Error: TypeError: Cannot read property 'disconnect' of null

Details:

(node:1416) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'disconnect' of null
    at a.$route (assets/js/page--src-templates-markdown-page-vue.2361b1f1.js:589:21)
......
(node:1416) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1416) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Influence: almost none. the building process finished normally, and the site worked normally.


The disconnect seems from the file ./src/components/OnThisPage.vue, line 65: this.observer.disconnect();.

some solutions?

marcodeluca commented 4 years ago

Just tried a fresh deploy and am getting the same issue. Any updates?

exuanbo commented 4 years ago

I solved this by moving this.observer.disconnect() and this.$nextTick(this.initObserver) into if (process.isClient).

IntersectionObserver is a browser API and should not be used during rendering.

watch: {
  $route: function () {
    if (process.isClient) {
      if (window.location.hash) this.activeAnchor = window.location.hash

      // Clear the current observer.
      this.observer.disconnect()

      // And create another one for the next page.
      this.$nextTick(this.initObserver)
    }
  }
}
kuleyu commented 4 years ago

@exuanbo Thanks, it's usefull.