Skip to content

Commit

Permalink
BREAKING CHANGE: React 19 support (#2318)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: React 19 support
  • Loading branch information
CodyJasonBennett authored Feb 19, 2025
1 parent c9d1463 commit eafb38d
Show file tree
Hide file tree
Showing 198 changed files with 1,736 additions and 2,300 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sandboxes": ["4nc1u", "bfplr", "1wh6f"],
"packages": ["dist"],
"node": "18"
"node": "20"
}
6 changes: 3 additions & 3 deletions .storybook/Setup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Vector3 } from 'three'
import { Canvas, Props as CanvasProps } from '@react-three/fiber'
import { Canvas, CanvasProps } from '@react-three/fiber'

import { OrbitControls } from '../src'

Expand All @@ -25,8 +25,8 @@ export const Setup = ({
{children}
{lights && (
<>
<ambientLight intensity={0.8} />
<pointLight intensity={1} position={[0, 6, 0]} />
<ambientLight intensity={0.8 * Math.PI} />
<pointLight intensity={1 * Math.PI} position={[0, 6, 0]} decay={0} />
</>
)}
{controls && <OrbitControls makeDefault />}
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/AccumulativeShadows.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as THREE from 'three'
import * as React from 'react'
import { ComponentProps } from 'react'
import { FlakesTexture } from 'three/examples/jsm/textures/FlakesTexture'
import { FlakesTexture } from 'three-stdlib'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
Expand Down Expand Up @@ -48,7 +48,7 @@ function Suzi(props: ComponentProps<'group'>) {
material.color.set('orange')
material.roughness = 0
material.normalMap = new THREE.CanvasTexture(
new FlakesTexture(),
new FlakesTexture() as HTMLCanvasElement,
THREE.UVMapping,
THREE.RepeatWrapping,
THREE.RepeatWrapping
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Adaptive.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function AdaptiveScene(props: ComponentProps<typeof AdaptiveDpr>) {
<Archer />
</Suspense>
<directionalLight
intensity={0.2}
intensity={0.2 * Math.PI}
position={[10, 10, 5]}
shadow-mapSize-width={64}
shadow-mapSize-height={64}
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/ArcballControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CustomCamera = ({ ...props }: ComponentProps<typeof ArcballControls>) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<OrthographicCamera | PerspectiveCameraType>()
const virtualCamera = useRef<PerspectiveCameraType>(null!)
const [virtualScene] = useState(() => new Scene())

useFrame(({ gl }) => {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/BBAnchor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function BBAnchorScene({
drawBoundingBox: boolean
children?: React.ReactNode
}) {
const ref = React.useRef(null)
const ref = React.useRef<THREE.Mesh<THREE.IcosahedronGeometry>>(null!)

useHelper(drawBoundingBox && ref, BoxHelper, 'cyan')

Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Bvh.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
type Story = StoryObj<typeof Bvh>

function TorusBVH({ z = 0, ...props }: { z: number } & React.ComponentProps<typeof Bvh>) {
const mesh = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const mesh = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

useHelper(mesh, MeshBVHHelper)

Expand Down Expand Up @@ -122,7 +122,7 @@ const DebugRayCast = ({ grp }) => {
}

function Scene(props: React.ComponentProps<typeof Bvh>) {
const grp = React.useRef<React.ElementRef<'group'>>(null)
const grp = React.useRef<React.ComponentRef<'group'>>(null)

const { raycaster } = useThree()
raycaster.firstHitOnly = true
Expand Down
8 changes: 4 additions & 4 deletions .storybook/stories/CameraControls.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createPortal, useFrame } from '@react-three/fiber'
import React, { ComponentProps, useRef, useState } from 'react'
import { Scene } from 'three'
import * as THREE from 'three'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
Expand Down Expand Up @@ -47,9 +47,9 @@ const CameraControlsScene2 = (props: ComponentProps<typeof CameraControls>) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<CameraControls['camera']>()
const [virtualScene] = useState(() => new Scene())
const cameraControlRef = useRef<CameraControls>(null)
const virtualCamera = useRef<THREE.PerspectiveCamera>(null!)
const [virtualScene] = useState(() => new THREE.Scene())
const cameraControlRef = useRef<CameraControls>(null!)

useFrame(({ gl }) => {
if (virtualCamera.current) {
Expand Down
12 changes: 5 additions & 7 deletions .storybook/stories/CubeCamera.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ export default {

type Story = StoryObj<typeof CubeCamera>

declare global {
namespace JSX {
interface IntrinsicElements {
axisHelper: object
}
declare module '@react-three/fiber' {
interface ThreeElements {
axisHelper: object
}
}

function Sphere({ offset = 0, ...props }: ComponentProps<typeof CubeCamera> & { offset?: number }) {
const ref = React.useRef<React.ElementRef<'mesh'>>(null)
const ref = React.useRef<THREE.Mesh>(null!)
useFrame(({ clock }) => {
ref.current!.position.y = Math.sin(offset + clock.elapsedTime) * 5
ref.current.position.y = Math.sin(offset + clock.elapsedTime) * 5
})

return (
Expand Down
10 changes: 4 additions & 6 deletions .storybook/stories/CurveModifier.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import { CurveModifier, CurveModifierRef } from '../../src'

extend({ StdText: TextGeometry })

type TextGeometryImpl = JSX.IntrinsicElements['extrudeGeometry'] & {
type TextGeometryImpl = ThreeElements['extrudeGeometry'] & {
args: [string, TextGeometryParameters]
}

declare global {
namespace JSX {
interface IntrinsicElements {
stdText: TextGeometryImpl
}
declare module '@react-three/fiber' {
interface ThreeElements {
stdText: TextGeometryImpl
}
}

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Extrude.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Extrude>

function ExtrudeScene(props: React.ComponentProps<typeof Extrude>) {
const ref = useTurntable<React.ElementRef<typeof Extrude>>()
const ref = useTurntable<React.ComponentRef<typeof Extrude>>()

return (
<>
Expand Down
8 changes: 4 additions & 4 deletions .storybook/stories/FaceControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as easing from 'maath/easing'
import { Setup } from '../Setup'

import { FaceLandmarker, FaceControls, Box, WebcamVideoTexture } from '../../src'
import { ComponentProps, ElementRef, useRef, useState } from 'react'
import { ComponentProps, ComponentRef, useRef, useState } from 'react'
import { FaceLandmarkerResult } from '@mediapipe/tasks-vision'
import { useFrame, useThree } from '@react-three/fiber'

Expand Down Expand Up @@ -55,8 +55,8 @@ export const FaceControlsSt = {
//

function FaceControlsScene2(props: ComponentProps<typeof FaceControls>) {
const faceLandmarkerRef = useRef<ElementRef<typeof FaceLandmarker>>(null)
const videoTextureRef = useRef<ElementRef<typeof WebcamVideoTexture>>(null)
const faceLandmarkerRef = useRef<ComponentRef<typeof FaceLandmarker>>(null)
const videoTextureRef = useRef<ComponentRef<typeof WebcamVideoTexture>>(null)

const [faceLandmarkerResult, setFaceLandmarkerResult] = useState<FaceLandmarkerResult>()

Expand Down Expand Up @@ -99,7 +99,7 @@ export const FaceControlsSt2 = {
//

function FaceControlsScene3(props: ComponentProps<typeof FaceControls>) {
const faceControlsRef = useRef<ElementRef<typeof FaceControls>>(null)
const faceControlsRef = useRef<ComponentRef<typeof FaceControls>>(null)

const camera = useThree((state) => state.camera)
const [current] = useState(() => new THREE.Object3D())
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Fbo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Fbo>

function SpinningThing() {
const mesh = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const mesh = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

useFrame(() => {
mesh.current.rotation.x = mesh.current.rotation.y = mesh.current.rotation.z += 0.01
Expand All @@ -40,7 +40,7 @@ function FboScene(props: React.ComponentProps<typeof Fbo>) {
}

function TargetWrapper({ target }: { target: THREE.WebGLRenderTarget }) {
const cam = React.useRef<React.ElementRef<typeof PerspectiveCamera>>(null!)
const cam = React.useRef<React.ComponentRef<typeof PerspectiveCamera>>(null!)

const scene = React.useMemo(() => {
const scene = new THREE.Scene()
Expand Down
14 changes: 7 additions & 7 deletions .storybook/stories/HTML.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function HTMLScene({
color?: React.ComponentProps<'meshBasicMaterial'>['color']
children?: React.ReactNode
} & HtmlProps) {
const ref = useTurntable<React.ElementRef<'group'>>()
const ref = useTurntable<React.ComponentRef<'group'>>()

return (
<group ref={ref}>
Expand Down Expand Up @@ -123,8 +123,8 @@ function HTMLOrthographicScene(props: HtmlProps) {
<Html {...props}>Orthographic</Html>
}
</Icosahedron>
<ambientLight intensity={0.8} />
<pointLight intensity={1} position={[0, 6, 0]} />
<ambientLight intensity={0.8 * Math.PI} />
<pointLight intensity={1 * Math.PI} position={[0, 6, 0]} decay={0} />
</>
)
}
Expand Down Expand Up @@ -164,8 +164,8 @@ export const HTMLCalculatePositionSt = {
//

function HTMLOccluderScene(props: HtmlProps) {
const turntableRef = useTurntable<React.ElementRef<'group'>>()
const occluderRef = React.useRef<React.ElementRef<typeof Icosahedron>>(null)
const turntableRef = useTurntable<React.ComponentRef<'group'>>()
const occluderRef = React.useRef<React.ComponentRef<typeof Icosahedron>>(null)

return (
<>
Expand Down Expand Up @@ -195,8 +195,8 @@ function HTMLOccluderScene(props: HtmlProps) {
</Html>
</Icosahedron>
</group>
<ambientLight intensity={0.8} />
<pointLight intensity={1} position={[0, 6, 0]} />
<ambientLight intensity={0.8 * Math.PI} />
<pointLight intensity={1 * Math.PI} position={[0, 6, 0]} decay={0} />
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Lathe.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Lathe>

function LatheScene(props: React.ComponentProps<typeof Lathe>) {
const ref = useTurntable<React.ElementRef<typeof Lathe>>()
const ref = useTurntable<React.ComponentRef<typeof Lathe>>()

return (
<Lathe ref={ref} {...props}>
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/MarchingCubes.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function MarchingCubesScene({
planeY?: boolean
planeZ?: boolean
} & React.ComponentProps<typeof MarchingCubes>) {
const cubeRefOne = React.useRef<React.ElementRef<typeof MarchingCube>>(null)
const cubeRefTwo = React.useRef<React.ElementRef<typeof MarchingCube>>(null)
const cubeRefOne = React.useRef<React.ComponentRef<typeof MarchingCube>>(null)
const cubeRefTwo = React.useRef<React.ComponentRef<typeof MarchingCube>>(null)

useFrame(({ clock }) => {
if (!cubeRefOne.current || !cubeRefTwo.current) return
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/MeshDistortMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const MeshDistortMaterialSt = {
//

function MeshDistortMaterialRefScene(props: React.ComponentProps<typeof MeshDistortMaterial>) {
const material = React.useRef<React.ElementRef<typeof MeshDistortMaterial>>(null!)
const material = React.useRef<React.ComponentRef<typeof MeshDistortMaterial>>(null!)

useFrame(({ clock }) => {
material.current.distort = Math.sin(clock.getElapsedTime())
Expand Down
17 changes: 12 additions & 5 deletions .storybook/stories/MeshRefractionMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Diamond({
rotation: React.ComponentProps<'mesh'>['rotation']
position: React.ComponentProps<'mesh'>['position']
} & React.ComponentProps<typeof MeshRefractionMaterial>) {
const ref = React.useRef<React.ElementRef<'mesh'>>(null)
const ref = React.useRef<React.ComponentRef<'mesh'>>(null)
const { nodes } = useGLTF('/dflat.glb') as any
// Use a custom envmap/scene-backdrop for the diamond material
// This way we can have a clear BG while cube-cam can still film other objects
Expand Down Expand Up @@ -74,9 +74,9 @@ function RefractionScene(props: React.ComponentProps<typeof MeshRefractionMateri
return (
<>
<color attach="background" args={['#f0f0f0']} />
<ambientLight intensity={0.5} />
<spotLight position={[5, 5, -10]} angle={0.15} penumbra={1} />
<pointLight position={[-10, -10, -10]} />
<ambientLight intensity={0.5 * Math.PI} />
<spotLight position={[5, 5, -10]} angle={0.15} penumbra={1} decay={0} />
<pointLight position={[-10, -10, -10]} decay={0} />

<Diamond rotation={[0, 0, 0.715]} position={[0, -0.175 + 0.5, 0]} {...props} />

Expand Down Expand Up @@ -110,7 +110,14 @@ function RefractionScene(props: React.ComponentProps<typeof MeshRefractionMateri
scale={12}
position={[0, -0.5, 0]}
>
<RandomizedLight amount={8} radius={10} ambient={0.5} intensity={1} position={[5, 5, -10]} bias={0.001} />
<RandomizedLight
amount={8}
radius={10}
ambient={0.5}
intensity={1 * Math.PI}
position={[5, 5, -10]}
bias={0.001}
/>
</AccumulativeShadows>
<Environment files="https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/1k/aerodynamics_workshop_1k.hdr" />
<OrbitControls makeDefault autoRotate autoRotateSpeed={0.1} minPolarAngle={0} maxPolarAngle={Math.PI / 2} />
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/MeshTransmissionMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function GelatinousCube(props: React.ComponentProps<typeof MeshTransmissionMater
function MeshTransmissionMaterialScene(props: React.ComponentProps<typeof MeshTransmissionMaterial>) {
return (
<>
<ambientLight />
<ambientLight intensity={Math.PI} />
<group position={[0, -2.5, 0]}>
<Center top>
<GelatinousCube {...props} />
Expand All @@ -70,7 +70,7 @@ function MeshTransmissionMaterialScene(props: React.ComponentProps<typeof MeshTr
opacity={0.8}
scale={20}
>
<RandomizedLight radius={10} ambient={0.5} intensity={1} position={[2.5, 8, -2.5]} bias={0.001} />
<RandomizedLight radius={10} ambient={0.5} intensity={1 * Math.PI} position={[2.5, 8, -2.5]} bias={0.001} />
</AccumulativeShadows>
</group>
<OrbitControls minPolarAngle={0} maxPolarAngle={Math.PI / 2} autoRotate autoRotateSpeed={0.05} makeDefault />
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/MeshWobbleMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const MeshWobbleMaterialSt = {
//

function MeshWobbleMaterialRefScene(props: React.ComponentProps<typeof MeshWobbleMaterial>) {
const material = React.useRef<React.ElementRef<typeof MeshWobbleMaterial>>(null)
const material = React.useRef<React.ComponentRef<typeof MeshWobbleMaterial>>(null)

useFrame(({ clock }) => {
if (material.current === null) return
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/OrbitControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CustomCamera = (props: OrbitControlsProps) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<React.ElementRef<typeof PerspectiveCamera> | null>(null)
const virtualCamera = useRef<React.ComponentRef<typeof PerspectiveCamera> | null>(null)
const [virtualScene] = useState(() => new Scene())

useFrame(({ gl }) => {
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Reflector.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ReflectorScene({
const roughnessMap = useTexture('roughness_floor.jpeg')
const normalMap = useTexture('NORM.jpg')
const distortionMap = useTexture('dist_map.jpeg')
const $box = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const $box = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

React.useEffect(() => {
distortionMap.wrapS = distortionMap.wrapT = RepeatWrapping
Expand Down Expand Up @@ -76,7 +76,7 @@ function ReflectorScene({
<TorusKnot args={[0.5, 0.2, 128, 32]} ref={$box} position={[0, 1, 0]}>
<meshPhysicalMaterial color="hotpink" />
</TorusKnot>
<spotLight intensity={1} position={[10, 6, 10]} penumbra={1} angle={0.3} />
<spotLight intensity={1 * Math.PI} position={[10, 6, 10]} penumbra={1} angle={0.3} decay={0} />
<Environment preset="city" />
</>
)
Expand Down
6 changes: 3 additions & 3 deletions .storybook/stories/RoundedBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof RoundedBox>

function RoundedBoxScene(props: React.ComponentProps<typeof RoundedBox>) {
const ref = useTurntable<React.ElementRef<typeof RoundedBox>>()
const ref = useTurntable<React.ComponentRef<typeof RoundedBox>>()

return (
<RoundedBox ref={ref} {...props}>
Expand All @@ -44,11 +44,11 @@ export const RoundedBoxSt = {
//

function RoundedBoxScene2(props: React.ComponentProps<typeof RoundedBox>) {
const ref = useTurntable<React.ElementRef<typeof RoundedBox>>()
const ref = useTurntable<React.ComponentRef<typeof RoundedBox>>()

return (
<>
<spotLight position={[35, 35, 35]} intensity={2} />
<spotLight position={[35, 35, 35]} intensity={2 * Math.PI} decay={0} />
<RoundedBox ref={ref} {...props}>
<meshPhongMaterial color="#f3f3f3" />
</RoundedBox>
Expand Down
Loading

0 comments on commit eafb38d

Please sign in to comment.