Conversation
This commit refactors the next-intl hook extraction logic to correctly handle existing hooks and aliases. It also updates tests to reflect these changes. Co-authored-by: jan <jan@amann.work>
|
Cursor Agent can help with this pull request. Just |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
useTranslations import for useExtracted
Co-authored-by: jan <jan@amann.work>
This change renames the extracted hooks `useTranslations` and `getTranslations` to `useTranslations$1` and `getTranslations$1` respectively. This prevents naming conflicts when the original hooks are also imported and used in the same scope. Co-authored-by: jan <jan@amann.work>
Co-authored-by: jan <jan@amann.work>
Co-authored-by: jan <jan@amann.work>
amannn
commented
Dec 3, 2025
| fn local_name(self) -> swc_atoms::Atom { | ||
| match self { | ||
| HookType::UseTranslation => "useTranslations$1".into(), | ||
| HookType::GetTranslation => "getTranslations$1".into(), |
Owner
Author
There was a problem hiding this comment.
I had an idea about using useExtracted here instead, but Bugbot made a valid point here: #2153 (comment)
useTranslations import for useExtracteduseTranslations import for useExtracted
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.
Fix duplicate
useTranslationsimports generated by the SWC plugin.The SWC plugin previously generated duplicate imports (e.g.,
import { useTranslations, useTranslations } from 'next-intl';) when bothuseExtractedanduseTranslationswere present. This fix ensures that if the target translation hook (useTranslationsorgetTranslations) is already imported, theuseExtracted/getExtractedimport is removed, and all transformed calls reuse the existing hook's local name.Note
Rewrites useExtracted/getExtracted imports to aliased real hooks and updates call sites to use unique local aliases, preventing duplicate useTranslations/getTranslations imports; adds/updates tests.
HookType::{extracted_name,target_name,local_name}for consistent mapping.useExtracted/getExtractedto target hooks (useTranslations/getTranslations) with unique local aliases (e.g.,useTranslations$1,getTranslations$1).DUMMY_SP.next-intlandnext-intl/server.existing-aliased-hookfixture to verify coexistence with existinguseTranslationsaliases.Written by Cursor Bugbot for commit 0fa519e. This will update automatically on new commits. Configure here.