-
-
Notifications
You must be signed in to change notification settings - Fork 62
Fix HMR not triggering for additional translation paths #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aqu1les
wants to merge
1
commit into
xiCO2k:main
Choose a base branch
from
aqu1les:fix/hot-reload-additional-translations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Escape special regex characters in path strings.
The path strings are inserted directly into the RegExp constructor without escaping. If any path contains special regex metacharacters (e.g.,
.,\,[,],(,), etc.), they will be interpreted as regex syntax rather than literal characters, causing incorrect matching behavior.For example:
C:\Users\Project\lang\contain backslasheslang.backupwould matchlangXbackupdue to the unescaped.Apply this diff to escape regex special characters:
Alternatively, for better readability, you could extract a helper function:
🤖 Prompt for AI Agents
🧩 Analysis chain
Verify path matching behavior with absolute paths and path separators.
The implementation needs verification for several path-handling concerns:
ctx.file format: Vite's
ctx.fileis typically an absolute path. Ensure the pattern matching works correctly with absolute paths fromctx.file.Path separator consistency:
langPathhas a trailingpath.sepappended at line 10, but elements inadditionalLangPathsmay not. This inconsistency could cause:langpattern would matchlang-backup/file.php)Test coverage: Verify the fix works with:
langPathdirectoryadditionalLangPathsdirectoriesRun the following script to check how
ctx.fileis used in similar Vite plugins:Consider normalizing all paths consistently:
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1107
🏁 Script executed:
Length of output: 1923
🏁 Script executed:
Length of output: 954
🏁 Script executed:
Length of output: 110
🏁 Script executed:
Length of output: 59
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 329
🌐 Web query:
💡 Result:
ctx.file is a filesystem path pointing to the changed file — it is an absolute path (you usually call path.relative(root, ctx.file) or normalizePath on it when you need a project-relative or POSIX-normalized path). [1][2]
Sources:
Fix path normalization and absolute path matching in handleHotUpdate.
Critical issues found during verification:
Absolute path mismatch:
ctx.fileis an absolute path (e.g.,/home/user/project/resources/lang/en.php), but the regex pattern uses relative paths likelang/.*\.php$. This pattern will never match because the absolute path contains the full directory structure.Path separator inconsistency:
langPathis normalized withpath.sepat line 10, butadditionalLangPathsare not. This causes:langPathpattern:lang/.*\.php$(correct boundary)additionalLangPathspattern:extra.*\.php$(matchesextra-dir/file.phpunintentionally)Missing normalization:
additionalLangPathsmust be normalized the same way aslangPathbefore use in the regex at line 57.Required fixes:
ctx.filepath.resolve()to convert relative paths to absolute, or usepath.relative(root, ctx.file)to convertctx.fileto project-relative for matchingExample correction:
Or use
path.relative()for more robust matching against the absolutectx.file.🤖 Prompt for AI Agents