From c306977c5e42f3af8157d9b33eb53a394e20e464 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Sun, 7 Jul 2024 15:25:52 +0530 Subject: [PATCH 1/3] fix --- packages/mui-docs/src/CodeCopy/CodeCopy.tsx | 14 +++++++------- packages/mui-docs/src/i18n/i18n.tsx | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx index f39c1adb147380..666175841d6b17 100644 --- a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx +++ b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx @@ -2,8 +2,8 @@ import * as React from 'react'; import { useRouter } from 'next/router'; import clipboardCopy from 'clipboard-copy'; -const CodeBlockContext = React.createContext>({ - current: null, +const CodeBlockContext = React.createContext>({ + current: undefined, }); /** @@ -24,7 +24,7 @@ export function useCodeCopy(): React.HTMLAttributes { onMouseLeave: (event) => { if (rootNode.current === event.currentTarget) { (rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur(); - rootNode.current = null; + rootNode.current = undefined; } }, onFocus: (event) => { @@ -32,7 +32,7 @@ export function useCodeCopy(): React.HTMLAttributes { }, onBlur: (event) => { if (rootNode.current === event.currentTarget) { - rootNode.current = null; + rootNode.current = undefined; } }, }; @@ -66,7 +66,7 @@ function InitCodeCopy() { const handleMouseLeave = () => { if (rootNode.current === elm) { (rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur(); - rootNode.current = null; + rootNode.current = undefined; } }; elm.addEventListener('mouseleave', handleMouseLeave); @@ -82,7 +82,7 @@ function InitCodeCopy() { const handleFocusout = () => { // use `focusout` because it bubbles from the copy button if (rootNode.current === elm) { - rootNode.current = null; + rootNode.current = undefined; } }; elm.addEventListener('focusout', handleFocusout); @@ -157,7 +157,7 @@ interface CodeCopyProviderProps { * Any code block inside the tree can set the rootNode when mouse enter to leverage keyboard copy. */ export function CodeCopyProvider({ children }: CodeCopyProviderProps) { - const rootNode = React.useRef(null); + const rootNode = React.useRef(undefined); React.useEffect(() => { document.addEventListener('keydown', (event) => { if (!rootNode.current) { diff --git a/packages/mui-docs/src/i18n/i18n.tsx b/packages/mui-docs/src/i18n/i18n.tsx index 48e628600e78df..f1dbf037b4d9b5 100644 --- a/packages/mui-docs/src/i18n/i18n.tsx +++ b/packages/mui-docs/src/i18n/i18n.tsx @@ -81,6 +81,14 @@ export function useSetUserLanguage() { const warnedOnce: Record = {}; +const warn = (fullKey: string) => { + if (!warnedOnce[fullKey]) { + console.warn(`Missing translation for ${fullKey}`); + + warnedOnce[fullKey] = true; + } +}; + export interface TranslateOptions { ignoreWarning?: boolean; } @@ -107,8 +115,7 @@ export function useTranslate() { 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(fullKey); } return getPath(translations.en, key); } From a7a1d2fcf7a4c54ea81e511be17d2900726ebcc3 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Mon, 8 Jul 2024 13:11:52 +0530 Subject: [PATCH 2/3] refactor warn function --- packages/mui-docs/src/i18n/i18n.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/mui-docs/src/i18n/i18n.tsx b/packages/mui-docs/src/i18n/i18n.tsx index f1dbf037b4d9b5..3ac36eeec1da05 100644 --- a/packages/mui-docs/src/i18n/i18n.tsx +++ b/packages/mui-docs/src/i18n/i18n.tsx @@ -81,8 +81,10 @@ export function useSetUserLanguage() { const warnedOnce: Record = {}; -const warn = (fullKey: string) => { - if (!warnedOnce[fullKey]) { +const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => { + 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; @@ -112,11 +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') { - warn(fullKey); - } + warn(userLanguage, key, ignoreWarning); return getPath(translations.en, key); } From f7d936d03b178a76adf0418fd3fe0fcc6feb6478 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Mon, 8 Jul 2024 13:30:37 +0530 Subject: [PATCH 3/3] revert codecopy --- packages/mui-docs/src/CodeCopy/CodeCopy.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx index 666175841d6b17..f39c1adb147380 100644 --- a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx +++ b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx @@ -2,8 +2,8 @@ import * as React from 'react'; import { useRouter } from 'next/router'; import clipboardCopy from 'clipboard-copy'; -const CodeBlockContext = React.createContext>({ - current: undefined, +const CodeBlockContext = React.createContext>({ + current: null, }); /** @@ -24,7 +24,7 @@ export function useCodeCopy(): React.HTMLAttributes { onMouseLeave: (event) => { if (rootNode.current === event.currentTarget) { (rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur(); - rootNode.current = undefined; + rootNode.current = null; } }, onFocus: (event) => { @@ -32,7 +32,7 @@ export function useCodeCopy(): React.HTMLAttributes { }, onBlur: (event) => { if (rootNode.current === event.currentTarget) { - rootNode.current = undefined; + rootNode.current = null; } }, }; @@ -66,7 +66,7 @@ function InitCodeCopy() { const handleMouseLeave = () => { if (rootNode.current === elm) { (rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur(); - rootNode.current = undefined; + rootNode.current = null; } }; elm.addEventListener('mouseleave', handleMouseLeave); @@ -82,7 +82,7 @@ function InitCodeCopy() { const handleFocusout = () => { // use `focusout` because it bubbles from the copy button if (rootNode.current === elm) { - rootNode.current = undefined; + rootNode.current = null; } }; elm.addEventListener('focusout', handleFocusout); @@ -157,7 +157,7 @@ interface CodeCopyProviderProps { * Any code block inside the tree can set the rootNode when mouse enter to leverage keyboard copy. */ export function CodeCopyProvider({ children }: CodeCopyProviderProps) { - const rootNode = React.useRef(undefined); + const rootNode = React.useRef(null); React.useEffect(() => { document.addEventListener('keydown', (event) => { if (!rootNode.current) {