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.

When using serializer.types, resolveComponent does not work and instead components have to be manually imported

See original GitHub issue

Version

module: 1.4.1 nuxt: 3-rc.11

When using the serializer, based on the docs, it seems the following should be possible:

<template>
  <SanityContent :blocks="content" :serializers="serializers"/>
</template>

<script setup>
import { resolveComponent } from 'vue'
  const props = defineProps({
    content:{required:true,type:Array}
  })

  const serializers = {
    types: {
      youtube:resolveComponent('YoutubeVideo'),
      gallery:resolveComponent('Gallery')
    },
  }
</script>

However, it returns the following error:

Failed to resolve component: Gallery
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. 

The only way I have managed to get this to work, is by importing the component manually, like so:

<template>
  <SanityContent :blocks="content" :serializers="serializers"/>
</template>


<script setup>
  import YoutubeVideo from '~/components/YoutubeVideo.vue'
  import Gallery from '~/components/Gallery.vue'


  const props = defineProps({
    content:{required:true,type:Array}
  })

  const serializers = {
    types: {
      youtube:YoutubeVideo,
      gallery:Gallery
    },
    marks: {
      // You can also just pass a string for a custom serializer if it's an HTML element
      internalLink: 'a'
    }
  }
</script>


Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
pascalwengertercommented, Dec 19, 2022

@danielroe would you mind keeping this issue open? At least @toddpadwick and me tried using the docs in their current form and ended up having problems, I suppose there’s some potential in being more clear on the different ways/use cases 😃

1reaction
danielroecommented, Dec 19, 2022

If Nuxt can’t know at build time which components you need, then you should mark them as global so they will all be built and available at runtime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · nuxt-modules/sanity - GitHub
When using serializer.types, resolveComponent does not work and instead components have to be manually imported bug Something isn't working.
Read more >
Serializers - Django REST framework - Tom Christie
Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered...
Read more >
Serializers - Django REST framework
Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily ...
Read more >
Define component schema with drf-spectacular for django API
As I am not using serializers, I am defining everything in the extend_schema decorator. Now my question is, if it is possible to...
Read more >
Model Relationships in Django REST Framework - Corgibytes
There are three major kinds of relationship between database entries: ... Don't worry, Django knows how to work with this, so you can...
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