Skip to content

Svelte 5: <script> tag doesn't load conditionally #11082

@Aloso

Description

@Aloso

Describe the bug

An {#if} branch containing only a <script> does not work in Svelte 5; the script isn't loaded when the condition becomes true.

Reproduction

{#if loading}
  <script src="https://www.instagram.com/embed.js"></script>
{/if}

complete reproduction (open the browser console and notice no request is being made)

Somehow it starts working when you add anything else (even whitespace) in the branch:

{#if loading}
  {' '}
  <script src="https://www.instagram.com/embed.js"></script>
{/if}

(it still doesn't work in the svelte playground due to CORS, but the request shows up in the browser console)

Logs

No response

System Info

System:
    OS: Linux 6.7 Manjaro Linux
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 681.68 MB / 7.11 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 21.6.2 - /usr/bin/node
    Yarn: 1.22.21 - /usr/bin/yarn
    npm: 10.5.0 - /usr/bin/npm
    pnpm: 8.15.2 - /usr/bin/pnpm
    bun: 0.1.13 - /usr/bin/bun
  Browsers:
    Chromium: 123.0.6312.58
  npmPackages:
    svelte: 5.0.0-next.90 => 5.0.0-next.90

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions