Skip to content
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

🐛 BUG: Astro import duplication bug #928

Closed
Zyruks opened this issue Aug 4, 2024 · 10 comments · Fixed by #929
Closed

🐛 BUG: Astro import duplication bug #928

Zyruks opened this issue Aug 4, 2024 · 10 comments · Fixed by #929
Assignees
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) regression

Comments

@Zyruks
Copy link

Zyruks commented Aug 4, 2024

Describe the Bug

When enabling organizeImports in VSCode settings, saving a file in an Astro project duplicates the import statements, especially when using import aliases defined in tsconfig.json. This issue occurs in Astro v2.13.1 and v2.13.0 but not in v2.12.8.

Environment:

  • OS: Windows 11 using WSL 2 with Ubuntu
  • Astro version: v2.13.1 and v2.13.0
  • VSCode version: 1.92.0 (system setup)
  • Commit: b1c0a14de1414fcdaa400695b4db1c0799bc3124
  • Date: 2024-07-31T23:26:45.634Z
  • Electron: 30.1.2
  • ElectronBuildId: 9870757
  • Chromium: 124.0.6367.243
  • Node.js: 20.14.0
  • V8: 12.4.254.20-electron.0
  • VSCode extensions: astro-build.astro-vscode

Additional Context:
Disabling organizeImports resolves the issue temporarily. Reverting to version 2.12.8 resolves the issue as well.

.vscode/settings.json
image

Bug in Action:

Code_Vl3LKhcC7n.mp4

If you need more information or further details, please let me know.

Steps to Reproduce

  1. Install Astro v2.13.1 or v2.13.0.
  2. Enable organizeImports in the VSCode settings.
  3. Define import aliases in tsconfig.json (e.g., @components, @layouts).
  4. Create a file with multiple import statements using these aliases.
  5. Save the file.
  6. Observe the duplicated import statements.

Expected Behavior

The import statements should not be duplicated upon saving.

Actual Behavior

Import statements are duplicated upon saving the file, particularly when using import aliases from tsconfig.json.

Link to Minimal Reproducible Example

https://github.com/Zyruks/astro-import-duplication-bug

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 4, 2024
@Princesseuh
Copy link
Member

I cannot seem to be able to reproduce this, and I'm not sure why that version would introduce that issue, but I'll take a look!

@Princesseuh Princesseuh added needs investigation The cause of the issue is unknown and a deeper investigation is needed to fix it and removed needs triage Issue needs to be triaged labels Aug 4, 2024
@Zyruks
Copy link
Author

Zyruks commented Aug 4, 2024

I have disabled all extensions, but the problem persists. You can try to reproduce the issue using the repository I uploaded.

Link to Repo

Code_nxBOOpSuR3.mp4

@Princesseuh
Copy link
Member

Even with your repo, I cannot reproduce the issue. There's probably something else at play here, maybe Windows etc.

@Zyruks
Copy link
Author

Zyruks commented Aug 4, 2024

Well, if I can help or try anything else, just let me know.

@MattheousDT
Copy link

Can confirm this is also happening to me on Windows on all Astro repositories when I have organizeImports turned on. Reverting back to 2.12.8 likewise fixed the issue

@Princesseuh
Copy link
Member

Princesseuh commented Aug 6, 2024

So far I have absolutely no idea what could cause this, the only difference between those two versions is the SCSS and LESS support, which should be totally unrelated to the frontmatter 🤔 I can confirm that I can reproduce on Windows, though.

@Princesseuh Princesseuh added - P4: important Violate documented behavior or significantly improves performance (priority) and removed needs investigation The cause of the issue is unknown and a deeper investigation is needed to fix it labels Aug 6, 2024
@Princesseuh Princesseuh self-assigned this Aug 6, 2024
@Princesseuh
Copy link
Member

@Zyruks @MattheousDT Does this still happen to you after the update?

@Zyruks
Copy link
Author

Zyruks commented Aug 13, 2024

Still happening
image

Code_aXFZSXiVXn.mp4

@Princesseuh

@Princesseuh
Copy link
Member

Yep, just figured out what's the reason. Working on a fix now! It only affects CRLF files, so at least it's possible to use LF as a workaround until a fix is released. Apologies for the inconvenience.

@Princesseuh
Copy link
Member

It should be fixed in the last version, apologies for the delay, issue ended up being a bit complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants