Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal component ProseCode class attribute seems to be not working #2111

Closed
narasimhajupally opened this issue Jun 17, 2023 · 7 comments · Fixed by #2187
Closed

internal component ProseCode class attribute seems to be not working #2111

narasimhajupally opened this issue Jun 17, 2023 · 7 comments · Fixed by #2187

Comments

@narasimhajupally
Copy link

Environment

Reproduction

We can the following warning

Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. 
  at <ProseCode class="language-javascript" code="var num1, num2, sum;\nnum1 = prompt(\"Enter first number\");\nnum2 = prompt(\"Enter second number\");\nsum = parseInt(num1) + parseInt(num2); // \"+\" means \"add\"\nalert(\"Sum = \" + sum); // \"+\" means combine into a string\n" language="javascript"  ... > 
  at <AsyncComponentWrapper class="language-javascript" code="var num1, num2, sum;\nnum1 = prompt(\"Enter first number\");\nnum2 = prompt(\"Enter second number\");\nsum = parseInt(num1) + parseInt(num2); // \"+\" means \"add\"\nalert(\"Sum = \" + sum); // \"+\" means combine into a string\n" language="javascript"  ... > 
  at <ContentRendererMarkdown value=

clone this repo https://github.com/narasimhajupally/tailwind-nuxtjs-starter-blog and go to route /blog/code-sample
you will see the warning [Vue warn] in the developer console.

Describe the bug

classes like language-javascript and language-python that are needed for syntax highlighting are not coming into effect.`

Additional context

No response

Logs

No response

@helltraitor
Copy link

Inline code highlight maybe enabled with `<code>`{lang=<lang>}

`const sum = parseInt('1')`{lang=js}
Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. 
  at <ProseCode class="language-javascript" code="var num1, num2, sum;\nnum1 = prompt(\"Enter first number\");\nnum2 = prompt(\"Enter second number\");\nsum = parseInt(num1) + parseInt(num2); // \"+\" means \"add\"\nalert(\"Sum = \" + sum); // \"+\" means combine into a string\n" language="javascript"  ... > 
  at <AsyncComponentWrapper class="language-javascript" code="var num1, num2, sum;\nnum1 = prompt(\"Enter first number\");\nnum2 = prompt(\"Enter second number\");\nsum = parseInt(num1) + parseInt(num2); // \"+\" means \"add\"\nalert(\"Sum = \" + sum); // \"+\" means combine into a string\n" language="javascript"  ... > 
  at <ContentRendererMarkdown value=

This warning happens because you don't use documentDriven mode and that is fine. You can ignore it, override by component (with required properties) or omit this warnings by filtering props in passed data (:value="post" in your layout)

As for strange colors in your code block: you changes theme, but not background.
Try set dark theme on default mode and you will see.

Solution is to properly use dark modes (like I did, for example)

As a result, this is not problems of @nuxt/content, but your setup

I'm lucky man, because I define all I want by myself and can widely control stuff

.prose :where(pre):not(:where([class~="not-prose"] *)) {}

This selector applies dark background and comes from your tailwind.css
I'm not fan of it, so further solution is up on you.

@nobkd
Copy link
Contributor

nobkd commented Jun 25, 2023

I have a fresh doc-driven project here: https://stackblitz.com/edit/github-gfxckn?file=nuxt.config.ts
The project is highlighted as soon as you uncomment the highlight key and the server restarts. (You might have to wait a few seconds and/or reload the content page a few times for the change to be displayed)

The Vue warn is there in both cases.
So the warning and the color not being displayed seem to be two different issues.

@bobby169
Copy link

I have the same vue warn.

[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. 
  at <ProseCode class="language-html" code="<p>code styling is easy</p>\n" filename="my-first-blog-post.md"  ... > 

@bobby169
Copy link

bobby169 commented Jun 26, 2023

I try to define the props class without warning again

file: components->content->ProseCode.vue

props: {
    ...otherProps,
    class: {
      type: String,
      default: "",
    }
}

bobby169 added a commit to bobby169/content that referenced this issue Jun 26, 2023
@narasimhajupally
Copy link
Author

@helltraitor The main problem is <ProseCode> component rendering multiple fragments or text root node. It should render a single root node so inheriting the class will work.

@bobby169
Copy link

bobby169 commented Jun 27, 2023

render a single root node so inheriting the class will work

Yes, you are right. just adding a single root node should work fine.

d0rich added a commit to exactpro/docs-toolkit that referenced this issue Jul 21, 2023
d0rich added a commit to exactpro/docs-toolkit that referenced this issue Jul 21, 2023
* Update dependencies to wanted

* Update dev dependencies to latest

* Update package.json

* Define tsconfig for server

* Workaround for type issue nuxt/content#2177

* Fix ProseCode warns nuxt/content#2111

* Fix internal links
@nobkd
Copy link
Contributor

nobkd commented Aug 27, 2023

@farnabaz this still happens in edge-channel.
Example: https://stackblitz.com/edit/github-zbixzf?file=content%2Findex.md,package.json
Open the preview in a new tab and look in the console logs.

chunk-RAKT47ZN.js:1449 [Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. 
  at <ProseCode class="language-ts" code="let x: number = 0;\n" language="ts"  ... > 
...

Edit: Never mind. Works fine with v2.8.2

imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Aug 30, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.

Currently, we're getting warnings in the form of " WARN  [nuxt] Two
component files resolving to the same name ProseP:" for all components
we override. This should be fixed in an upcoming version of nuxt
(nuxt/nuxt#22882).
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Sep 5, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.

Currently, we're getting warnings in the form of " WARN  [nuxt] Two
component files resolving to the same name ProseP:" for all components
we override. This should be fixed in an upcoming version of nuxt
(nuxt/nuxt#22882).
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Sep 9, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.

Currently, we're getting warnings in the form of " WARN  [nuxt] Two
component files resolving to the same name ProseP:" for all components
we override. This should be fixed in an upcoming version of nuxt
(nuxt/nuxt#22882).
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Sep 11, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.

Currently, we're getting warnings in the form of " WARN  [nuxt] Two
component files resolving to the same name ProseP:" for all components
we override. This should be fixed in an upcoming version of nuxt
(nuxt/nuxt#22882).
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Sep 13, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.

Currently, we're getting warnings in the form of " WARN  [nuxt] Two
component files resolving to the same name ProseP:" for all components
we override. This should be fixed in an upcoming version of nuxt
(nuxt/nuxt#22882).
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Dec 16, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Dec 16, 2023
Nuxt Content 2.8 fixes Vue warnings when rendering code (see also
nuxt/content#2111). Update to this
version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants