Skip to content

Commit

Permalink
fix: full support react 19 typings
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 3, 2025
1 parent 9d68dad commit 735d7a1
Show file tree
Hide file tree
Showing 152 changed files with 319 additions and 323 deletions.
4 changes: 2 additions & 2 deletions dev/embedded-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"styled-components": "^6.1.0"
},
"devDependencies": {
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.4",
"typescript": "5.7.2",
"vite": "^5.4.11"
Expand Down
6 changes: 5 additions & 1 deletion dev/test-next-studio/app/registry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {useServerInsertedHTML} from 'next/navigation'
import {useState, useSyncExternalStore} from 'react'
import {ServerStyleSheet, StyleSheetManager} from 'styled-components'

export function StyledComponentsRegistry({children}: {children: React.ReactNode}): JSX.Element {
export function StyledComponentsRegistry({
children,
}: {
children: React.ReactNode
}): React.JSX.Element {
const isMounted = useSyncExternalStore(
emptySubscribe,
() => true,
Expand Down
2 changes: 1 addition & 1 deletion dev/test-studio/preview/FieldGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Box, Card, Stack, Text} from '@sanity/ui'

import {useQuery} from './loader'

export function FieldGroups(): JSX.Element {
export function FieldGroups(): React.JSX.Element {
const {data, loading, error} = useQuery<
{
_id: string
Expand Down
2 changes: 1 addition & 1 deletion dev/test-studio/preview/SimpleBlockPortableText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const components: PortableTextComponents = {
},
}

export function SimpleBlockPortableText(): JSX.Element {
export function SimpleBlockPortableText(): React.JSX.Element {
const {data, loading, error} = useQuery<
{
_id: string
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"@types/glob": "^7.2.0",
"@types/lodash": "^4.17.7",
"@types/node": "^22.10.0",
"@types/react": "^18.3.12",
"@types/react": "^19.0.2",
"@types/semver": "^7.5.6",
"@types/yargs": "^17.0.7",
"@typescript-eslint/eslint-plugin": "^7.18.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/@sanity/block-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
},
"dependencies": {
"@sanity/types": "3.68.3",
"@types/react": "^18.3.5",
"get-random-values-esm": "1.0.2",
"lodash": "^4.17.21"
},
Expand All @@ -60,11 +59,15 @@
"@sanity/schema": "3.68.3",
"@types/jsdom": "^20.0.0",
"@types/lodash": "^4.17.7",
"@types/react": "^19.0.2",
"@vercel/stega": "0.1.2",
"@vitest/coverage-v8": "^2.1.1",
"jsdom": "^23.0.1",
"vitest": "^2.1.8"
},
"peerDependencies": {
"@types/react": "18 || 19"
},
"publishConfig": {
"access": "public"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/cli/test/test-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"@sanity/vision": "^3.62.0",
"@tailwindcss/typography": "^0.5.15",
"@types/node": "^22.7.8",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vercel/speed-insights": "^1.0.13",
"autoprefixer": "^10.4.20",
"date-fns": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@sanity/icons": "^3.5.7",
"@types/lodash": "^4.17.7",
"@types/object-inspect": "^1.13.0",
"@types/react": "^18.3.12",
"@types/react": "^19.0.2",
"rimraf": "^5.0.10",
"vitest": "^2.1.8"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@repo/package.config": "workspace:*",
"@repo/test-config": "workspace:*",
"@sanity/insert-menu": "1.0.18",
"@types/react": "^18.3.5",
"@types/react": "^19.0.2",
"@vitejs/plugin-react": "^4.3.4",
"react": "^18.3.1",
"rimraf": "^5.0.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface BaseSchemaTypeOptions {
export interface BaseSchemaDefinition {
name: string
title?: string
description?: string | ReactElement
description?: string | ReactElement<any>
hidden?: ConditionalProperty
readOnly?: ConditionalProperty
icon?: ComponentType | ReactNode
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/vision/src/components/ResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ResultViewWrapper} from './ResultView.styled'

const lru = new LRU({maxSize: 50000})

export function ResultView(props: {data: unknown; datasetName: string}): JSX.Element {
export function ResultView(props: {data: unknown; datasetName: string}): React.JSX.Element {
const {data, datasetName} = props
const workspaceDataset = useDataset()

Expand Down
10 changes: 5 additions & 5 deletions packages/@sanity/vision/src/components/VisionGui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ interface VisionGuiState {
}

export class VisionGui extends PureComponent<VisionGuiProps, VisionGuiState> {
_visionRoot: RefObject<HTMLDivElement>
_queryEditorContainer: RefObject<HTMLDivElement>
_paramsEditorContainer: RefObject<HTMLDivElement>
_operationUrlElement: RefObject<HTMLInputElement>
_customApiVersionElement: RefObject<HTMLInputElement>
_visionRoot: RefObject<HTMLDivElement | null>
_queryEditorContainer: RefObject<HTMLDivElement | null>
_paramsEditorContainer: RefObject<HTMLDivElement | null>
_operationUrlElement: RefObject<HTMLInputElement | null>
_customApiVersionElement: RefObject<HTMLInputElement | null>
_resizeListener: ResizeObserver | undefined
_querySubscription: Subscription | undefined
_listenSubscription: Subscription | undefined
Expand Down
6 changes: 3 additions & 3 deletions packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"@sentry/react": "^8.33.0",
"@tanstack/react-table": "^8.16.0",
"@tanstack/react-virtual": "^3.11.2",
"@types/react-is": "^18.3.0",
"@types/react-is": "^19.0.0",
"@types/shallow-equals": "^1.0.0",
"@types/speakingurl": "^13.0.3",
"@types/tar-stream": "^3.1.3",
Expand Down Expand Up @@ -288,8 +288,8 @@
"@types/log-symbols": "^2.0.0",
"@types/node": "^22.10.0",
"@types/raf": "^3.4.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@types/refractor": "^3.0.0",
"@types/resolve-from": "^4.0.0",
"@types/semver": "^6.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ interface TreeEditingStoryProps {
value?: SanityDocument
}

export function TreeEditingStory(props: TreeEditingStoryProps): JSX.Element {
export function TreeEditingStory(props: TreeEditingStoryProps): React.JSX.Element {
const {legacyEditing, openPath, value} = props

const types = getSchemaTypes({legacyEditing})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const StyledChangeConnectorRoot = styled(ChangeConnectorRoot)`
* @description This component is used to wrap all tests in the providers it needs to be able to run successfully.
* It provides a mock Sanity client and a mock workspace.
*/
export const TestWrapper = (props: TestWrapperProps): JSX.Element | null => {
export const TestWrapper = (props: TestWrapperProps): React.JSX.Element | null => {
const {children, schemaTypes, betaFeatures} = props
const [mockWorkspace, setMockWorkspace] = useState<Workspace | null>(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface PackageInfo {
// NOTE: when doing changes here, also remember to update versions in help docs at
// https://sanity.io/admin/structure/docs;helpArticle;upgrade-packages
const PACKAGES = [
{name: 'react', supported: ['^18'], deprecatedBelow: null},
{name: 'react-dom', supported: ['^18'], deprecatedBelow: null},
{name: 'react', supported: ['^18 || ^19'], deprecatedBelow: null},
{name: 'react-dom', supported: ['^18 || ^19'], deprecatedBelow: null},
{name: 'styled-components', supported: ['^6'], deprecatedBelow: null},
{name: '@sanity/ui', supported: ['^2'], deprecatedBelow: null},
]
Expand Down
4 changes: 2 additions & 2 deletions packages/sanity/src/_internal/manifest/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ interface SchemaIconProps {
subtitle?: string
}

const SchemaIcon = ({icon, title, subtitle}: SchemaIconProps): JSX.Element => {
const SchemaIcon = ({icon, title, subtitle}: SchemaIconProps): React.JSX.Element => {
return <ThemeProvider theme={theme}>{normalizeIcon(icon, title, subtitle)}</ThemeProvider>
}

function normalizeIcon(
Icon: ComponentType | ReactNode | undefined,
title: string,
subtitle = '',
): JSX.Element {
): React.JSX.Element {
if (isValidElementType(Icon)) return <Icon />
if (isValidElement(Icon)) return Icon
return createDefaultIcon(title, subtitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const BLOCKS: CommentMessage = [
},
]

export default function CommentsMessageURLSerializerStory(): JSX.Element {
export default function CommentsMessageURLSerializerStory(): React.JSX.Element {
return (
<Container width={1} padding={4} sizing="border">
<Stack space={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface CommentMessageSerializerProps {
* @beta
* @hidden
*/
export function CommentMessageSerializer(props: CommentMessageSerializerProps): JSX.Element {
export function CommentMessageSerializer(props: CommentMessageSerializerProps): React.JSX.Element {
const {blocks} = props

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface NormalBlockProps {
children: ReactNode
}

export function NormalBlock(props: NormalBlockProps): JSX.Element {
export function NormalBlock(props: NormalBlockProps): React.JSX.Element {
const {children} = props

return <NormalText size={1}>{children}</NormalText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface CommentReactionsMenuButtonProps {
open: boolean
tooltipContent: string
t: TFunction
}) => React.ReactElement
}) => React.ReactElement<any>
}

export function CommentReactionsMenuButton(props: CommentReactionsMenuButtonProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function FormattedUserList({currentUserId, userIds}: {currentUserId: string; use
* not special case on _comma_ per se, but rather by the presence of a non-whitespace character.
*/
const parts = listFormat.formatToParts(userIds)
const elements: JSX.Element[] = []
const elements: React.JSX.Element[] = []
for (let i = 0; i < parts.length; i++) {
const item = parts[i]

Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/components/DefaultDocument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const EMPTY_ARRAY: never[] = []
/**
* @hidden
* @beta */
export function DefaultDocument(props: DefaultDocumentProps): ReactElement {
export function DefaultDocument(props: DefaultDocumentProps): ReactElement<any> {
const {entryPath, css = EMPTY_ARRAY} = props

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function WithReferringDocuments({
children,
id,
}: {
children: (props: {isLoading: boolean; referringDocuments: SanityDocument[]}) => ReactElement
children: (props: {isLoading: boolean; referringDocuments: SanityDocument[]}) => ReactElement<any>
/**
* @deprecated - no longer required
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface CollapseMenuProps {
gap?: number | number[]
menuButtonProps?: Omit<MenuButtonProps, 'id' | 'menu' | 'button'> & {
id?: string
button?: ReactElement
button?: ReactElement<any>
}
onMenuClose?: () => void
}
Expand Down Expand Up @@ -73,13 +73,13 @@ const OptionObserveElement = styled(ObserveElement)`
${OPTION_STYLE}
`

function _isReactElement(node: unknown): node is ReactElement {
function _isReactElement(node: unknown): node is ReactElement<any> {
return Boolean(node)
}

interface IntersectionEntry {
intersects: boolean
element: ReactElement
element: ReactElement<any>
// todo: potentially add bounding rects so we can calculate how many we can fit non-collapsed vs collapsed
}

Expand Down Expand Up @@ -126,7 +126,7 @@ export const CollapseMenu = forwardRef(function CollapseMenu(

/** @internal */
export const AutoCollapseMenu = forwardRef(function AutoCollapseMenu(
props: Omit<CollapseMenuProps, 'children' | 'collapsed'> & {menuOptions: ReactElement[]},
props: Omit<CollapseMenuProps, 'children' | 'collapsed'> & {menuOptions: ReactElement<any>[]},
ref: ForwardedRef<HTMLDivElement>,
) {
const {
Expand Down Expand Up @@ -180,7 +180,7 @@ export const AutoCollapseMenu = forwardRef(function AutoCollapseMenu(
)

const handleExpandedIntersection = useCallback(
(e: IntersectionObserverEntry, element: ReactElement) => {
(e: IntersectionObserverEntry, element: ReactElement<any>) => {
setExpandedIntersections((current) => {
const key = element.key
if (key === null) {
Expand All @@ -205,7 +205,7 @@ export const AutoCollapseMenu = forwardRef(function AutoCollapseMenu(
)

const handleCollapsedIntersection = useCallback(
(e: IntersectionObserverEntry, element: ReactElement) => {
(e: IntersectionObserverEntry, element: ReactElement<any>) => {
setCollapsedIntersections((current) => {
const key = element.key
if (key === null) {
Expand Down Expand Up @@ -335,10 +335,10 @@ export const AutoCollapseMenu = forwardRef(function AutoCollapseMenu(
})

const RenderHidden = memo(function RenderHidden(props: {
elements: ReactElement[]
elements: ReactElement<any>[]
gap?: number | number[]
intersectionOptions: IntersectionObserverInit
onIntersectionChange: (e: IntersectionObserverEntry, element: ReactElement) => void
onIntersectionChange: (e: IntersectionObserverEntry, element: ReactElement<any>) => void
}) {
const {elements, gap, intersectionOptions, onIntersectionChange} = props
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Button, type ButtonProps, type TooltipProps} from '../../../ui-component

/** @internal */
export interface CommonProps extends Omit<ButtonProps, 'text' | 'iconRight'> {
as?: ElementType | keyof JSX.IntrinsicElements
as?: ElementType | keyof React.JSX.IntrinsicElements
dividerBefore?: boolean
focused?: boolean
tooltipProps?: TooltipProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const CollapseOverflowMenu = forwardRef(function CollapseOverflowMenu(
props: Pick<
CollapseMenuProps,
'disableRestoreFocusOnClose' | 'menuButtonProps' | 'onMenuClose'
> & {menuOptions: ReactElement[]; menuButton: ReactElement},
> & {menuOptions: ReactElement<any>[]; menuButton: ReactElement<any>},
forwardedRef: ForwardedRef<HTMLButtonElement>,
) {
const {disableRestoreFocusOnClose, menuButton, menuButtonProps, menuOptions, onMenuClose} = props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Flex} from '@sanity/ui'
import {type ReactElement, useEffect, useState} from 'react'

interface ObserveElementProps {
children: ReactElement
children: ReactElement<any>
options?: IntersectionObserverInit
onIntersectionChange: IntersectionObserverCallback
}
Expand Down
Loading

0 comments on commit 735d7a1

Please sign in to comment.