Skip to content
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

feat(localizations): Reuse english characters to improve performance #5498

Closed
wants to merge 1 commit into from

Conversation

nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Apr 1, 2025

Description

This PR replaces all hardcoded character literals within strings across the codebase with default imports from the @characters npm package.

With this change we improve:

  • Reusability & consistency: This approach makes the source of every character explicit. We can immediately see that each character is intentionally sourced from the @characters library, rather than being an arbitrary part of a magic string.
  • Bundle size: This modular approach offers more granular control. If certain characters are truly unused across the entire project, they will be eliminated, reducing the final bundle size.
  • Improved code readability: This point self-explanatory, as the intent of each character is now clearly defined.

Important considerations:

Before opening the PR, @anagstef and I benchmarked the bundle size and the runtime impact. We found out that the runtime impact is negligible, while the bundle size is reduced by approximately 2.1%. Given the minimal runtime cost, we both think is a good trade-off.

Happy to discuss further before merging. We will need to apply the same to all localization files as well.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Apr 1, 2025

🦋 Changeset detected

Latest commit: c00250b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@clerk/localizations Patch
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 1, 2025

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

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2025 0:22am

selectDropdown__role: `${S}${e}${l}${e}${c}${t} ${r}${o}${l}${e}`,
subtitle: `${E}${n}${t}${e}${r} ${o}${r} ${p}${a}${s}${t}${e} ${o}${n}${e} ${o}${r} ${m}${o}${r}${e} ${e}${m}${a}${i}${l} ${a}${d}${d}${r}${e}${s}${s}${e}${s}, ${s}${e}${p}${a}${r}${a}${t}${e}${d} ${b}${y} ${s}${p}${a}${c}${e}${s} ${o}${r} ${c}${o}${m}${m}${a}${s}.`,
successMessage: `${I}${n}${v}${i}${t}${a}${t}${i}${o}${n}${s} ${s}${u}${c}${c}${e}${s}${s}${f}${u}${l}${l}${y} ${s}${e}${n}${t}`,
title: `${I}${n}${v}${i}${t}${e} ${n}${e}${w} ${m}${e}${m}${b}${e}${r}${s}`,
},
membersPage: {
action__invite: 'Invite',
Copy link
Member

Choose a reason for hiding this comment

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

@nikosdouvlis we missed this one I guess

Copy link
Member Author

@nikosdouvlis nikosdouvlis Apr 1, 2025

Choose a reason for hiding this comment

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

Does this affect bundle size at all or can we ignore for now?

Edit: this does affect bundle size, the tests now fail. I will fix the rest of the file

@jacekradko
Copy link
Member

:shipit: Looks rock solid!

Copy link
Member

@dstaley dstaley left a comment

Choose a reason for hiding this comment

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

This is great! I love that the reusability will reduce maintenance burden for maintainers. LGTM 👍

@nikosdouvlis
Copy link
Member Author

nikosdouvlis commented Apr 2, 2025

After internal discussions, we decided not to go forward with this approach at this time. The @characters/{} packages are helpful but the default exports break ESM/CJS interoperability for certain bundler configurations. We will revisit this in April 2026

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

Successfully merging this pull request may close these issues.

6 participants