Heex performs html validation and there were few bugs in its html validation. You might be experiencing this bug:
opened 11:56PM - 30 Sep 21 UTC
closed 08:01AM - 01 Oct 21 UTC
### Environment
* Elixir version (elixir -v): 1.12.3
* Phoenix version (mix … deps): 1.6.0
* Phoenix LiveView version (mix deps): 0.16.4
* Operating system: MacOS 11.6
* Browsers you attempted to reproduce this bug on (the more the merrier): none
* Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: no
### Actual behavior
The project fails to compile on new .heex templates with the following JS embedded
```
<script type="text/javascript" nonce={@conn.assigns[:script_src_nonce]}>
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
heap.load({heap_key});
</script>
```
The stacktrace is:
```
== Compilation error in file lib/portal_web/views/layout_view.ex ==
** (Phoenix.LiveView.HTMLTokenizer.ParseError) lib/portal_web/templates/layout/shareable.html.heex:38:674: expected attribute name
(phoenix_live_view 0.16.4) lib/phoenix_live_view/html_tokenizer.ex:252: Phoenix.LiveView.HTMLTokenizer.handle_attribute/5
(phoenix_live_view 0.16.4) lib/phoenix_live_view/html_engine.ex:90: Phoenix.LiveView.HTMLEngine.handle_text/3
(eex 1.12.3) lib/eex/compiler.ex:48: EEx.Compiler.generate_buffer/4
(eex 1.12.3) lib/eex/compiler.ex:80: EEx.Compiler.generate_buffer/4
(phoenix_view 1.0.0) lib/phoenix/template.ex:371: Phoenix.Template.compile/3
(phoenix_view 1.0.0) lib/phoenix/template.ex:165: anonymous fn/4 in Phoenix.Template."MACRO-__before_compile__"/2
(elixir 1.12.3) lib/enum.ex:2385: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_view 1.0.0) expanding macro: Phoenix.Template.__before_compile__/1
```
### Expected behavior
.heex templates with embedded JS compile without error.
### Context and Thanks
Beautifying the ugly JS here still causes an error but different messages at different locations. Sorry if this is expected but it doesn't seem like it should be failing on this case. Have a great evening, thank you for looking into this! If you need additional help and context, please let me know. Thanks again!
Check the version of phoenix_live_view
you are using. Upgrading to the latest {:phoenix_live_view, "~> 0.17.6"}
will help - many html validation bugs have been fixed in recent releases.
If problem still exists after upgrading to latest - log a bug on phoenix_live_view repository.
Previous discussion in the forum:
Here’s the snippet Segment is giving me:
<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnony…