Skip to content

fix: file reloading mechanism and add profile watch ignores#2112

Merged
aklinker1 merged 16 commits into
wxt-dev:mainfrom
ZerGo0:fix/dev-watch-missed-reloads
Jun 30, 2026
Merged

fix: file reloading mechanism and add profile watch ignores#2112
aklinker1 merged 16 commits into
wxt-dev:mainfrom
ZerGo0:fix/dev-watch-missed-reloads

Conversation

@ZerGo0

@ZerGo0 ZerGo0 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes flaky dev reload detection where WXT sometimes ignores real source file saves.

Root cause:

  • Dev watcher used a debounced callback (leading: true, trailing: false) and queued events inside that callback.
  • With noisy filesystem activity (especially browser profile/cache files), relevant source change events could be dropped.

Changes:

  • Reworked dev file reload flow in packages/wxt/src/core/create-server.ts to:
    • queue every watcher event immediately
    • process the queue in a serialized loop
    • keep flushing after each debounce window until no new events arrive
  • Added runner profile watch ignores in packages/wxt/src/core/builders/vite/index.ts so browser profile churn is not watched:
    • chromiumProfile
    • firefoxProfile
    • chromiumArgs --user-data-dir (split and = forms)
    • firefoxArgs -profile (split and = forms)
  • Added a single regression test:
    • packages/wxt/src/core/__tests__/create-server.test.ts
    • Simulates browser-profile noise event followed by real source change and verifies the source change is detected/reloaded.

Manual Testing

This is pretty hard/annoying to reproduce. The new test is probably the best way of reproducing this: pnpm -C packages/wxt test --run src/core/__tests__/create-server.test.ts

  1. Use a project with browser profile inside project dir (example):
    • Chromium: chromiumArgs: ['--user-data-dir=./private/.dev-profile']
    • Firefox: firefoxProfile: './private/.dev-firefox-profile'
    • My main project does a ton of stuff in indexed dbs, this causes a ton of changes in the browser profile directory
  2. Run pnpm wxt.
  3. Save a real source file while browser is active.
  4. A rebuild should be triggered, but it just doesn't sometimes.

Related Issue

None I think.

- Exported `createFileReloader` function to allow external usage.
- Improved the file reloading process by implementing a queue worker to handle multiple file changes without dropping events.
- Added `getRunnerProfileWatchIgnores` function to dynamically generate ignored paths based on user profiles for Chromium and Firefox.
- Updated Vite builder configuration to include these new ignore patterns.
@netlify

netlify Bot commented Feb 11, 2026

Copy link
Copy Markdown

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit a3c33f6
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6a44224058a32b00082f8847
😎 Deploy Preview https://deploy-preview-2112--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, I really like these changes!

I just woke up and am on mobile, so I'll need to do some manual testing to make sure everything is working later today.

@pkg-pr-new

pkg-pr-new Bot commented Feb 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@2112

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@2112

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@2112

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@2112

@wxt-dev/is-background

npm i https://pkg.pr.new/@wxt-dev/is-background@2112

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@2112

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@2112

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@2112

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@2112

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@2112

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@2112

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@2112

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@2112

wxt

npm i https://pkg.pr.new/wxt@2112

commit: a3c33f6

@codecov

