Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
Why does `dangerouslySetInnerHTML` not execute the javascript in nextjs?

In my next js application i would like for a script tag to be loaded and some javascript to be executed. what i have in my next js component is as follow :-

typeof window !== 'undefined' ? <div data-id='text_div_for_testing_only' dangerouslySetInnerHTML={{ __html: product.description }}></div> : null

The contents of product.description is as follows :-

<script>alert("I am the richtextbox alert")</script>

What i see in the HTML is basically this

<script>alert("I am the richtextbox alert")</script>

Unfortunately, the javascript never gets executed. However, if i do the following :-

typeof window !== 'undefined' ? alert("ok alert me") : null

I do see an alert in the UI. So why does dangerouslySetInnerHTML not execute the javascript in nextjs ?

P.S. also can't use Script from nextjs as i'am using a lower version of nextjs.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!