svelte-preview
svelte-preview copied to clipboard
Creating an EventDispatcher breaks the preview.
Describe the bug Creating an EventDispatcher breaks the preview.
To Reproduce Steps to reproduce the behavior: Create the following component.
<script>
import { createEventDispatcher } from 'svelte';
let count = 0;
function incrementCount() {
count += 1;
}
// Adding this line breaks the preview
const dispatch = createEventDispatcher();
</script>
<button on:click={incrementCount}>
Clicked {count} {count === 1 ? 'time' : 'times'}
</button>
Expected behavior When I create an event dispatcher the preview should not be affected.
Logs Error in the preview console:
Error: Function called outside component initialization
at get_current_component (/Users/boriska/code/incoming-frontend/node_modules/svelte/src/runtime/internal/lifecycle.js:11:32)
at createEventDispatcher (/Users/boriska/code/incoming-frontend/node_modules/svelte/src/runtime/internal/lifecycle.js:97:20)
at instance (/Users/boriska/code/incoming-frontend/src/lib/components/application/assistant_instructions/Test.svelte:70:19)
at init (/Users/boriska/.vscode/extensions/rafaelmartinez.svelte-preview-2.7.1/media/svelte.js:2111:7)
at new Component (/Users/boriska/code/incoming-frontend/src/lib/components/application/assistant_instructions/Test.svelte:77:3)
at /Users/boriska/code/incoming-frontend/src/lib/components/application/assistant_instructions/Test.svelte:81:5
Run the command <img width="553" alt="Screenshot 2024-09-19 at 5 54 39 PM" src="https://github.com/user-attachments/assets/1bd3b81f-91da-4ca9-8d34-4a642d1ae600">
and make a screenshoot/pastebin of the console content
Screenshots
Version: v2.7.1
Additional context Add any other context about the problem here.