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.

Fragments supporting dangerouslySetInnerHTML

See original GitHub issue

Is your feature request related to a problem?

Currently seems like this is not possible:

// const icon = '<svg ...>'
<Fragment dangerouslySetInnerHTML={icon}></Fragment>
Type '{ dangerouslySetInnerHTML: string; }' is not assignable to type 'IntrinsicAttributes & { children?: any; }'.
  Property 'dangerouslySetInnerHTML' does not exist on type 'IntrinsicAttributes & { children?: any; }'.ts(2322)

Describe the solution you’d like

<Fragment> should accept dangerouslySetInnerHTML like other elements

Describe alternatives you’ve considered

Using spans everywhere

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
manucorporatcommented, Aug 11, 2022

I will keep an eye open, but this is specially tricky in qwik because of the serialization requirements, and update after ssr. Thanks for the issue, but i will close since we will not implement this anytime soon

0reactions
Nefcantocommented, Nov 12, 2022

@manucorporat since you mentioned you wouldn’t be implementing this soon, what is our alternative?

We are considering migrating to Qwik + Qwik City from React + Next for our entire company and all projects.

We’re testing one project for migration and now we’re stuck at this.

In Next, we get data from a headless CMS. Inside this data, there is SVG tags. So SVG tags are not available at build time. We receive them from API.

In React, we could use:

                    <div
                        className="[&>*]:text-icon w-[55px] aspect-square group-hover:-scale-x-100 transition-all duration-500 "
                        dangerouslySetInnerHTML={{ __html: item.iconSvg }}
                    />

This way, we could print the SVG using React and style it using Tailwind.

What should we do to migrate this code to Qwik + Qwik City?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Have Fragments support dangerouslySetInnerHTML #12014
To me Fragment seems to be the ideal candidate to support dangerouslySetInnerHTML so that you may inject HTML without wrapping elements.
Read more >
Using Fragment to insert HTML rendered on the back end via ...
In my case, dangerouslySetInnerHTML was utilized to render plain HTML for a user to download; it was not ideal to have additional wrapper ......
Read more >
Dangerously Set innerHTML | React
Improper use of the innerHTML can open you up to a cross-site scripting (XSS) attack. Sanitizing user input for display is notoriously error-prone,...
Read more >
DOM Elements - React
dangerouslySetInnerHTML is React's replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it's easy to ......
Read more >
react-dom-fragment - npm
A React Fragment that supports dangerously setting innerHTML. Latest version: 1.0.0, last published: 3 years ago.
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