Repository navigation
fix(i18n): degrade malformed translations to raw text instead of crashing (#4046) - #4745
Merged
Merged
Conversation
…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]>
Contributor
|
Website preview ready: https://pr-4745-marktext-website.ransixi.workers.dev Built from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: 9isNOT_ALLOW_NEST_PLACEHOLDER. vue-i18n compiles each translation lazily on first use; the export flow resolves a batch ofeditor.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.tsused the object formmessageCompiler: { compile }. vue-i18n 11 expectsmessageCompilerto be a function and silently ignores the object form, so:|handling never took effect (the default compiler still plural-split), and{{…}}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 (
compilefrom@intlify/core-base) wrapped intry/catch:{name}interpolation, plurals and linked references (compiled by the real compiler);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-baseis promoted to a direct dependency (pinned to vue-i18n's version).Reproduction & tests (TDD)
Added regression tests in
test/unit/specs/i18n.spec.ts:{{type}}no longer throws and renders as raw text (this failed before the fix withMessage compilation error: Not allowed nest placeholder);Hello {name}message still interpolates.Verification
typecheck✅ ·lint✅ (no new findings).🤖 Generated with Claude Code