Skip to content

Vite plugin marks strings as obsolete after git branch switch (stale in-memory state) #376

@Stadly

Description

@Stadly

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

  1. Create two branches with different translatable strings in a route
  2. Start the dev server (vite dev) on branch A
  3. Switch to branch B (git checkout branch-b)
  4. 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

  1. 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.

  2. Detect branch switches — Watch .git/HEAD for changes and reset in-memory extraction state, triggering a full re-extract from scratch.

  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions