preact icon indicating copy to clipboard operation
preact copied to clipboard

当我使用preact和 //translate.google.com/translate_a/element.js 时,会渲染不正确

Open lvzegeng opened this issue 3 years ago • 4 comments

渲染的错误Dom元素,包含了翻译之前的文字: image

渲染的正确Dom元素: image

lvzegeng avatar Mar 23 '21 10:03 lvzegeng

Please use this patch: https://gist.github.com/developit/3e807962630ddbd4977cbd07b597f24f

I've spoken to the Translate team about this and suggested fixes, but it will take a long time.

developit avatar Mar 23 '21 23:03 developit

How should I use this patch There is a problem with the options variable

lvzegeng avatar Mar 24 '21 03:03 lvzegeng

@lvzegeng - sorry, I forgot to include the import. I have updated the Gist, it should work now.

Just import this before any rendering happens:

import { render } from 'preact';
import './preact-google-translate-patch';

render(...);

developit avatar Mar 30 '21 15:03 developit

Hello @developit I'm having the same problem and I have tried to use the patch but by the nature of the project I'm working on everything gets rendered using portals (it's a nav). Do you know how could I apply the patch to work for this scenario? Thanks!

This how I tried to use it.

/** @jsx h */
import { FunctionalComponent, VNode } from 'preact';
import { createPortal } from 'preact/compat';
import '../../utils/translationFix';

oscar-reyes-beachbody avatar Jun 30 '21 21:06 oscar-reyes-beachbody