Skip to content

Fix cache not invalidated when files are ignored or restored#18029

Merged
fisker merged 3 commits into
prettier:mainfrom
kovsu:fix-#18016
Jun 27, 2026
Merged

Fix cache not invalidated when files are ignored or restored#18029
fisker merged 3 commits into
prettier:mainfrom
kovsu:fix-#18016

Conversation

@kovsu

@kovsu kovsu commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Description

fix: #18016

After:

CleanShot.2025-10-10.at.16.51.22.mp4

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2025

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-hermes@18029.tgz
yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-oxc@18029.tgz
yarn add https://pkg.pr.new/prettier/prettier@18029.tgz

commit: 386bfb6

@netlify

netlify Bot commented Oct 10, 2025

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 386bfb6
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/691a89a1d2b1df00081f5fb4
😎 Deploy Preview https://deploy-preview-18029--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@fisker

fisker commented Oct 11, 2025

Copy link
Copy Markdown
Member

I think the bug can be fixed by removing the initial value of shouldSetCache

- let shouldSetCache = !isDifferent;
+ let shouldSetCache = false;

Will it work?

Also, we need tests for this case.

@kovsu

kovsu commented Oct 12, 2025

Copy link
Copy Markdown
Contributor Author

Will it work?

It seems don't work. If the file is ignored, it gets an early return.

  const isFileIgnored = isIgnored(filename);
  if (
    isFileIgnored &&
    (context.argv.debugCheck ||
      context.argv.write ||
      context.argv.check ||
      context.argv.listDifferent)
  ) {
    continue;
 }

@fisker fisker added this to the 3.7 milestone Oct 16, 2025
@fisker fisker self-requested a review October 16, 2025 20:19
@fisker

fisker commented Nov 16, 2025

Copy link
Copy Markdown
Member

Hello @kovsu , sorry for the long delay.

Do you know why we need removeFormatResultsCache? Shouldn't the file hash mismatch on the second run?

For example:

If I run prettier foo.js bar.js --no-single-quote --write, we will cache result for both foo.js and bar.js. Then I run prettier foo.js --single-quote --write, will we remove the cache for bar.js?

This really doesn't make sense to me, since each command can even have a different cache location.

@fisker fisker modified the milestones: 3.7, 3.8 Nov 26, 2025
@nikwotton

Copy link
Copy Markdown

It looks like there's been no action on this PR since November - is it dead? Is there a different fix for #18016 somewhere?

@fisker

fisker commented Jun 8, 2026

Copy link
Copy Markdown
Member

Maybe caused by jaredwray/cacheable#1648?

@kovsu

kovsu commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Maybe caused by jaredwray/cacheable#1648?

Yes, I will confirm this when it publish the new version.

@fisker

fisker commented Jun 27, 2026

Copy link
Copy Markdown
Member

jaredwray/cacheable#1648 won't get released in time, I'll merge this and release v3.9 and revisit later.

@fisker fisker merged commit fe040ae into prettier:main Jun 27, 2026
35 checks passed
@fisker fisker mentioned this pull request Jun 27, 2026
6 tasks
@kovsu kovsu deleted the fix-#18016 branch June 27, 2026 16:17
@fisker

fisker commented Jun 27, 2026

Copy link
Copy Markdown
Member

@kovsu https://github.com/jaredwray/cacheable/releases/tag/2026-06-27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cache issue] Prettier does not recheck files which used to be in .prettierignore

3 participants