Skip to content

Commit c1620b8

Browse files
feat: use stats-gl v2 (#1749)
1 parent 2c0c7a2 commit c1620b8

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"meshline": "^3.1.6",
7272
"react-composer": "^5.0.3",
7373
"react-merge-refs": "^1.1.0",
74-
"stats-gl": "^1.0.4",
74+
"stats-gl": "^2.0.0",
7575
"stats.js": "^0.17.0",
7676
"suspend-react": "^0.1.3",
7777
"three-mesh-bvh": "^0.6.7",

src/core/StatsGl.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { addEffect, addAfterEffect, useThree } from '@react-three/fiber'
2+
import { addAfterEffect, useThree } from '@react-three/fiber'
33
import Stats from 'stats-gl'
44

55
type Props = Partial<Stats> & {
@@ -9,26 +9,24 @@ type Props = Partial<Stats> & {
99
}
1010

1111
export function StatsGl({ className, parent, ...props }: Props) {
12-
const gl = useThree((state) => state.gl)
12+
const gl: any = useThree((state) => state.gl)
1313

1414
const stats = React.useMemo(() => {
1515
const stats = new Stats({
1616
...props,
1717
})
18-
stats.init(gl.domElement)
18+
stats.init(gl)
1919
return stats
2020
}, [gl])
2121

2222
React.useEffect(() => {
2323
if (stats) {
2424
const node = (parent && parent.current) || document.body
25-
node?.appendChild(stats.container)
25+
node?.appendChild(stats.dom)
2626
if (className) stats.container.classList.add(...className.split(' ').filter((cls) => cls))
27-
const begin = addEffect(() => stats.begin())
28-
const end = addAfterEffect(() => stats.end())
27+
const end = addAfterEffect(() => stats.update())
2928
return () => {
30-
node?.removeChild(stats.container)
31-
begin()
29+
node?.removeChild(stats.dom)
3230
end()
3331
}
3432
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12635,10 +12635,10 @@ static-extend@^0.1.1:
1263512635
define-property "^0.2.5"
1263612636
object-copy "^0.1.0"
1263712637

12638-
stats-gl@^1.0.4:
12639-
version "1.0.5"
12640-
resolved "https://registry.yarnpkg.com/stats-gl/-/stats-gl-1.0.5.tgz#7f2b6688cc37b3d4bc79749ab122c063528be9c3"
12641-
integrity sha512-XimMxvwnf1Qf5KwebhcoA34kcX+fWEkIl0QjNkCbu4IpoyDMMsOajExn7FIq5w569k45+LhmsuRlGSrsvmGdNw==
12638+
stats-gl@^2.0.0:
12639+
version "2.0.0"
12640+
resolved "https://registry.yarnpkg.com/stats-gl/-/stats-gl-2.0.0.tgz#50788125495b54762fd0a0dabe6fdcb12cee73b1"
12641+
integrity sha512-fDUcbOmcdTJspBBw8BAXXICSpQbL4nbfBdYCWHWoimnfguHmIH3xH+HBCJBjewDOy2EzTJYw3e5fnbALIKTiQA==
1264212642

1264312643
stats.js@^0.17.0:
1264412644
version "0.17.0"

0 commit comments

Comments
 (0)