Skip to content

feat(message-utils): separate browser/node exports for generateMessageId#2401

Merged
andrii-bodnar merged 3 commits intolingui:mainfrom
yslpn:feat/separate-browser/node-exports-for-generate-message-id
Jan 23, 2026
Merged

feat(message-utils): separate browser/node exports for generateMessageId#2401
andrii-bodnar merged 3 commits intolingui:mainfrom
yslpn:feat/separate-browser/node-exports-for-generate-message-id

Conversation

@yslpn
Copy link
Contributor

@yslpn yslpn commented Jan 16, 2026

Description

Split generateMessageId into separate browser (default) and Node.js implementations:

  • Browser: use sha256.array() directly instead of hex string conversion
  • Node.js: use native crypto.createHash().digest('base64')

Node.js crypto is faster and doesn't require js-sha256 dependency. Browser version optimized by avoiding hex parsing. Other runtimes (Deno, Bun, edge workers) support Node.js exports and should work out of the box.

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 #2381

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 Jan 16, 2026

@yslpn is attempting to deploy a commit to the Crowdin Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.70%. Comparing base (6bb8983) to head (734b5ab).
⚠️ Report is 253 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2401      +/-   ##
==========================================
- Coverage   77.05%   76.70%   -0.35%     
==========================================
  Files          84      102      +18     
  Lines        2157     2752     +595     
  Branches      555      720     +165     
==========================================
+ Hits         1662     2111     +449     
- Misses        382      513     +131     
- Partials      113      128      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko left a comment

Choose a reason for hiding this comment

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

LGTM, except of the bumped dep. Thanks for the contribution!

@timofei-iatsenko
Copy link
Collaborator

@Zxilly fyi

@yslpn
Copy link
Contributor Author

yslpn commented Jan 19, 2026

By the way, what is the use case for generateMessageId in a browser? I couldn't find any information.

@Zxilly
Copy link
Contributor

Zxilly commented Jan 19, 2026

My initial idea was to create a faster generateMessageId, but after implementing multi thread, the performance was generally satisfactory to me. What might be more important to me is a customizable generateMessageId, but I haven't come up with a good approach if using the swc plugin.

@timofei-iatsenko
Copy link
Collaborator

@Zxilly what in particulare you would like to customize in it? Maybe that could be solved somehow else.

@yslpn it is not used directly in the lingui code, but used by the external integrations.

One of the potential use-cases - when you download raw, non-compiled catalogs from the TMS (OTA delivery) and then you need to prepare them to be usable in app.

Another use-case which i am aware of, Vue integration which doesn't use compile time macro which is replacing source message with an id, but instead it generate message id at runtime (in a browser).

@vercel
Copy link

vercel bot commented Jan 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
js-lingui Ready Ready Preview Jan 19, 2026 0:59am

Request Review

@andrii-bodnar andrii-bodnar merged commit 2afe02f into lingui:main Jan 23, 2026
13 checks passed
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.

Dual nodejs/browser version for @lingui/message-utils

4 participants