Description
While working on #2514 I became aware of a potential bug/discrepancy in how Lingui processes dynamic IDs between JS Macros and JSX Macros:
- JS Macros (
t({ id: dynId, message: "Welcome" })):
Preserves the dynamic AST node dynId in the output because Babel processes object properties directly. The output retains "id": dynId.
- JSX Macros (
<Trans id={dynId}>Hello</Trans>):
The dynamic attribute is lost. maybeNodeValue() inside macroJsx.ts evaluates non-static JSX attributes to null. It strips the attribute, completely drops dynId, and instead relies on the hash fallback identifier from the text.
I'm not sure what the expected behaviour is but figured I'd surface this in case it's a bug.
Example test snapshot
import { Trans } from "@lingui/react/macro";
const dynId = "dynamic";
<Trans id={dynId}>Hello</Trans>;
↓ ↓ ↓ ↓ ↓ ↓
import { Trans as _Trans } from "@lingui/react";
const dynId = "dynamic";
<_Trans
{
/*i18n*/
...{
id: "uzTaYi",
message: "Hello",
}
}
/>;
Verifications
Macro Support
Babel with babel-macro-plugin
Lingui Version
6.0.0-next.3
Description
While working on #2514 I became aware of a potential bug/discrepancy in how Lingui processes dynamic IDs between JS Macros and JSX Macros:
t({ id: dynId, message: "Welcome" })):Preserves the dynamic AST node
dynIdin the output because Babel processes object properties directly. The output retains"id": dynId.<Trans id={dynId}>Hello</Trans>):The dynamic attribute is lost.
maybeNodeValue()insidemacroJsx.tsevaluates non-static JSX attributes tonull. It strips the attribute, completely dropsdynId, and instead relies on the hash fallback identifier from the text.I'm not sure what the expected behaviour is but figured I'd surface this in case it's a bug.
Example test snapshot
Verifications
Macro Support
Babel with babel-macro-plugin
Lingui Version
6.0.0-next.3