Description
When using the wuchale() Vite plugin during development, switching git branches causes strings from the previous branch to be marked as obsolete (#~) in .po files. This happens because the plugin retains extracted strings in memory from the previous branch and marks them obsolete when they are no longer found in the new branch's source files.
Reproduction
- Create two branches with different translatable strings in a route
- Start the dev server (
vite dev) on branch A
- Switch to branch B (
git checkout branch-b)
- Observe that
.po files now contain #~ obsolete markers for strings that only existed on branch A
Expected behavior
After a branch switch, .po files should remain unchanged (matching the git-checked-out state for the new branch). The Vite plugin should not mark strings as obsolete based on in-memory state from a previous branch.
Root cause
The Vite plugin accumulates extracted strings in memory during the session. When source files change (branch switch), it performs an incremental extraction and marks any previously-known strings that are no longer in source as obsolete. It has no way to distinguish between "string was intentionally removed" and "we switched to a different branch".
Clearing the .wuchale/ cache directory does not help because the in-memory state takes precedence over the disk cache in the running process.
Attempted workarounds
svelte-kit sync in post-checkout hook — regenerates route manifest but does not affect wuchale's in-memory state
- Clearing
.wuchale/ directory — in-memory state persists regardless of disk cache
- Touching/modifying
vite.config.ts — does not reliably trigger a Vite server restart in v8
git checkout -- *.po after switch — restores files but requires manual step after each branch switch
Proposed solutions
-
Don't mark strings obsolete in watch/dev mode (preferred) — In the Vite plugin's watch mode, only add newly discovered strings to .po files. Never mark existing strings as #~ obsolete. Marking obsolete should be a deliberate action via the CLI (wuchale command), not a side-effect of live development. Strings disappearing from source during dev could be a branch switch, a refactor in progress, etc.
-
Detect branch switches — Watch .git/HEAD for changes and reset in-memory extraction state, triggering a full re-extract from scratch.
-
Expose a reset mechanism — Provide a trigger (file-based, IPC, or API) to clear in-memory state so external tools (git hooks) can signal wuchale to start fresh.
Environment
- wuchale:
0.23.4
- vite:
8.0.13
- @sveltejs/kit:
2.58.0
- Node.js:
24.15.0
Description
When using the
wuchale()Vite plugin during development, switching git branches causes strings from the previous branch to be marked as obsolete (#~) in.pofiles. This happens because the plugin retains extracted strings in memory from the previous branch and marks them obsolete when they are no longer found in the new branch's source files.Reproduction
vite dev) on branch Agit checkout branch-b).pofiles now contain#~obsolete markers for strings that only existed on branch AExpected behavior
After a branch switch,
.pofiles should remain unchanged (matching the git-checked-out state for the new branch). The Vite plugin should not mark strings as obsolete based on in-memory state from a previous branch.Root cause
The Vite plugin accumulates extracted strings in memory during the session. When source files change (branch switch), it performs an incremental extraction and marks any previously-known strings that are no longer in source as obsolete. It has no way to distinguish between "string was intentionally removed" and "we switched to a different branch".
Clearing the
.wuchale/cache directory does not help because the in-memory state takes precedence over the disk cache in the running process.Attempted workarounds
svelte-kit syncin post-checkout hook — regenerates route manifest but does not affect wuchale's in-memory state.wuchale/directory — in-memory state persists regardless of disk cachevite.config.ts— does not reliably trigger a Vite server restart in v8git checkout -- *.poafter switch — restores files but requires manual step after each branch switchProposed solutions
Don't mark strings obsolete in watch/dev mode (preferred) — In the Vite plugin's watch mode, only add newly discovered strings to
.pofiles. Never mark existing strings as#~obsolete. Marking obsolete should be a deliberate action via the CLI (wuchalecommand), not a side-effect of live development. Strings disappearing from source during dev could be a branch switch, a refactor in progress, etc.Detect branch switches — Watch
.git/HEADfor changes and reset in-memory extraction state, triggering a full re-extract from scratch.Expose a reset mechanism — Provide a trigger (file-based, IPC, or API) to clear in-memory state so external tools (git hooks) can signal wuchale to start fresh.
Environment
0.23.48.0.132.58.024.15.0