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.

`You should use slots` when using components and json files

See original GitHub issue

Environment

  • Operating System: Windows_NT
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.5
  • Builder: vite
  • User Config: meta, css, modules, build, vite, router, publicRuntimeConfig, content, tailwindcss
  • Runtime Modules: @nuxt/content@2.0.0, @nuxtjs/tailwindcss@5.1.2, @vueuse/nuxt@8.5.0, vue-plausible@1.3.1
  • Build Modules: -

Reproduction

Use the content-wind template and create a test.json in /content with one of the 2 following contents:

{
    "title": "Test",
    "description": "a test description"
}

or

{
    "title": "Test",
    "description": "a test description",
    "body": {
        "type": "root",
        "children": [
            {
                "type": "element",
                "tag": "h1",
                "props": {
                    "id": "title"
                },
                "children": [
                    {
                        "type": "text",
                        "value": "title"
                    }
                ]
            }
        ]
    }
}

Then go to http://localhost:3000/test

Describe the bug

I expect the content but I get the following error rendered by the component:

{
  "message": "You should use slots with <ContentRenderer>",
  "value": {
    "_path": "/test",
    "_draft": false,
    "_partial": false,
    "title": "Test",
    "description": "a test description",
    "excerpt": {
      "type": "root",
      "children": [
        {
          "type": "element",
          "tag": "h1",
          "props": {
            "id": "title"
          },
          "children": [
            {
              "type": "text",
              "value": "title"
            }
          ]
        }
      ]
    },
    "body": {
      "type": "root",
      "children": [
        {
          "type": "element",
          "tag": "h1",
          "props": {
            "id": "title"
          },
          "children": [
            {
              "type": "text",
              "value": "title"
            }
          ]
        }
      ],
      "toc": {
        "title": "",
        "searchDepth": 2,
        "depth": 2,
        "links": []
      }
    },
    "_id": "content:2.test.json",
    "_type": "json",
    "_source": "content",
    "_file": "2.test.json",
    "_extension": "json"
  },
  "excerpt": false,
  "tag": "div"
}

Same with ContentDoc

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jbierfeldtcommented, Aug 9, 2022

Instead of running yarn run preview you can run npx serve .output/public

Unfortunately, I am seeing the same error even if I serve .output/public or dist directly.

{
  "message": "You should use slots with <ContentDoc>",
  "slot": "default",
  ...
}

I tried changing my catch-all page so that the <ContentDoc> component uses slots, using the code below, pulled directly from the <ContentDoc> api page:


<template>
  <main>
    <ContentDoc v-slot="{ doc }">
      <h1>{{ doc.title }}</h1>
      <ContentRenderer :value="doc" />
    </ContentDoc>
  </main>
</template>

After doing this, I’m still getting essentially the same error, but now it is complaining about the lack of slot usage in <ContentRenderer>:

{
  "message": "You should use slots with <ContentRenderer>",
  ...
}
2reactions
L422Ycommented, Nov 7, 2022

I found that my issue was dealing with CloudFront and Legacy cache settings - I updated my cache settings to their current version and this solved the problem.

I too was having issues with CloudFront. Adding an adjusted behavior for /api/* seems to have also helped, but I did a clean node_modules install and lost my modification (posted above) and things stopped working again, once I restored the change, things seem to work as expected (mostly)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Slots and Web Components - Raymond Camden
A look at slots and how they work with web components. ... Obviously, the use of slots versus arguments will change on a...
Read more >
Vue.js simplified: Components, props, and slots
This simole guide shows you how to use components, props, and slots to make writing code in Vue.js easier, cleaner, and faster.
Read more >
Using slots in Vue js - James Doyle
If you are working with server-rendered apps, using Vue slots can help you create more reusable and flexible components.
Read more >
Understand the components.json File and Format
Each component has an "id" property, which must be unique. This property is used to distinguish between components with the same "type" ....
Read more >
Component Slots - A Vue.js Lesson From our Vue.js Course
If you need to pass HTML to your components, use slots. If you need to pass data, use props. Important Note. Since Vue.js...
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