Skip to content
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

[docs] Fix issues reported by react compiler in docs folder #42881

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/mui-docs/src/i18n/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ export function useSetUserLanguage() {

const warnedOnce: Record<string, boolean> = {};

const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => {
Copy link
Member

Choose a reason for hiding this comment

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

function for top-level declarations

Suggested change
const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => {
function warn(userLanguage: string, key: string, ignoreWarning: boolean) {

Copy link
Member

@oliviertassinari oliviertassinari Jul 21, 2024

Choose a reason for hiding this comment

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

We should migrate to use the warnOnce helper in the future mui/mui-x#13911. We can't yet, but eventually. I have left a TODO message in the code.

const fullKey = `${userLanguage}:${key}`;
// No warnings in CI env
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
console.warn(`Missing translation for ${fullKey}`);

warnedOnce[fullKey] = true;
}
};

export interface TranslateOptions {
ignoreWarning?: boolean;
}
Expand All @@ -104,12 +114,7 @@ export function useTranslate() {
const translation = getPath(wordings, key);

if (!translation) {
const fullKey = `${userLanguage}:${key}`;
// No warnings in CI env
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
console.error(`Missing translation for ${fullKey}`);
warnedOnce[fullKey] = true;
}
warn(userLanguage, key, ignoreWarning);
return getPath(translations.en, key);
}

Expand Down