#<script> tag in JSX logic

1 messages · Page 1 of 1 (latest)

stoic walrus
#

What would be the best practice for a scenario: <script> tags in JSX scoped which does not get build unless it's place outside JSX?

{ SUBMITTED ? (
    // No <script>
) : (
    <script></script>
)}
plush hinge
#

You could put the condition inside the script tag

#
<script define:vars={{SUBMITTED}}>
  if (SUBMITTED){
    ...
  }
</script>
plush hinge
#

For bundled scripts though they would get injected by the compiler regardless

stoic walrus
#

Let's say if a form is submitted, the <script> won't load on the Thank you page after the form is submitted

plush hinge
#

Is it that you don't want the script to load, or you found that it is not loading?

stoic walrus
#

Does not want the script to load as the thank you message doesn't need <script> which was used for form validation.

plush hinge
#

The code in your post should would

#

If you add is:inline Regardless of that

stoic walrus
#

The strange thing is, JS does not build unless I place outside JSX

plush hinge
#

It's not included in the page?

#

A minimal reproduction would help a lot

stoic walrus
#

You can test by adding this code, no trace of console.log was build

<layout>
{
<script>
console.log('Hello World');
</script>
}
</layout>
#

More like a bug or expected behaviour?

#

To add on, I use Node for SSR

plush hinge
stoic walrus
plush hinge
#

Ah okay, feel free to submit a new issue, thanks!

#

!issue