Repository navigation
fix(muya): crash typing '#' β guard I18n.t + add heading-copy-link locale key - #4424
Merged
Merged
Conversation
t() fell through to `resources.en[key]`, but `resources.en` is undefined
whenever the loaded locale is not named `en` (the constructor stores only
`{ [name]: resource }`). A key missing from the current locale therefore
threw `Cannot read properties of undefined` instead of falling back. Use
optional chaining so a missing key is always safe.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The HeadingCopyLink affordance (PG11, #4414) used this i18n key but it was never added to the locale resources, so typing `#` to create a heading crashed in a non-en locale (and showed the raw key in en). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a renderer crash triggered when creating a heading (#) by making I18n.t() resilient to missing locale entries and by adding the missing heading-copy-link label key across all Muya locales.
Changes:
- Guarded the English fallback lookup in
I18n.t()to avoid throwing whenresources.enis missing. - Added the new locale key
'Copy anchor link to this heading'to all shipped locales (en/zh-CN/zh-TW/de/es/fr/ja/ko/pt).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/muya/src/i18n/index.ts | Makes translation fallback safer to prevent crashes when a key/locale is missing. |
| packages/muya/src/locales/en.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/de.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/es.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/fr.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/ja.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/ko.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/pt.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/zh-CN.ts | Adds the heading copy-link label key. |
| packages/muya/src/locales/zh-TW.ts | Adds the heading copy-link label key. |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
18
to
22
| t(key: string): string { | ||
| const { lang, resources } = this; | ||
|
|
||
| return resources?.[lang]?.[key] || resources.en[key] || key; | ||
| return resources?.[lang]?.[key] || resources.en?.[key] || key; | ||
| } |
Member
Author
There was a problem hiding this comment.
Done β changed the en fallback to resources?.en?.[key] so both lookups optional-chain resources consistently and t() stays crash-safe even if resources is ever unset. Thanks!
Keeps I18n.t fully crash-safe and consistent with the primary lookup if `resources` is ever unset. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Jocs
added a commit
that referenced
this pull request
Jun 9, 2026
β¦i18n keys (#4427) An i18n-key audit (prompted by the #4424 heading-copy-link crash) found two more keys used via i18n.t() but absent from the locale resources. Before #4424's crash-safety fix these threw in a non-en locale; after it they displayed the raw English key. Added both to all 9 locales. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Jocs
added a commit
that referenced
this pull request
Jun 10, 2026
β¦4434) Fill the highest-value missing automated tests from the @muyajs/core migration regression audit β the recently-fixed bugs and data-loss-adjacent paths that had no engine coverage. - headingLocaleCrash.spec.ts (#4424/#4427 TOP priority): boots Muya under a non-en (zh-CN) locale and types `#` to create a heading, exercising the HeadingCopyLink `i18n.t` path that used to crash. Asserts no throw, the translated copy-anchor label resolves per-locale, the affordance still emits `heading-copy-link`, and `I18n.t` stays crash-safe (raw-key fall-through) for a key missing from a non-en locale. - formatToggle.spec.ts: the public `Format.format()` toggle-OFF and `clear` paths over a real boot (strong/em/del/u/mark/link/inline-code) β only the apply-side `_addFormat` was previously covered. - backspaceUnwrap.spec.ts (data-loss): Backspace-at-offset-0 cross-block surgery β paragraph merge + caret join point, and block-quote / list unwrap across all four branches (only/first/middle), asserting no item is dropped. - tableCell backspaceSafety.spec.ts (data-loss): empty-table Backspace β paragraph replacement, and previous-cell caret jump without destructive merge. - table insertRowColumn.spec.ts: insertRow/insertColumn shape, per-column alignment inheritance, delimiter round-trip, and returned caret cell β only the removal paths were previously unit-tested. All assert already-correct behavior (coverage gaps, not failing-first) and pass on current develop. Gates: lint, lint:types, check-circular, test, test:spec. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.
Crash
Typing
#to create a heading throws in the renderer:Root cause (two bugs)
I18n.tis not crash-safe.return resources?.[lang]?.[key] || resources.en[key] || keyβresources.enis undefined whenever the loaded locale isn't nameden(the constructor stores only{ [name]: resource }). A key missing from the current locale fell through toresources.en[key]β throw.HeadingCopyLink(PG11, feat(muya): emit preview-image + heading-copy-link events (PG10/PG11)Β #4414) callsi18n.t('Copy anchor link to this heading'), but that key isn't in any locale resource β so it always hit the unguarded fallback.Fix
resources.en[key]βresources.en?.[key](any missing key is now safe, every locale).'Copy anchor link to this heading'to all 9 locales (en/zh-CN/zh-TW/de/es/fr/ja/ko/pt).Verified:
lint,lint:types, fulltestgreen. This is a real-app regression the headless tests missed (the spec/e2e ran under theendefault whereresources.enexists) β exactly the Phase G class.