zed icon indicating copy to clipboard operation
zed copied to clipboard

Zed deletes code randomly in Svelte files

Open drwpow opened this issue 8 months ago • 6 comments

Summary

In Svelte files, code is randomly deleted

Description

When working in .svelte files, starting to type certain expressions will yield in the rest of the file being deleted from the current cursor. See example:

https://github.com/user-attachments/assets/0d095e47-0293-4613-aa70-169580fd0c09

Steps to reproduce:

It seems random. I’ve seen it happen while typing other phrases, and doesn’t seem to be limited to a specific expression, or feature of the language. Just sporadically, mid-typing, the rest of the file will disappear.

Expected Behavior: Actual Behavior:

click to expand

Extensions

The Svelte and HTML extensions are installed. Other extensions were Biome, Astro, TOML, and Catpucchin Theme which may or may not be relevant.

Logs

These are the only things in the zed log, which doesn’t seem relevant:

2025-04-27T21:09:08-06:00 INFO  [project.lsp_format] Formatting via LSP
2025-04-27T21:09:08-06:00 WARN  [project.lsp_format] Timer 'format-full' took 721µs. Which was longer than the expected limit of 0ns
2025-04-27T21:09:21-06:00 INFO  [diagnostics] Expanding to ancestor reached the top node, so using default context line count.
2025-04-27T21:09:21-06:00 INFO  [diagnostics] Expanding to ancestor reached the top node, so using default context line count.
2025-04-27T21:09:21-06:00 INFO  [diagnostics] Expanding to ancestor reached the top node, so using default context line count.
2025-04-27T21:11:53-06:00 INFO  [project.lsp_format] Formatting via LSP
2025-04-27T21:11:53-06:00 WARN  [project.lsp_format] Timer 'format-full' took 5.437625ms. Which was longer than the expected limit of 0ns

Zed Version and System Specs

Zed: v0.183.11 (Zed) OS: macOS 15.4.1 Memory: 8 GiB Architecture: aarch64

drwpow avatar Apr 28 '25 03:04 drwpow

Yeah could confirm, but it did not delete entire file, some text replaced abnormally tho.

https://github.com/user-attachments/assets/df0ad15d-79e6-461d-acc8-6acabbb6bc44

Zed: v0.183.11 (Zed) OS: Linux Wayland ubuntu 24.04 Memory: 15.3 GiB Architecture: x86_64 GPU: Intel(R) Graphics (RPL-P) || Intel open-source Mesa driver || Mesa 24.2.8-1ubuntu1~24.04.1

azvyae avatar Apr 28 '25 07:04 azvyae

Hey, thanks for reporting.

Are you able to reproduce this consistently? I know you said it happens sporadically, but does undoing then typing in the same phrase again reproduce the behavior? Or is it truly random. If you are able to reproduce it consistently, could you provide the code contents that you're able to reproduce it with?

Additionally, whether it's reproduceable or not, could you provide us with the contents of your Zed log, as well try disabling language servers, and see if you can reproduce the issue with them disabled, like so:

    "Svelte": {
      "language_servers": []
    }

probably-neb avatar Apr 28 '25 14:04 probably-neb

Are you able to reproduce this consistently? I know you said it happens sporadically, but does undoing then typing in the same phrase again reproduce the behavior?

Oh yes it does! In a .svelte file, typing any square brackets in <script> almost anywhere reproduces the behavior.

Additionally, whether it's reproduceable or not, could you provide us with the contents of your Zed log,

For some reason I checked the logs the first time, and didn’t see anything standing out (I didn’t realize the <details> was inside an HTML comment; fixed so now it’s visible). But now I do see some interesting failures:

Zed Log
2025-04-28T09:40:57-06:00 INFO  [lsp] starting language server process. binary path: "/Users/drew/Library/Application Support/Zed/extensions/work/biome/node_modules/@biomejs/cli-darwin-arm64/biome", working directory: "/Users/drew/.config/zed", args: ["lsp-proxy"]
2025-04-28T09:40:58-06:00 INFO  [lsp] Language server with id 3 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/drew/Sites/drwpow/vipper/packages/vipper/src/lib/index.ts"
  }
}
2025-04-28T09:40:58-06:00 INFO  [lsp] Language server with id 3 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/drew/Sites/drwpow/vipper/packages/compendium/src/lib/index.ts"
  }
}
2025-04-28T09:40:58-06:00 INFO  [lsp] Language server with id 3 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/drew/Sites/drwpow/vipper/packages/compendium/src/components/component-matrix.svelte"
  }
}
2025-04-28T09:40:58-06:00 INFO  [lsp] Language server with id 3 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/drew/Sites/drwpow/vipper/packages/compendium/src/routes/+page.svelte"
  }
}
2025-04-28T09:40:58-06:00 INFO  [lsp] Language server with id 3 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/drew/Sites/drwpow/vipper/packages/vipper/dist/index.js"
  }
}