codecov Bot commented Feb 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.70175% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.35%. Comparing base (d3983a6) to head (a3c33f6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/wxt/src/core/builders/vite/index.ts 37.50% 11 Missing and 4 partials ⚠️
...ackages/wxt/src/core/utils/create-file-reloader.ts 90.90% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2112      +/-   ##
==========================================
+ Coverage   78.81%   79.35%   +0.53%     
==========================================
  Files         134      134              
  Lines        3918     4005      +87     
  Branches      891      910      +19     
==========================================
+ Hits         3088     3178      +90     
+ Misses        741      737       -4     
- Partials       89       90       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Introduced `getRelevantDevChangedFiles` to filter out unrelated file changes.
- Updated `detectDevChanges` to utilize the new filtering function for improved accuracy.
- Modified `createFileReloader` to work with relevant file changes, ensuring only necessary reloads occur.
- Enhanced tests to validate the new behavior and ensure proper handling of HTML-only reloads.
@ZerGo0

ZerGo0 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

I pushed another small change. I don't really like the changes in 0cf79bb but I can't really think of a better way of doing this.

The problem is that it would show potentially wrong files in the "Changed: ..." log line and so on because they all use the "raw"/unfiltered queue. My latest commit fixes that.

@PatrykKuniczak

Copy link
Copy Markdown
Collaborator

I'm also have 1 file on which HMR doesn't work and i was about to report it, but i'll check it on your branch, maybe your PR will solve that issue 😄

Comment thread packages/wxt/src/core/builders/vite/index.ts

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested, things seem to behave the same way for me. One requested change.

Comment thread packages/wxt/src/core/create-server.ts Outdated
Move createFileReloader into an internal core utils file and update create-server/test imports.
- Exported `createFileReloader` function to allow external usage.
- Improved the file reloading process by implementing a queue worker to handle multiple file changes without dropping events.
- Added `getRunnerProfileWatchIgnores` function to dynamically generate ignored paths based on user profiles for Chromium and Firefox.
- Updated Vite builder configuration to include these new ignore patterns.
- Introduced `getRelevantDevChangedFiles` to filter out unrelated file changes.
- Updated `detectDevChanges` to utilize the new filtering function for improved accuracy.
- Modified `createFileReloader` to work with relevant file changes, ensuring only necessary reloads occur.
- Enhanced tests to validate the new behavior and ensure proper handling of HTML-only reloads.
Move createFileReloader into an internal core utils file and update create-server/test imports.
@PatrykKuniczak PatrykKuniczak force-pushed the fix/dev-watch-missed-reloads branch from 41b2084 to 9e4d40d Compare February 14, 2026 09:09
@PatrykKuniczak

Copy link
Copy Markdown
Collaborator

it's working for Windows also, but it doesn't solve my issue, i'll open new issue about it.

Comment thread packages/wxt/src/core/utils/create-file-reloader.ts Outdated
- detect entrypoint directory file events that are missed by step-based dev change detection and treat them as rebuild candidates.
- recompute and merge latest entrypoint groups on file changes so new entrypoints are built immediately instead of waiting for a dev server restart.
- reload the extension when new entrypoints are introduced to keep manifest/runtime behavior in sync.
- add and update `createFileReloader` tests to cover noisy events and newly added entrypoint files.
Comment thread packages/wxt/src/core/utils/create-file-reloader.ts Outdated
@PatrykKuniczak

Copy link
Copy Markdown
Collaborator

@aklinker1 This one also, needs your review

): string[] {
const root = normalizePath(wxtConfig.root);
const chromiumArgProfiles = extractPathArgs(
wxtConfig.runnerConfig.config?.chromiumArgs,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I'm working on adding an alternative runner in the next major version and hardcoding access to one of the runner's config will prevent me from abstracting it.

It works for now like this, but we'll likely have to add a hook for this in the future...

Just thinking out loud, no changes here.

Comment thread packages/wxt/src/core/builders/vite/index.ts
Comment thread packages/wxt/src/core/create-server.ts Outdated
@@ -1,35 +1,15 @@
import { debounce } from 'perfect-debounce';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we remove this dependency?

Comment thread packages/wxt/src/core/utils/create-file-reloader.ts
Comment thread packages/wxt/src/core/utils/__tests__/create-file-reloader.test.ts
@ZerGo0

ZerGo0 commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@aklinker1 I can do a clean PR if you want?

(This issue is super frustrating tbh, 1/20 file saves trigger a rebuild/reload for me right now for me. It's usually faster to just stop and start the dev command ^^)

@aklinker1

aklinker1 commented Apr 27, 2026

Copy link
Copy Markdown
Member

Yeah, resolve the conflicts and I'll finish reviewing it.

ZerGo0 added 2 commits April 29, 2026 09:23
…d-reloads

# Conflicts:
#	packages/wxt/src/core/builders/vite/index.ts
#	packages/wxt/src/core/utils/create-file-reloader.ts
@ZerGo0 ZerGo0 requested a review from aklinker1 April 29, 2026 07:42
expect(server.reloadExtension).toBeCalledTimes(1);
});

it('should rebuild and reload extension when a new entrypoint is added', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed you resolved that TODO, thanks!

Comment thread packages/wxt/src/core/utils/create-file-reloader.ts Outdated
@ZerGo0 ZerGo0 requested a review from aklinker1 April 30, 2026 06:57

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some type errors causing CI to fail, the no-reload case is still not handled properly, it runs the final else block and tries to reload content scripts

@ZerGo0 ZerGo0 requested a review from aklinker1 May 19, 2026 08:01

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay on this, merging now!

@aklinker1 aklinker1 enabled auto-merge (squash) June 30, 2026 20:05
@aklinker1 aklinker1 merged commit 82825a5 into wxt-dev:main Jun 30, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for helping make WXT better!

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