Skip to content

CLDXiang/svelte-custom-element-host-bug

Repository files navigation

Reproduce Svelte $host() rune bug

This is a reproduction of the bug of Svelte's $host() rune:

If you assign $host() to a variable, the assignment statement will be removed after compilation.

source

MyElement.svelte

function fail(greeting: string) {
  const element = $host() as HTMLElement;
  element.dispatchEvent(
  new CustomEvent('greeting', { detail: greeting })
  );
}

after compilation

components.iife.js

function fail(greeting) {
  element.dispatchEvent(new CustomEvent("greeting", { detail: greeting }));
}

Which will throw ReferenceError: element is not defined in runtime.

About

Reproduce Svelte bug related to $host() rune

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published