Skip to content

Svelte 5: $host() assignment statement will be removed after compilation #13121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CLDXiang opened this issue Sep 4, 2024 · 0 comments · Fixed by #13127
Closed

Svelte 5: $host() assignment statement will be removed after compilation #13121

CLDXiang opened this issue Sep 4, 2024 · 0 comments · Fixed by #13127
Assignees
Labels
Milestone

Comments

@CLDXiang
Copy link

CLDXiang commented Sep 4, 2024

Describe the bug

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

Reproduction

https://github.com/CLDXiang/svelte-custom-element-host-bug

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

Compilation output:

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

var element = $$props.$$host is missing.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 16.67 GB / 31.85 GB
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.9.0 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: 5.0.0-next.243 => 5.0.0-next.243

Severity

annoyance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants