Skip to content

fix(macro): map injected imports to original statements #2252

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timofei-iatsenko
Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko commented May 16, 2025

Description

This PR brings:

whenever runtime import injected by macro it's mapped to the authored import by the source maps:

import {Trans} from '@lingui/react/macro'

// injected and mapped to 

import {Trans} from '@lingui/react'

This applies to all imports supported by macro.

That potentially should resolve issue with dual package hazard in the react native 0.79,
Alternative fix for this: #2233

Probably, the import is getting replaced but dropping the source import loc, which Metro needs to map the dependency to the original import
The good news is that category of problem should go away when we move off the Babel ESM transform and we don’t need to rely on source mappings to determine the original import style.
For now the best fix for lingui-js would be to preserve the source loc when it replaces an import - which it definitely should be doing anyway.

Key word for the search

Error: useLingui hook was used without I18nProvider

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview May 16, 2025 9:05am

Copy link

size-limit report 📦

Path Size
packages/core/dist/index.mjs 2.91 KB (0%)
packages/detect-locale/dist/index.mjs 618 B (0%)
packages/react/dist/index.mjs 1.35 KB (0%)

@timofei-iatsenko
Copy link
Collaborator Author

@vonovak could you test it locally, does it resolve the issue?

@timofei-iatsenko timofei-iatsenko requested a review from vonovak May 16, 2025 09:11
@timofei-iatsenko timofei-iatsenko marked this pull request as ready for review May 16, 2025 09:11
@vonovak
Copy link
Collaborator

vonovak commented May 16, 2025

Will check this, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants