Files
sim/apps/sim/app/_shell/hydration-error-handler.tsx
Emir Karabeg 3dbf0f5679 feat: keyboard navigation; improvement: SEO/GEO; refactor: file structure, unused fonts; fix: chat streaming, notification stack (#2083)
* improvement: panel tabs handler on click

* fix: output break words

* feat: keyboard navigation; improvement: SEO/GEO; refactor: file structure, unused fonts; fix: chat streaming, notification stack

* feat: unresolved value handling on error; fix: layout refresh; refactor: delete old panel

* refactor: control bar delete; improvement: workflow constants; fix: clear notifications keyboard shortcut

* update developers count

* fixed relative imports

---------

Co-authored-by: waleed <walif6@gmail.com>
2025-11-20 19:37:09 -08:00

49 lines
1.2 KiB
TypeScript

'use client'
import { useEffect } from 'react'
import { createLogger } from '@/lib/logs/console/logger'
const logger = createLogger('RootLayout')
const BROWSER_EXTENSION_ATTRIBUTES = [
'data-new-gr-c-s-check-loaded',
'data-gr-ext-installed',
'data-gr-ext-disabled',
'data-grammarly',
'data-fgm',
'data-lt-installed',
]
/**
* Client component that intercepts console.error to filter and log hydration errors
* while ignoring errors caused by browser extensions.
*/
export function HydrationErrorHandler() {
useEffect(() => {
const originalError = console.error
console.error = (...args) => {
if (args[0].includes('Hydration')) {
const isExtensionError = BROWSER_EXTENSION_ATTRIBUTES.some((attr) =>
args.some((arg) => typeof arg === 'string' && arg.includes(attr))
)
if (!isExtensionError) {
logger.error('Hydration Error', {
details: args,
componentStack: args.find(
(arg) => typeof arg === 'string' && arg.includes('component stack')
),
})
}
}
originalError.apply(console, args)
}
return () => {
console.error = originalError
}
}, [])
return null
}