Skip to content

Commit 18c24eb

Browse files
authored
fix: Stats and StatsGl don't remove previous class names on rerender (#1994)
* fix(StatsGl): remove class names on useEffect cleanup * fix(Stats): remove class names on useEffect cleanup
1 parent 1bb5b95 commit 18c24eb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/core/Stats.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export function Stats({ showPanel = 0, className, parent }: Props): null {
1717
const node = (parent && parent.current) || document.body
1818
stats.showPanel(showPanel)
1919
node?.appendChild(stats.dom)
20-
if (className) stats.dom.classList.add(...className.split(' ').filter((cls) => cls))
20+
const classNames = (className ?? '').split(' ').filter((cls) => cls)
21+
if (classNames.length) stats.dom.classList.add(...classNames)
2122
const begin = addEffect(() => stats.begin())
2223
const end = addAfterEffect(() => stats.end())
2324
return () => {
25+
if (classNames.length) stats.dom.classList.remove(...classNames)
2426
node?.removeChild(stats.dom)
2527
begin()
2628
end()

src/core/StatsGl.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ export function StatsGl({ className, parent, ...props }: Props) {
2323
if (stats) {
2424
const node = (parent && parent.current) || document.body
2525
node?.appendChild(stats.dom)
26-
if (className) stats.container.classList.add(...className.split(' ').filter((cls) => cls))
26+
const classNames = (className ?? '').split(' ').filter((cls) => cls)
27+
if (classNames.length) stats.dom.classList.add(...classNames)
2728
const end = addAfterEffect(() => stats.update())
2829
return () => {
30+
if (classNames.length) stats.dom.classList.remove(...classNames)
2931
node?.removeChild(stats.dom)
3032
end()
3133
}

0 commit comments

Comments
 (0)