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

error img is a self-closing tag and must neither have children nor use dangerouslySetInnerHTML. #9020

Closed
1 task
dande-sun opened this issue Nov 8, 2023 · 2 comments · Fixed by #9141
Closed
1 task
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: react Related to React (scope)

Comments

@dande-sun
Copy link

Astro Info

> astro info

Astro                    v3.4.3
Node                     v20.8.1
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react
                         @astrojs/tailwind
                         @astrojs/sitemap
 error   Command failed: which xclip

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When I pass img tag as props to react component, I got an error: 'img is a self-closing tag and must neither have children nor use dangerouslySetInnerHTML.'.
but if the img tag coding in the react component, it's working.
the astro code:
image
the react code:
image

What's the expected result?

I hope can pass the img tag to React component, because astro components is deficient, and most of it is development phase.

Link to Minimal Reproducible Example

https://codesandbox.io/p/sandbox/angry-sun-xpzhps?file=%2Fsrc%2Fcomponents%2FCarousel.tsx%3A16%2C19

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 8, 2023
@milcaunicorn
Copy link

milcaunicorn commented Nov 15, 2023

Try the adding client instructions on which strategy for hydration astro should use for non astro components.

<ReactComp client:load client:only="react">
   children
</ReactComp>

@lilnasy lilnasy added pkg: react Related to React (scope) - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Nov 17, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Nov 17, 2023

Thanks for looking into it, @milcaunicorn! This really helps. Summarizing the issue:

  • Affects both dev and build
  • Affects server render, "client:only" works.
  • Appears only when experimentalReactChildren is enabled.
  • React expects self-closing elements to not have children, but the react integration's experimental feature always creates an array.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: react Related to React (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants