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

style content erased #255

Closed
tipy01 opened this issue Oct 13, 2021 · 5 comments · Fixed by #256
Closed

style content erased #255

tipy01 opened this issue Oct 13, 2021 · 5 comments · Fixed by #256
Labels
bug Something isn't working

Comments

@tipy01
Copy link

tipy01 commented Oct 13, 2021

Hello,

I face a situation where the style content is erased by prettier, I tried to rearrange things in the file to find the problem cause but I definitely do not understand how it behaves.
For the moment my workaround is to avoid having a second script context="module", but I have such script in others of my files in which I did not see this problem.

The symptomatic file is in the zip archive:

sample.zip

@dummdidumm
Copy link
Member

Could you post the content of that file in here?

@cedricr
Copy link

cedricr commented Oct 14, 2021

I've got the same kind of problem here, and it's really strange....

The following file will get its <style> content stripped

<script>
  import MyFunction from "./this_is_a_long_import_path/this_is_a_long_import_name.svelte";

  // a long, and useless comment
</script>

<style>
  iframe {
    width: 100%;
  }
</style>

<svelte:head>
  <script></script>
</svelte:head>

Now if I remove anything from it, or even make the import path shorter, it won't get stripped anymore.

@tipy01
Copy link
Author

tipy01 commented Oct 14, 2021

Could you post the content of that file in here?

Actually, I tried to share the code with one of my colleague to compare using copy/paste method but sometime is not exactly the same thing that result on each editors at the end, it is the reason why I preferred to provide it as an attachment (and it is too bad that we can not attach a svelte file directly).

Regarding the strange behavior I think that it is important to have exactly the same code to compare.

dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue Oct 20, 2021
When snipping the tag contents, after replacing a match, we need to adjust the matching spans as the content length now differs. Else "is within other span" might give wrong results.
Fixes sveltejs#255
dummdidumm added a commit that referenced this issue Oct 20, 2021
When snipping the tag contents, after replacing a match, we need to adjust the matching spans as the content length now differs. Else "is within other span" might give wrong results.
Fixes #255
@dummdidumm dummdidumm added the bug Something isn't working label Oct 20, 2021
@cedricr
Copy link

cedricr commented Nov 16, 2021

Edit: I've created a new issue for it here: #261

@dummdidumm I think that was fixed at one point, but this stills happens with up to date packages.
Let me know if you'd prefer to have a new issue opened.

Repro:

$ npm init svelte@next my-app
Need to install the following packages:
  create-svelte@next
Ok to proceed? (y) 
(...)
✔ Which Svelte app template? › Skeleton project
✔ Use TypeScript? … No 
✔ Add ESLint for code linting? … No 
✔ Add Prettier for code formatting? … Yes

At this point the dev dependencies are:

  "devDependencies": {
    "@sveltejs/kit": "next",
    "prettier": "^2.4.1",
    "prettier-plugin-svelte": "^2.4.0",
    "svelte": "^3.42.6"
  },

After npm install:

$ npm list
[email protected] /Users/cr/Dora/src/my-app
├── @sveltejs/[email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Then add the file content of my previous comment: #255 (comment) to src/routes/test.svelte

Now both npx prettier --plugin-search-dir=. src/routes/test.svelte or vscode format document will reformat the file like this, losing the style content:

<script>
        import MyFunction from './this_is_a_long_import_path/this_is_a_long_import_name.svelte';

        // a long, and useless comment
</script>

<svelte:head>
        <script></script>
</svelte:head>

<style></style>

If i downgrade prettier-plugin-svelte to 2.4.0, by removing the leading version caret in package.json, followed by npm install, I then get:

$ npm list
[email protected] /Users/cr/Dora/src/my-app
├── @sveltejs/[email protected]
├── [email protected]
├── [email protected]
└── [email protected]

And this time formatting via either the cli or vscode option works as expected.

@tipy01
Copy link
Author

tipy01 commented Nov 23, 2021

For my case with prettier-plugin-svelte 2.5.0 it is fixed. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants