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

When sprig, closing HTML tag in <script> get removed #34

Closed
hongc-cc opened this issue Sep 23, 2020 · 8 comments
Closed

When sprig, closing HTML tag in <script> get removed #34

hongc-cc opened this issue Sep 23, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@hongc-cc
Copy link

hongc-cc commented Sep 23, 2020

Describe the bug

When sprig, closing HTML tag in <script> get removed

To reproduce

Live test case: https://asiaspa.com/form?123

Simplified test case

{# text.twig #}

{% include "_script.twig" %}
{{ sprig ("_script.twig") }}
{# _script.twig #}

<span>placeholder</span>
<script type="text/javascript"><span>placeholder</span></script>

Rendered Result:

<!-- test.twig -->
<span>placeholder</span>
<script type="text/template"><p>placeholder</p></script>

<span>placeholder</span>
<script type="text/template"><p>placeholder</script>

Versions

  • Plugin version:1.0.0-beta.16
  • Craft version: 3.5.11.1
@hongc-cc hongc-cc added the bug Something isn't working label Sep 23, 2020
@hongc-cc hongc-cc changed the title Weird rendering in <script> When sprig, closing HTML tag in <script> get removed Sep 23, 2020
@bencroker
Copy link
Collaborator

What are you trying to do with this code? JavaScript code is generally placed inside of <script> tags, not HTML.

<script type="text/javascript"><span>placeholder</span></script>

Either way, you should try to avoid having <script> tags inside of Sprig components and keep them in the main template only.

@hongc-cc
Copy link
Author

hongc-cc commented Sep 24, 2020

Agreed. Yet is the stripping behavior normal / expected?
I think putting HTML snippets in <script type="text/javascript"> is a common approach
when developers dont want to put too much HTML in javascript file.

Issue originated from another plugin:
verbb/formie#131

@bencroker
Copy link
Collaborator

The markup is being modified by the DOM library that Sprig uses to walk the DOM tree looking for attributes. I'll look into what can be done about this.

@bencroker
Copy link
Collaborator

Your code appears to be invalid HTML so Sprig is not really at fault here. I suggest you use the template tag, which is valid HTML and works fine with Sprig.

<template><p>placeholder</p></template>

@hongc-cc
Copy link
Author

hongc-cc commented Sep 24, 2020

i think <script type="text/template"><span>placeholder</span></script> is not invalid HTML?

@engram-design
Copy link

Just weighing in here. It's not an option to use <template> for Formie as part of our commitment to front-end support. It's not supported in IE10/11 for example.

I suppose as @bencroker mentions, its being modified by the DOM library, so it's probably an issue on their end.

Formie's repeater field uses <script type="text/template">some-html</script> in its templates.

@bencroker
Copy link
Collaborator

Ok reopening and I’ll see what can be done to make this work.

@bencroker bencroker reopened this Sep 24, 2020
@bencroker
Copy link
Collaborator

Fixed in bf4a9ab and released in version 1.0.0-beta.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants