Skip to content

Commit

Permalink
fix: Stats and StatsGl don't remove previous class names on rerender (#…
Browse files Browse the repository at this point in the history
…1994)

* fix(StatsGl): remove class names on useEffect cleanup

* fix(Stats): remove class names on useEffect cleanup
  • Loading branch information
lukehorvat committed Jun 15, 2024
1 parent 1bb5b95 commit 18c24eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export function Stats({ showPanel = 0, className, parent }: Props): null {
const node = (parent && parent.current) || document.body
stats.showPanel(showPanel)
node?.appendChild(stats.dom)
if (className) stats.dom.classList.add(...className.split(' ').filter((cls) => cls))
const classNames = (className ?? '').split(' ').filter((cls) => cls)
if (classNames.length) stats.dom.classList.add(...classNames)
const begin = addEffect(() => stats.begin())
const end = addAfterEffect(() => stats.end())
return () => {
if (classNames.length) stats.dom.classList.remove(...classNames)
node?.removeChild(stats.dom)
begin()
end()
Expand Down
4 changes: 3 additions & 1 deletion src/core/StatsGl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export function StatsGl({ className, parent, ...props }: Props) {
if (stats) {
const node = (parent && parent.current) || document.body
node?.appendChild(stats.dom)
if (className) stats.container.classList.add(...className.split(' ').filter((cls) => cls))
const classNames = (className ?? '').split(' ').filter((cls) => cls)
if (classNames.length) stats.dom.classList.add(...classNames)
const end = addAfterEffect(() => stats.update())
return () => {
if (classNames.length) stats.dom.classList.remove(...classNames)
node?.removeChild(stats.dom)
end()
}
Expand Down

0 comments on commit 18c24eb

Please sign in to comment.