Skip to content

fix(theme): ignore atomic-write tmp files in the theme dev watcher#7870

Merged
isaacroldan merged 6 commits into
Shopify:mainfrom
andershagbard:fix/ignore-editor-tmp-files-in-theme-watcher
Jul 6, 2026
Merged

fix(theme): ignore atomic-write tmp files in the theme dev watcher#7870
isaacroldan merged 6 commits into
Shopify:mainfrom
andershagbard:fix/ignore-editor-tmp-files-in-theme-watcher

Conversation

@andershagbard

@andershagbard andershagbard commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

This is an error which happens because Claude Code generates these tmp files. Not sure if other tools use the same method or naming.

  • Editor tools (including AI coding assistants) create temporary files like blocks/foo.liquid.tmp.93809.4dbd82e0b95a during atomic save operations and delete them within milliseconds.
  • Because the per-event debounce fires independently for add and unlink events, the file watcher sees the add, tries to upload the invalid asset key to Shopify, and crashes shopify theme dev — requiring a manual restart.
  • Adds **/*.tmp.* to DEFAULT_IGNORE_PATTERNS so chokidar never emits events for these files.

Root cause

queueFsEvent debounces per ${fileKey}:${eventName}, meaning add and unlink are queued separately. By the time the 250ms debounce fires for add, the file is already gone — but Shopify still gets the upload attempt with an invalid key.

Test plan

  • New unit test asserting **/*.tmp.* is present in chokidar's ignored option
  • All 44 existing theme-fs tests pass
  • Type-check passes
  • Lint passes

🤖 Generated with Claude Code

Editor tools (including AI coding assistants) create temporary files like
`blocks/foo.liquid.tmp.93809.4dbd82e0b95a` during atomic save operations,
then delete them within milliseconds. Because the per-event debounce fires
independently for `add` and `unlink`, Shopify's file watcher sees the add
event, attempts to upload the invalid asset key, and crashes the dev server.

Adding `**/*.tmp.*` to `DEFAULT_IGNORE_PATTERNS` prevents chokidar from
emitting events for these files entirely.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@andershagbard andershagbard marked this pull request as ready for review June 19, 2026 15:48
@andershagbard andershagbard requested review from a team as code owners June 19, 2026 15:48
Comment thread packages/theme/src/cli/constants.ts Outdated
'**/config.yml',
'**/node_modules/',
'.prettierrc.json',
'**/*.tmp.*', // Atomic-write temp files (e.g. blocks/foo.liquid.tmp.93809.4dbd82e0b95a)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @andershagbard. We're just having a discussion internally here because there are going to be themes that already contain files with .tmp. in the name that this would break.

The purpose behind the PR makes sense but we need to think of how to make sure our fix doesn't break existing themes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because the devserver will crash because the API doesn't accept that file name. I assume it's blocked serverside, and therefore these files would not exist?

@andershagbard andershagbard Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong, but I think this can be enforced in all folders except assets.

I am getting these errors in the theme editor:

FileSaveError: Must have a .liquid file extension

FileSaveError: "sections/test.json.tmp.1231231" contains illegal characters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right that files like sections/test.json.tmp.1231231 are not valid theme files and won’t be accepted server-side.

The piece I’m worried about is the breadth of **/*.tmp.*. DEFAULT_IGNORE_PATTERNS is used for the initial file glob too, so this can hide real files (e.g. snippets/test.tmp.liquid).

Maybe we can narrow this to non-asset theme folders and only ignore files where the temp suffix is appended after a valid extension?

[
  '**/blocks/**/*.liquid.tmp.*',
  '**/layout/**/*.liquid.tmp.*',
  '**/snippets/**/*.liquid.tmp.*',
  '**/config/**/*.json.tmp.*',
  '**/locales/**/*.json.tmp.*',
  '**/sections/**/*.{liquid,json}.tmp.*',
  '**/templates/**/*.{liquid,json}.tmp.*',
]

That should catch sections/test.json.tmp.1231231 and blocks/foo.liquid.tmp.93809.4dbd82e0b95a, but not ignore valid files like snippets/test.tmp.liquid or any legitimate assets/* files.

As a personal workaround for now you could also add the following to your .shopifyignore:

/\.tmp\.[0-9]+(\.[0-9a-fA-F]+)?$/

Replace the broad `**/*.tmp.*` glob with directory-specific patterns
scoped to the theme file types that actually use atomic writes.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
graygilmore
graygilmore previously approved these changes Jun 24, 2026
Comment thread packages/theme/src/cli/constants.ts Outdated
Comment thread packages/theme/src/cli/utilities/theme-fs.test.ts Outdated
@graygilmore graygilmore dismissed their stale review June 24, 2026 22:29

Meant to just comment

andershagbard and others added 2 commits June 25, 2026 07:58
Co-authored-by: Gray Gilmore <graygilmore@gmail.com>
@isaacroldan isaacroldan added this pull request to the merge queue Jul 6, 2026
Merged via the queue into Shopify:main with commit 7d9e260 Jul 6, 2026
27 checks passed
@andershagbard andershagbard deleted the fix/ignore-editor-tmp-files-in-theme-watcher branch July 6, 2026 08:49
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.

3 participants