Skip to content

fix(i18n): degrade malformed translations to raw text instead of crashing (#4046) - #4745

Merged
Jocs merged 2 commits into
developfrom
fix/i18n-malformed-message-crash-4046
Jun 26, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/i18n-malformed-message-crash-4046

Conversation

@Jocs

@Jocs Jocs commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #4046 — exporting HTML/PDF could surface an "Unexpected renderer process error" even though the export itself completed and produced valid files.

The error originates in vue-i18n's message compiler:

SyntaxError: 9
    at createCompileError ...
    at readTokenInPlaceholder ...
    at parseMessage ...
    at baseCompile ...

SyntaxError: 9 is NOT_ALLOW_NEST_PLACEHOLDER. vue-i18n compiles each translation lazily on first use; the export flow resolves a batch of editor.export.* / exportSettings.* / store.editor.export* keys for the first time. If the active locale's value for one of them contains a nested placeholder (a literal {{x}}, or a { inside a {…}), that first compile throws and crashes the renderer — while the export, which runs independently, still succeeds. This matches the report exactly (error dialog + well-formed output).

Root cause

The existing guard in i18n/index.ts used the object form messageCompiler: { compile }. vue-i18n 11 expects messageCompiler to be a function and silently ignores the object form, so:

  • the intended | handling never took effect (the default compiler still plural-split), and
  • the {{…}} crash was not prevented — the app behaved like the default compiler, which throws.

Fix

Replace it with the correct function form that reuses vue-i18n's own compiler (compile from @intlify/core-base) wrapped in try/catch:

  • well-formed messages keep {name} interpolation, plurals and linked references (compiled by the real compiler);
  • a message that fails to compile degrades to its raw text instead of throwing — a single bad translation can never crash the renderer again.

Because the old object form was already ignored, behavior is byte-identical for every valid message; only malformed messages change from throw to raw text. @intlify/core-base is promoted to a direct dependency (pinned to vue-i18n's version).

Reproduction & tests (TDD)

Added regression tests in test/unit/specs/i18n.spec.ts:

  • a registered message containing {{type}} no longer throws and renders as raw text (this failed before the fix with Message compilation error: Not allowed nest placeholder);
  • a well-formed Hello {name} message still interpolates.

Verification

  • Full unit suite: 668 passed (33 files), no regressions.
  • typecheck ✅ · lint ✅ (no new findings).
  • Verified all 10 shipped locales compile cleanly under the new compiler (so no current message is affected).

🤖 Generated with Claude Code

Jocs and others added 2 commits June 26, 2026 21:47
…hing

vue-i18n compiles each translation lazily on first use and throws a
SyntaxError when a value can't be parsed — e.g. a literal `{{x}}` (nested
placeholder) or stray linked-message syntax. A single malformed translation
then crashed the renderer; during HTML/PDF export this surfaced as an
"Unexpected renderer process error" even though the export itself succeeded
(issue #4046).

The previous `messageCompiler: { compile }` used the object form, which
vue-i18n 11 silently ignores, so it neither special-cased `|` nor prevented
the crash. Replace it with the correct function form that reuses vue-i18n's
own compiler (`compile` from @intlify/core-base) so well-formed messages keep
their `{name}` interpolation, plurals and linked references, and falls back to
the raw text when compilation fails.

Behavior is byte-identical for every valid message (the old object form was
already ignored); only malformed messages change from "throw" to "raw text".

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reproduce the export crash: a registered translation whose value contains a
nested placeholder (`{{type}}`) must not throw from t() and should degrade to
its raw text. Also assert well-formed messages still interpolate, guarding the
compiler swap from regressing normal translation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Website preview ready: https://pr-4745-marktext-website.ransixi.workers.dev

Built from 6fa724ad80dcf73627009c03bf1b6ec40ed51072 · Worker: marktext-website · Version: b33aa173-174b-44d0-b1bc-c2cc6e169410 · Alias: pr-4745

@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4745:

Run: https://github.com/marktext/marktext/actions/runs/28242248203

Artifact Size Link
marktext-windows-arm64 275.6 MB Download
marktext-linux 627.3 MB Download
marktext-macos-x64 293.0 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit fa63a8e into develop Jun 26, 2026
18 checks passed
@Jocs
Jocs deleted the fix/i18n-malformed-message-crash-4046 branch June 26, 2026 15:19
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.

"Unexpected renderer process error" exporting HTML or PDF

1 participant