It is correct that I’m not using ESLint in my project (I’m using Biome)

as well try disabling language servers,

Ooh that does seem to fix the behavior! So it does seem related to Svelte’s language server, or something.

drwpow avatar Apr 28 '25 15:04 drwpow

I'm not able to reproduce this on main or on v0.183.11. If it's still happening for you, is there a way you could provide a minimal reproduction for this? The default SvelteKit app works just fine for me: https://svelte.dev/docs/kit/creating-a-project.

smitbarmase avatar May 12 '25 14:05 smitbarmase

@smitbarmase Yeah! Made a quick repro here: https://github.com/drwpow/zed-svelte-bug-repro. See the README for instructions.

What’s interesting is I’m still getting the error, but after poking at it more, there seems to be some level of complexity needed. I.e. If I just type out:

let foo = []

It handles that fine. So the nested structure of arrays & objects does seem to be significant here, and I’m not sure why.

drwpow avatar May 12 '25 15:05 drwpow

Thank you for your quick response. I'm still not able to reproduce this. Can you verify:

  1. What Zed version are you using? I'm on Zed Preview 0.186.6.

  2. What eslint, vtsls, typescript, and svelte extension versions are you using?

    • eslint: /Users/smit/Library/Application Support/Zed/languages/eslint/vscode-eslint-2.4.4
    • typescript and vtsls: (from /Users/smit/Library/Application Support/Zed/languages/vtsls/package.json)
    {
      "dependencies": {
        "@vtsls/language-server": "0.2.8",
        "typescript": "5.8.3"
      }
    }
    
    • svelte: 0.2.7 (from: /Users/smit/Library/Application Support/Zed/extensions/installed/svelte/extension.toml)
  3. Try commenting any additional settings you might have just to verify if this is some kind of edge case or default behavior?

Here is how it looks for me:

https://github.com/user-attachments/assets/a7114f9d-459f-4ef2-b869-f4dd8e6a6fe1

smitbarmase avatar May 12 '25 15:05 smitbarmase

  1. What Zed version are you using? Posted above — v0.183.11 in original message. But it’s auto-updated since original message and I still see it on v0.186.10.
  2. What eslint, vtsls, typescript, and svelte extension versions are you using?
  • eslint: 2.4.4
  • typescript and vtsls: 5.8.3 and 0.2.8
  • svelte: 0.2.7
  • biome: 0.1.5 ← This was the problem! Not Svelte
  1. Try commenting any additional settings you might have just to verify if this is some kind of edge case or default behavior?

    Turns out wasn’t a setting! It was the Biome Zed extension. But what’s weird is it only breaks on Svelte files, nothing else, so I didn’t suspect it! With that disabled, I have no issues.

drwpow avatar May 20 '25 05:05 drwpow

Hey figured what's going on, looks like the issue is with the Biome language server's textDocument/onTypeFormatting request that fires after closing brackets. They've fixed this in Beta 4, so updating your project's Biome should fix it. More: https://github.com/biomejs/biome-zed/issues/105. Closing this as resolved. Thanks for the report. cc @gianpaj @drwpow

smitbarmase avatar May 20 '25 12:05 smitbarmase

I'm still getting this error, after starting a fresh project and with latest versions, following this guide: https://biomejs.dev/reference/zed/

 Configuration: {
  "biome": {
    "configurationPath": "~/project/biome.json",
    "requireConfiguration": true
  }
./node_modules/@biomejs/biome/bin/biome --version
Version: 2.3.2
  • Zed 0.209.7
  • Biome extension: 0.2.2

I have this .svelte file:

<script lang="ts">
   import "../app.css";
   import favicon from "$lib/assets/favicon.svg";

   let { children } = $props();
</script>

<svelte:head>
   <link rel="icon" href={favicon} />
</svelte:head>

{@render children?.()}

And after formatting everything gets removed:

	import "../app.css";
	import favicon from "$lib/assets/favicon.svg";

	let { children } = $props();

phoenisx avatar Oct 29 '25 10:10 phoenisx

@phoenisx Can you open a new issue to track this? I want to keep that thread separate from this one since the root issue might be different from the original.

smitbarmase avatar Nov 03 '25 08:11 smitbarmase