Modified `wxt.config` via `wxt.hook` is reset on dev reloaded
Describe the bug
There is a bug that causes wxt.config modified via hook to be reset. I'm modifying the outDir, but the path is broken. The path is correct at startup dev, but the reset when the HMR reloads. This is causing content-script to not reload.
It can be reproduced with the example of separating outDir from dev and prod written in docs - https://wxt.dev/guide/go-further/reusable-modules.html#actually-doing-something.
This is similar to this #863 . Perhaps the cause may be the same.
Reproduction
https://github.com/wxt-dev/wxt/compare/main...1natsu172:repro-weired-ourDir-path
Steps to reproduce
cd packages/wxt-demo
pnpm dev
# save something content-script file.
System Info
System:
OS: macOS 14.6.1
CPU: (8) arm64 Apple M1
Memory: 178.72 MB / 8.00 GB
Shell: 3.7.0 - /opt/homebrew/bin/fish
Binaries:
Node: 22.7.0 - ~/.asdf/installs/nodejs/22.7.0/bin/node
npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 9.6.0 - ~/.asdf/installs/nodejs/22.7.0/bin/pnpm
bun: 1.1.25 - ~/.asdf/shims/bun
Watchman: 2024.04.22.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 111.1.49.120
Chrome: 128.0.6613.85
Safari: 17.6
npmPackages:
wxt: workspace:* => 0.19.7
Used Package Manager
pnpm
Validations
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
I think there is probably the cause. The reloadConfig is being called, but resolveConfig is executed in the context before the hook.
https://github.com/wxt-dev/wxt/blob/24cd01dd31e0a5bdd130d2c895efe3dece09ab66/packages/wxt/src/core/wxt.ts#L46-L48
https://github.com/wxt-dev/wxt/blob/24cd01dd31e0a5bdd130d2c895efe3dece09ab66/packages/wxt/src/core/wxt.ts#L66-L68
Duplicate of #857. Keep this open because I like your description more. Need to think more of how exactly to solve this problem. Maybe add a new hook and make people modify config in that hook instead.
Right, if you don't change the whole core design, a dedicated hook might be a good low-cost idea. It would be easy to understand for people.
Released in v0.19.17