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.

Better support for <script>

See original GitHub issue

&lt;script> is a bit hard to use right now.

  • If you have a {...} then it’s going to start interpolating. And you are bound to have whenever you use if, function … Workaround: you can wrap it inside of an interpolated string {'if (true) { ... }'}
  • If you have any ' or " it’s going to output the html encoded version and Javascript is going to throw a parsing exception.

In order to workaround those two issues the best way I found is to use dangerouslySetInnerHTML and use ES6 backtick in order to have multi-line strings.

<script dangerouslySetInnerHTML={{__html: `
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('send', 'pageview');
`}} />

We should probably make it easier, it’s quite a pain to use right now.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
martencommented, Aug 26, 2014

@spicyj If I may answer for @matthewwithanm, since I just ran into the same issue, we still have some server-side rendered pages that we would like to open inside a modal dialog.

I made a Dialog component that gets a URL via props, and on componentDidMount fetches HTML from the server, and renders it inside the dialog using dangerouslySetInnerHTML. I was quite surprised when I found out that the code inside the script tag that was also in the fetched HTML was not executed.

0reactions
bochen2014commented, Jun 1, 2017

@syranide thanks for sharing that! i didn’t know it before

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Write a Great Customer Support Script for Frontline ...
Drafting a new customer support script, but don't know where to begin? Follow these sure-fire tips to set up your agents for success....
Read more >
Customer Service Call Scripts for IT Help Desks: 7 Best ...
One way to improve your IT help desk performance is to use customer service call scripts. Here are some examples and best practices...
Read more >
Run a support script - ExtraHop Documentation
In the Status and Diagnostics section, click Support Scripts. · Click Run Custom Support Script. · Click Choose File, navigate to the diagnostic...
Read more >
50+ Customer Service Scripts For Your Team
Explore 50+ ready-to-use customer service script templates. ... Read More: Choose the Best Customer Support Channels for Your Growing ...
Read more >
Use These Scripts To Get More Effective Support, Ideas, And ...
Below, you'll find 8 dos and don'ts of asking for support for your small business. Plus, I've provided a number of scripts you...
Read more >

github_iconTop Related Medium Post

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