Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

fix: useFetch in renderless component leads to error "Cannot convert undefined or null to object" #600

Open
@thekonz

Description

@thekonz

🐛 The bug
I have a renderless component that uses useFetch. In ssr: true mode, it crashes the app with this error:
Cannot convert undefined or null to object in serverPrefetch

node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs

     : vm._fetchKey || vm.$ssrContext.fetchCounters['']++
  if (!vm.$vnode.data) vm.$vnode.data = {}
  const attrs = (vm.$vnode.data.attrs = vm.$vnode.data.attrs || {})
  attrs['data-fetch-key'] = vm._fetchKey
  const data = { ...vm._data }
  Object.entries(vm.__composition_api_state__.rawBindings).forEach(
    ([key, val]) => {
      if (val instanceof Function || val instanceof Promise) return
      data[key] = isRef(val) ? val.value : val
    }
  )

The issue is that vm.__composition_api_state__.rawBindings is not set for a renderless component.

🛠️ To reproduce
Steps to reproduce the behavior:

  1. Download the repo https://github.com/thekonz/reproduce-bug-nuxt-composition-use-fetch
  2. Run yarn dev
  3. See that there is no error, if you set ssr: false in nuxt.config.js

Repo for reproduction: https://github.com/thekonz/reproduce-bug-nuxt-composition-use-fetch
Component: https://github.com/thekonz/reproduce-bug-nuxt-composition-use-fetch/blob/master/components/outer.vue

🌈 Expected behaviour

I expect it to work the same on ssr as in client.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions