Skip to content

Commit

Permalink
React 19-compatible types (#2930)
Browse files Browse the repository at this point in the history
* Incorporating makefile changes

* Fixing ref types and replacing ReactHTML reference in Reorder

* Updating types

* Changing HTML types

* Fixing tests
  • Loading branch information
mattgperry authored Dec 9, 2024
1 parent 49a5442 commit c46dc47
Show file tree
Hide file tree
Showing 23 changed files with 172 additions and 196 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Motion adheres to [Semantic Versioning](http://semver.org/).

Undocumented APIs should be considered internal and may change without warning.

## [11.13.3] 2024-12-09

### Fixed

- Attempting to update types to be compatible with both React 18 and 19.

## [11.13.2] 2024-12-04

### Fixed
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WORKTREE_NODE_MODULES := $(BASE_DIR)/node_modules/.yarn-state.yml
WORKSPACE_NODE_MODULES := node_modules

# Update node modules if package.json is newer than node_modules or yarn lockfile
$(WORKTREE_NODE_MODULES) $(WORKSPACE_NODE_MODULES): $(BASE_DIR)/yarn.lock package.json packages/framer-motion/package.json packages/framer-motion-3d/package.json
$(WORKTREE_NODE_MODULES) $(WORKSPACE_NODE_MODULES): $(BASE_DIR)/yarn.lock package.json packages/framer-motion/package.json
yarn install
touch $@

Expand All @@ -38,8 +38,6 @@ $(WORKTREE_NODE_MODULES) $(WORKSPACE_NODE_MODULES): $(BASE_DIR)/yarn.lock packag
# Makefile
bootstrap:: $(WORKTREE_NODE_MODULES)

SOURCE_FILES := $(shell find packages/framer-motion/src packages/framer-motion-3d/src -type f)

######

# The location to gather test reports
Expand Down
2 changes: 1 addition & 1 deletion dev/html/public/optimized-appear/portal.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
(animation) => {
// Hydrate root mid-way through animation
setTimeout(() => {
ReactDOM.createRoot(
ReactDOMClient.createRoot(
document.getElementById("portal")
).render(
React.createElement(motion.div, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const child = {
}

export const App = () => {
const ref = useRef()
const ref = useRef(null)
return (
<div ref={ref} style={container}>
<motion.div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const child = {
}

export const App = () => {
const ref = useRef()
const ref = useRef(null)
return (
<div ref={ref} style={container}>
<motion.div
Expand Down
2 changes: 1 addition & 1 deletion dev/react/src/examples/Drag-constraints-ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SiblingLayoutAnimation = () => {
}

export const App = () => {
const ref = useRef()
const ref = useRef(null)
const [count, setCount] = useState(0)
return (
<>
Expand Down
16 changes: 8 additions & 8 deletions dev/react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import React from "react"
import ReactDOMClient from "react-dom/client"
import App from "./App.tsx"
import "./index.css"

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
ReactDOMClient.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
2 changes: 1 addition & 1 deletion dev/react/src/tests/scroll-callback-element-x.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const width = 400

export const App = () => {
const [progress, setProgress] = useState(0)
const ref = useRef<Element>(null)
const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
if (!ref.current) return
Expand Down
3 changes: 2 additions & 1 deletion dev/react/src/tests/scroll-callback-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const height = 400

export const App = () => {
const [progress, setProgress] = useState(0)
const ref = useRef(null)
const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
if (!ref.current) return
return scroll(setProgress, { source: ref.current })
}, [])

Expand Down
2 changes: 1 addition & 1 deletion packages/framer-motion-3d/src/components/MotionCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function CanvasComponent(
// Throw exception outwards if anything within canvas throws
if (error) throw error

const root = useRef<ReconcilerRoot<HTMLCanvasElement>>()
const root = useRef<ReconcilerRoot<HTMLCanvasElement> | null>(null)
if (size.width > 0 && size.height > 0) {
if (!root.current) {
root.current = createRoot(canvasRef.current)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useLayoutCamera<CameraType>(
const size = useThree((three) => three.size)
const gl = useThree((three) => three.gl)
const { visualElement: parentVisualElement } = useContext(MotionContext)
const measuredLayoutSize = useRef<Size>()
const measuredLayoutSize = useRef<Size | undefined>(undefined)

useLayoutEffect(() => {
measuredLayoutSize.current = size
Expand Down
11 changes: 3 additions & 8 deletions packages/framer-motion/src/components/Reorder/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import { invariant } from "motion-utils"
import * as React from "react"
import {
forwardRef,
FunctionComponent,
ReactHTML,
useEffect,
useRef,
} from "react"
import { forwardRef, FunctionComponent, useEffect, useRef } from "react"
import type { HTMLElements } from "../../render/html/supported-elements"
import { ReorderContext } from "../../context/ReorderContext"
import { motion } from "../../render/components/motion/proxy"
import { HTMLMotionProps } from "../../render/html/types"
Expand All @@ -22,7 +17,7 @@ export interface Props<V> {
*
* @public
*/
as?: keyof ReactHTML
as?: keyof HTMLElements

/**
* The axis to reorder along. By default, items will be draggable on this axis.
Expand Down
5 changes: 3 additions & 2 deletions packages/framer-motion/src/components/Reorder/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

import { invariant } from "motion-utils"
import * as React from "react"
import { ReactHTML, FunctionComponent, useContext, forwardRef } from "react"
import { FunctionComponent, useContext, forwardRef } from "react"
import { ReorderContext } from "../../context/ReorderContext"
import { motion } from "../../render/components/motion/proxy"
import { HTMLMotionProps } from "../../render/html/types"
import { useConstant } from "../../utils/use-constant"
import { useMotionValue } from "../../value/use-motion-value"
import { useTransform } from "../../value/use-transform"
import { isMotionValue } from "../../value/utils/is-motion-value"
import { HTMLElements } from "../../render/html/supported-elements"

export interface Props<V> {
/**
* A HTML element to render this component as. Defaults to `"li"`.
*
* @public
*/
as?: keyof ReactHTML
as?: keyof HTMLElements

/**
* The value in the list that this component represents.
Expand Down
2 changes: 1 addition & 1 deletion packages/framer-motion/src/events/use-dom-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { addDomEvent } from "./add-dom-event"
* @public
*/
export function useDomEvent(
ref: RefObject<EventTarget>,
ref: RefObject<EventTarget | null>,
eventName: string,
handler?: EventListener | undefined,
options?: AddEventListenerOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/framer-motion/src/gestures/drag/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export interface DraggableProps extends DragHandlers {
* }
* ```
*/
dragConstraints?: false | Partial<BoundingBox> | RefObject<Element>
dragConstraints?: false | Partial<BoundingBox> | RefObject<Element | null>

/**
* The degree of movement allowed outside constraints. 0 = no movement, 1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ViewportEventHandler = (
) => void

export interface ViewportOptions {
root?: RefObject<Element>
root?: RefObject<Element | null>
once?: boolean
margin?: string
amount?: "some" | "all" | number
Expand Down
4 changes: 2 additions & 2 deletions packages/framer-motion/src/motion/utils/use-visual-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useVisualElement<Instance, RenderState>(
const presenceContext = useContext(PresenceContext)
const reducedMotionConfig = useContext(MotionConfigContext).reducedMotion

const visualElementRef = useRef<VisualElement<Instance>>()
const visualElementRef = useRef<VisualElement<Instance> | null>(null)

/**
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
Expand Down Expand Up @@ -137,7 +137,7 @@ export function useVisualElement<Instance, RenderState>(
}
})

return visualElement
return visualElement!
}

function createProjectionNode(
Expand Down
Loading

0 comments on commit c46dc47

Please sign in to comment.