sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.89k stars 4.25k forks source link

Allow mustache syntax inside nested <script> for SSR components #7748

Closed dmitrysmagin closed 2 years ago

dmitrysmagin commented 2 years ago

Describe the problem

I'm using Svelte as a part of Elderjs framework which generates static pages using Svelte templates in SSR mode. Very often it is needed to have some js code on the static page without hydrating the whole component.

<script>
    // This is executed when generating the SSR component
    let something = "TESTING";
</script>

<div>
    <!-- Below 'something' is evaluated both for the attribute and inside the tag -->
    <div someattr={something }>This string should read {something}></div>

    <!-- But here 'something' is not evaluated inside the tag -->
    <!-- This code is executed in browser when the page is loaded, so it has no access to vars in <script> above -->
    <script someattr={something }>console.log({something})</script>
<div>

Describe the proposed solution

The text inside nested Githubissues.

  • Githubissues is a development platform for aggregating issues.