Skip to content

Svelte 5: Regular scripts no longer execute #9484

@brunnerh

Description

@brunnerh

Describe the bug

Scripts that are not the component top-level script do not seem to execute.
Apparently the way that <script> gets inserted into the document matters for execution, maybe that needs a special case.

Reproduction

<div>
	<!-- NOT a Svelte script -->
	<script>
		function logMessage(text) {
			console.log(text);
		}
		console.log('logMessage is', typeof logMessage);
	</script>
</div>

<button onclick={() => eval("logMessage('Hello')")}>
	Log "Hello"
</button>

v4
v5

Thought that maybe isolating the <script> so it would be inserted separately using {#if true} instead of a div would maybe help, but it did not.

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions