Skip to content

feat(translate): implement JSX placeholder mask/restore to prevent LLM corruption #173

@luandro

Description

@luandro

Background

The translation pipeline currently protects JSX/MDX attribute syntax only via prompt instructions. The integration test (scripts/eval/jsx-preservation.integration.test.ts) explicitly documents that this is non-deterministic:

"Before that implementation [scripts/shared/jsxPlaceholders.ts] exists, these tests will fail non-deterministically because the LLM can corrupt JSX attribute syntax"

The file scripts/shared/jsxPlaceholders.ts is referenced as the intended fix but does not yet exist.

What to implement

A jsxPlaceholders.ts module (analogous to localeImagePlaceholders.ts) that:

  1. Before translation: scans the markdown for JSX blocks and attributes (e.g. <Tabs>, <TabItem value="android">, MDX import/export statements) and replaces them with stable opaque tokens that the LLM will not alter.
  2. After translation: restores the original JSX from the tokens.

The mask/restore approach makes JSX preservation deterministic regardless of LLM behaviour.

Acceptance criterion

The existing integration tests in scripts/eval/jsx-preservation.integration.test.ts should pass reliably when RUN_LIVE_TRANSLATION_TESTS=1 without the prompt-only protection being the sole guard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions