-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function t() { [native code] } #1675
Comments
please provide a minimal reproducible example repository or codesandbox... |
I modified the logic cut-in timing of dynamically adding resources, and it has returned to normal. |
There is still a problem, your words reminded me that I did use lazy loading for routing. Remember, after using it, my i18n is not working properly! I organized a small demo but couldn't reproduce my anomalies. |
I was sure it was an encapsulation problem with react-i18nex. When I directly removed react-i18nex and used the original i18nex library to implement the page re-rendering logic, all the problems were solved. When a component is repeatedly added and deleted, react-i18next will have the above problems. It may be that the library performs repeated rendering, or it may be caused by some problem. The problem is currently unknown. |
I'm also running into this. I am not explicitly calling export const TauriBackend: BackendModule = {
type: "backend",
init: function (
services: Services,
backendOptions: object,
i18nextOptions: InitOptions<object>
): void {
// Nothing to do
},
read: function (
language: string,
namespace: string,
callback: ReadCallback
): void {
console.log("i18n", language, namespace);
invoke<string>("read_translations", {
language: language,
namespace: namespace,
})
.then((fileContent) => {
const data = JSON.parse(fileContent);
callback(null, data);
})
.catch((ex) => callback(ex, null));
},
}; |
use Suspense or check the ready flag: https://react.i18next.com/latest/usetranslation-hook#not-using-suspense |
ready para I tried, but it was still a mistake |
I also encountered a problem with the tauri program. Currently, I am using the native i18next to temporarily solve the problem. I do not know what is causing this situation in the react-i8next library. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Similar problem in safari (verison in console) Simple example: |
Looks like this issue libwebkit2gtk-4.0-37=2.40.5-1 only... (maybe some another versions) Reproducing issue on debian-11.7.0: libwebkit2gtk-4.0-37=2.40.5-1 is latest for some OS like AstraLinux and it's needed for tauri apps. And if you open devtools on test issue will not be reproducing) |
Btw, temporary fix (useTranslation wrapper, 'static' and 'backend' - my namespaces): import { useMemo } from 'react';
import type { FallbackNs, UseTranslationOptions } from 'react-i18next';
import { useTranslation as useTranslationi18Next } from 'react-i18next';
import type { KeyPrefix, TFunction } from 'i18next';
import type { $Tuple } from 'react-i18next/helpers';
export const useTranslation: typeof useTranslationi18Next = <
Ns extends
| 'static'
| 'backend'
| $Tuple<'static' | 'backend'>
| undefined = undefined,
KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
>(
ns?: Ns,
options?: UseTranslationOptions<KPrefix>,
) => {
const { t: tI18Next, ...other } = useTranslationi18Next<Ns, KPrefix>(
ns,
options,
);
const t = useMemo<TFunction<FallbackNs<Ns>>>(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const t = (...args: any) => {
const res = tI18Next(...args);
return typeof res === 'function' ? res.call(null, ...args) : res;
};
t.$TFunctionBrand = tI18Next.$TFunctionBrand;
return t;
}, [tI18Next]);
return { t, ...other };
}; |
🐛 Bug Report
Display abnormalities may occur when loading the cut flower page for the first time or refreshing it multiple times.
console pringt Warning:
UI Display Error
code
I18NExtManage.tsx
I18NResources.ts
Call functions
Error if not adding toString function
Occasionally report an error
I ensure that the returned value must be a string
I guess the exception is caused when the page calls the following function, but the added event has been added and re-rendered, but it still doesn't work.
Expected behavior
Regardless of the first load or page switching, refreshing, resource addition, the page displays normally
Environment
runtime version*: i.e. node v18.17.1
The text was updated successfully, but these errors were encountered: