Skip to content

[v6] Inconsistent behaviour of dynamic IDs in JS/JSX macros #2523

@mogelbrod

Description

@mogelbrod

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:

  1. 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.
  2. 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

  • I've checked the docs and this isn't covered there.
  • I've searched existing issues on GitHub.

Macro Support

Babel with babel-macro-plugin

Lingui Version

6.0.0-next.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions