Files
Joshen Lim 6d08d66b7d Add eslint rule for google translate dynamic spans + address all issues (#52949)
## Context

We've been seeing many `NotFoundError: Failed to execute 'removeChild'
on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on
'Node'` events on Sentry which are historically known to be caused by
Google Translate in the browser.

There's technically no _right way_ to address this unfortunately, but
one of the solutions which should address most of these issues is to
wrap any dynamic text within a span - we've considered that quite a
while back tbh but never took the time to do this until today with the
help of Claude. Although just a heads up that it might not necessarily
completely eradicate those issues.

Also added an eslint rule which should prevent future occurences of this
<img width="1264" height="192" alt="image"
src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29"
/>
2026-11-05 23:28:46 +08:00

30 lines
873 B
TypeScript

import { HTMLAttributes } from 'react'
import { cn } from 'ui'
import { calculateImprovement } from './index-advisor.utils'
interface IndexImprovementTextProps extends HTMLAttributes<HTMLParagraphElement> {
indexStatements: string[]
totalCostBefore: number
totalCostAfter: number
}
export const IndexImprovementText = ({
indexStatements,
totalCostBefore,
totalCostAfter,
className,
...props
}: IndexImprovementTextProps) => {
const improvement = calculateImprovement(totalCostBefore, totalCostAfter)
return (
<p className={cn('text-sm text-foreground-light mb-3', className)} {...props}>
Query's performance can be improved by{' '}
<span className="text-primary">{improvement.toFixed(2)}%</span> by creating this{' '}
{indexStatements.length > 1 ? <span>indexes</span> : <span>index</span>}
<span>:</span>
</p>
)
}