question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Large files getting emptied if you quit + save too fast (before Prettier runs)

See original GitHub issue

Here’s a gif with the visual keyboard open so that you can see which keys I’m pressing (slowed down)… ezgif com-gif-maker

Full speed GIF

kapture 2018-05-30 at 17 07 06


Reproduction steps:

  • Add a lot of whitespace in a large file (seems to work best with JSX but it’s also happening in files without any JSX)
  • Press CMD + S and then CMD + W. This will show the “do you want to save your file before quitting” prompt (since Prettier is still running after having pressed CMD + S). Press enter to save the file.
  • Re-open the file, it should not have been formatted.
  • Press CMD + S and then CMD + W again. This won’t show the prompt but the next time you open the file, it will be empty.

Obviously, it’s not only an issue when you add “a lot of whitespace”. It happens to me quite a lot but this is the only way I managed to reproduce it. Notice how the second time I re-open the file, it hasn‘t been formatted by Prettier after I quit it (even though I pressed Enter to save the file and formatOnSave is activated). This wasn’t an issue before so I assume there was a Prettier update (or on your side?) that would cause those problems… I haven’t changed my VS Code config or installed extensions in a while.

I would really appreciate if someone could try and reproduce! Happy to help and provide more informations if needed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
CiGitcommented, Jun 1, 2018

How it works:

  1. VSCode asks this extension to format a document.
  2. This extension (Ext) gets information it needs from the document (content, filePath, lang, …)
  3. Ext calls prettier with content and params
  4. Ext returns formatted text.

It would be interesting to have the stack trace of Cannot read property ‘read’ of null or any other stack trace you may have during your test.

It could be empty at document.getText() which is where this extension reads the content https://github.com/prettier/prettier-vscode/blob/v1.3.1/src/PrettierEditProvider.ts#L252 But I don’t know why.

Can you reproduce something like that without any extension but the default formatter ? or only this extension?

0reactions
github-actions[bot]commented, Apr 13, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Install - Prettier
First, install Prettier locally:
Read more >
Why does Prettier not format code in VS Code? - Stack Overflow
Select File -> Preferences -> Settings ( Ctrl + comma ) and search form formatter; Set Prettiers as Default formatter. enter image ...
Read more >
Linting in TypeScript using ESLint and Prettier - LogRocket Blog
Integrate Prettier with ESLint to automate type-checking in your TypeScript code and ensure that the code has no bugs.
Read more >
How to use ESLint and Prettier for code analysis and formatting
Restarting the ESLint Server ... Sometimes the linting does not work after making changes. To fix this in Visual Studio Code run the...
Read more >
CLI | Dev Cheatsheets - Michael Currin
Once installed, Prettier can be used as a CLI tool. See the Prettier CLI page of the Prettier docs for more info. File...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found