Skip to content

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)

@vercel
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

@github-actions
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!

Copy link
Collaborator

@vonovak vonovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm this works, thank you! 💯

tested by building lingui-babel-plugin-lingui-macro and installing from lingui-babel-plugin-lingui-macro-5.3.2.tgz into the example project.

vonovak added a commit that referenced this pull request May 26, 2025
@vonovak
Copy link
Collaborator

vonovak commented May 26, 2025

also updated #2232 for this

@vonovak vonovak mentioned this pull request May 26, 2025
4 tasks
@andrii-bodnar andrii-bodnar merged commit 73b081e into main May 26, 2025
13 checks passed
@andrii-bodnar andrii-bodnar deleted the fix/map-macro-import-to-injected branch May 26, 2025 17:31
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.

4 participants