wxt icon indicating copy to clipboard operation
wxt copied to clipboard

Modified `wxt.config` via `wxt.hook` is reset on dev reloaded

Open 1natsu172 opened this issue 1 year ago • 3 comments

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.

image

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

1natsu172 avatar Aug 28 '24 15:08 1natsu172

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

1natsu172 avatar Aug 28 '24 15:08 1natsu172

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.

aklinker1 avatar Aug 28 '24 16:08 aklinker1

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.

1natsu172 avatar Aug 28 '24 17:08 1natsu172

Released in v0.19.17

aklinker1 avatar Nov 28 '24 14:11 aklinker1