Repository navigation
fix: respect absolute paths in handleHotUpdate - #33
Merged
rosskevin merged 1 commit intoJun 3, 2026
Merged
Conversation
`path.join(cwd, absolutePath)` does not strip the absolute prefix (unlike `path.resolve`); it just concatenates with a separator. When the consumer passes an absolute path to `paths`, the join produces a non-existent path like `<cwd>/Users/.../resources`, so `file.startsWith(...)` is always false and the virtual module is never reloaded. Fix: only prepend cwd when the configured path is not already absolute. Adds tests covering absolute paths, relative paths, non-locale files, and files outside the configured paths.
Member
|
@kainstar I'm sorry I missed this notification! Thank you |
Member
|
I'll fix the release, I need to do a little tooling maintenance. Should be out soon. |
Member
|
Released in v4.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
handleHotUpdatenever reloads the virtual module whenpathscontains an absolute path.The current check is:
path.join(unlikepath.resolve) does not strip an absolute prefix from its later arguments — it just concatenates with a separator:So when a consumer passes an absolute path (very common — e.g.
path.resolve(__dirname, '../resources')in a monorepo where cwd ≠ the project root), the join produces a path no real file starts with, the predicate is alwaysfalse, and HMR for locale files silently does nothing.This is independent of any Vite version —
handleHotUpdate({ file })has been absolute since Vite 3.Fix
Only join with
process.cwd()when the configured path is relative; pass absolute paths through as-is.Tests
Adds
src/__tests__/handleHotUpdate.test.tscovering:paths→ reloadModule is called (regression test for this bug)paths(relative to cwd) → reloadModule is calledAll 18 tests pass.
How to reproduce the original bug
In any project where the plugin is configured with an absolute path:
Edit any locale YAML/JSON and observe that the virtual module is never reloaded; you have to restart Vite to see changes.