Skip to content

fix: prevent browser translation DOM crashes - #387

Draft
sleroq wants to merge 1 commit into
friendly-social:devfrom
sleroq:fix/browser-translation-dom-crash
Draft

sleroq wants to merge 1 commit into
friendly-social:devfrom
sleroq:fix/browser-translation-dom-crash

Conversation

@sleroq

@sleroq sleroq commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Resolves #323

Chrome translation replaces text nodes that React still expects to find.

Changes:

  • post content: reuse elements instead of rebuilding them during updates.
  • sign-in buttons: put each label inside a span so React can safely replace it with a loading spinner
  • timestamps: wrap in span, making updates safer after translation

To be clear - the crash I've reproduced was only caused by the post content. Other stuff in theory can cause a crash as well, but it's not super necessary.

@sleroq sleroq changed the title fix(translation): prevent browser translation DOM crashes fix: prevent browser translation DOM crashes Oct 2, 2026
@sleroq
sleroq marked this pull request as ready for review October 2, 2026 14:25
@y9san9

y9san9 commented Oct 6, 2026

Copy link
Copy Markdown
Member

Sorry, I missed all the PRs. Can you please delete merge commit and rebase instead?

</ReactMarkdown>
)}
>
<ImageClickContext.Provider value={onImageClick}>

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.

Honestly I don't think it should be a context. It's makes things more complicated than it needs to be

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Context helps there because this way we avoid remounting potentially translated markdown content. But this may be unnecessary change I made while searching for the cause of the crash.

I'll look into it later and try to simplify this pr

@y9san9

y9san9 commented Oct 6, 2026

Copy link
Copy Markdown
Member

To be clear - the crash I've reproduced was only caused by the post content. Other stuff in theory can cause a crash as well, but it's not super necessary

Can you point what was the reason of the crash specifically?

@sleroq

sleroq commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@y9san9 Translate plugin is replacing the text nodes with the translated ones, react then is failing to edit removed node or insert elements in relation to them. Wrapping text with span fixes this.

Alternatively we could just instruct translate extension not to translate the site, but probably some other extensions would do the same so I think this is worth it.

@y9san9

y9san9 commented Oct 6, 2026

Copy link
Copy Markdown
Member

@sleroq Yeah and can you point to the specific lines in this PR that wrap text into spans in the post description?

I am from mobile now, I hope you are not :D

Also would be nice to separate this single thing and other changes, since I am not against optimizing for translaters

@sleroq
sleroq force-pushed the fix/browser-translation-dom-crash branch from 26034d2 to 4df2361 Compare October 6, 2026 09:12
@sleroq
sleroq marked this pull request as draft October 6, 2026 09:30

This branch has not been deployed

No deployments
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.

Crash on sign-in with enabled Google Translator

2 participants