Skip to content

Translate: ability to save long translations - #4449

Merged
eemeli merged 3 commits into
mozilla:mainfrom
ayshushus:4438-long-translations
Aug 31, 2026
Merged

eemeli merged 3 commits into
mozilla:mainfrom
ayshushus:4438-long-translations

Conversation

@ayshushus

@ayshushus ayshushus commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fix #4438

The bug is in CodeMirror’s parser state handling:

  • fluentMode and commonMode store tokenizer state as an array stack.
  • CodeMirror’s default copyState() incorrectly copies that array into a plain object.
  • When parsing resumes from that copied state, state.at() / push() / pop() no longer exist, causing TypeError: state.at is not a function.
  • This only occurs for sufficiently long, multi-line values when editing near the end, because that’s when CodeMirror resumes from a saved parser snapshot. After 512 + 25 characters.

Fix:

  • Add custom copyState for fluentMode and commonMode.
  • Add tests that resume typing from a parser state snapshot.

@ayshushus ayshushus changed the title update copyState for fluentMode and commonMode Translate: ability to save long translations Aug 25, 2026
@ayshushus ayshushus self-assigned this Aug 25, 2026
@ayshushus
ayshushus requested a review from mathjazz August 25, 2026 16:11
@ayshushus
ayshushus marked this pull request as ready for review August 25, 2026 16:11
@mathjazz
mathjazz removed their request for review August 27, 2026 11:47
@ayshushus

Copy link
Copy Markdown
Contributor Author

@eemeli I also think that the tests don't need changes (at least functionally) even after going with the in-line approach, correct?

@ayshushus
ayshushus requested a review from eemeli August 27, 2026 18:06

@eemeli eemeli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but with respect to

The snapshot reference is there because the bug was being caused by chunking and was saving an empty {}.

there is no explanation documented about what happened here either in this PR, the issue, or in code comments. As far as I can tell, the only place where the problem investigation is described is in a comment on the #l10n-community Matrix channel.

Before merging, please include a comment somewhere on GitHub describing why the changes here fix the observed problem.

@ayshushus

Copy link
Copy Markdown
Contributor Author

include a comment

Added a comment on this PR's description.

@ayshushus
ayshushus requested a review from eemeli August 31, 2026 14:48
@eemeli
eemeli merged commit 3a424f4 into mozilla:main Aug 31, 2026
10 checks passed
@ayshushus
ayshushus deleted the 4438-long-translations branch September 30, 2026 19:54
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.

Unable to save long translations

2 participants