refactor(组件): 将 destroyOnClose 替换为 destroyOnHidden 以优化组件销毁逻辑
refactor(React工具): 重构 React 18 兼容性补丁,合并开发环境修复功能 优化多个组件中的销毁逻辑,统一使用 destroyOnHidden 替代 destroyOnClose。同时重构 React 18 兼容性补丁代码,将开发环境的相关修复功能整合到 setupReactDevFixes 方法中,提高代码可维护性。
This commit is contained in:
@ -6,40 +6,11 @@ import App from './App'
|
||||
import 'antd/dist/reset.css'
|
||||
import '@douyinfe/semi-ui/dist/css/semi.min.css'
|
||||
import './styles/global.css'
|
||||
// 导入 React 18 兼容性补丁
|
||||
import { setupReact18Polyfill, setupDevSanitizeDOMProps } from './utils/react18-polyfill'
|
||||
import { setupReactDevFixes } from './utils/react18-polyfill'
|
||||
|
||||
// 应用 React 18 兼容性补丁
|
||||
setupReact18Polyfill()
|
||||
// 开发期:剔除会透传到原生 DOM 的非标准属性(localeCode/defaultCurrency/showCurrencySymbol)
|
||||
setupDevSanitizeDOMProps()
|
||||
|
||||
// 仅在开发环境过滤特定第三方库产生的已知无害告警
|
||||
// 仅在开发环境启用所有修复(幂等,不影响其他功能)
|
||||
if (import.meta.env.DEV) {
|
||||
const shouldSuppress = (msg: unknown) => {
|
||||
if (typeof msg !== 'string') return false
|
||||
// semi-ui 某些组件链路在 React 18 下把非标准属性透传到 DOM,触发告警
|
||||
if (msg.includes('React does not recognize the `localeCode` prop on a DOM element')) return true
|
||||
if (msg.includes('React does not recognize the `defaultCurrency` prop on a DOM element')) return true
|
||||
if (msg.includes('React does not recognize the `showCurrencySymbol` prop on a DOM element')) return true
|
||||
// 浏览器建议表单自动填充
|
||||
if (msg.includes('[DOM] Input elements should have autocomplete attributes')) return true
|
||||
return false
|
||||
}
|
||||
|
||||
const origError = console.error
|
||||
console.error = (...args: any[]) => {
|
||||
const msg = args?.[0]
|
||||
if (shouldSuppress(msg)) return
|
||||
origError(...args)
|
||||
}
|
||||
|
||||
const origWarn = console.warn
|
||||
console.warn = (...args: any[]) => {
|
||||
const msg = args?.[0]
|
||||
if (shouldSuppress(msg)) return
|
||||
origWarn(...args)
|
||||
}
|
||||
setupReactDevFixes()
|
||||
}
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
|
||||
Reference in New Issue
Block a user