Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update react types #5237

Merged
merged 19 commits into from
Nov 3, 2023
Merged

Update react types #5237

merged 19 commits into from
Nov 3, 2023

Conversation

snowystinger
Copy link
Member

@snowystinger snowystinger commented Oct 12, 2023

Closes #5157

Also handles https://github.com/orgs/adobe/projects/19/views/4?pane=issue&itemId=41163780

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Oct 12, 2023

@@ -46,7 +46,7 @@ function App() {
{(item: any) =>
(<Row key={item.foo} UNSTABLE_childItems={item.childRows}>
{(key) => {
return <Cell>{item[key.toString()]}</Cell>;
return <Cell>{item[key]}</Cell>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -3,7 +3,7 @@ import React from "react";

interface SectionProps {
title: string;
children: JSX.Element | JSX.Element[];
children: React.JSX.Element | React.JSX.Element[];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React got rid of the global namespace, but JSX is still in the React namespace, so reference through that
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L3309

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated but not removed. Doesn't really explain why it broke. Any idea?

Copy link
Member Author

@snowystinger snowystinger Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It broke between RAC alpha 4 and alpha 5 https://unpkg.com/browse/react-aria-components@1.0.0-alpha.5/dist/
Here's the list of commits between those two versions 5911ed2...7186d21

in alpha 4, we exported using the global namespace which included JSX. in alpha 5, we stopped doing that and started exporting the React namespaced version.

I suspect some parcel or update to types in our own repo which caused us to stop using the global namespace, but I haven't nailed it down yet. Upgrading the types caused it to be marked as deprecated in our own code base, but the problem was already present.

I'm following up with the issue author because I suspect they have multiple copies of react types. I suspect users just need to upgrade their types and dedupe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it "broke" in 1123b0f
we upgraded our react/types from 17 to 18, and it seems as though our type generation is smart enough to find the non-global namespace of JSX and prefer that. I'm not sure where that is in the parcel transformer?

I haven't actually "fixed" it in this PR, I think people have to update themselves which is what I followed up with the issue author to do.

In addition to explicit references to the global JSX (RAC DialogTrigger), we also have many implicit references to it. Any inferred component's return value for instance. So if we wanted to "fix" this by using the global JSX namespace again, we'd need to handle both of these.

@@ -31,7 +31,7 @@
"copyrights": "babel-node --presets @babel/env ./scripts/addHeaders.js",
"build:icons": "babel-node --presets @babel/env ./scripts/buildIcons.js",
"clean:icons": "babel-node --presets @babel/env ./scripts/cleanIcons.js",
"postinstall": "yarn build:icons && patch-package",
"postinstall": "patch-package && yarn build:icons",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run first so that we can fix lodash types before icons build since they'll fail if the types are bad

@@ -0,0 +1,2 @@

export type Key = string | number;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this a good place for the type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have just put it in collections.d.ts. But if you want to keep it in a new file you'll need a license header.

@@ -76,7 +76,12 @@ const GROUPS = {
};

export function PropTable({component, links, style}) {
let [ungrouped, groups] = groupProps(component.props.properties);
let ungrouped, groups;
if (!component.props) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what about the typescript update broke this, but some times we now get 'parameters' instead of just 'props'

@@ -6,6 +6,5 @@ export interface LabeledValueProps extends LabeledValueBaseProps {
/** The value to display. */
value: string | string[] | number | RangeValue<number> | DateTime | RangeValue<DateTime>,
/** Formatting options for the value. The available options depend on the type passed to the `value` prop. */
// @ts-ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have gotten rid of these Intl.ListFormatOptions anytime after upgrading ts to v5, may as well remove it here

'no-getByRole-toThrow': noGetByRoleToThrow
'no-getByRole-toThrow': noGetByRoleToThrow,
'no-react-key': noReactKey,
'sort-imports': sortImports
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved in here so i could add some tests more easily

}
-
-// Backward compatibility with --target es5
-declare global {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why lodash has this but I don't think it's needed and it was causing our build to fail because we don't skip lib check

@rspbot
Copy link

rspbot commented Oct 13, 2023

reidbarber
reidbarber previously approved these changes Oct 13, 2023
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's get this in for testing.

@rspbot
Copy link

rspbot commented Oct 14, 2023

@rspbot
Copy link

rspbot commented Oct 15, 2023

reidbarber
reidbarber previously approved these changes Oct 17, 2023
# Conflicts:
#	packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx
#	yarn.lock
@rspbot
Copy link

rspbot commented Oct 26, 2023

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commenting a review here to merge some newline removals nits, will push a separate commit for the rest

packages/@react-aria/dnd/src/useDroppableCollection.ts Outdated Show resolved Hide resolved
packages/@react-aria/grid/src/utils.ts Outdated Show resolved Hide resolved
packages/@react-aria/gridlist/src/useGridList.ts Outdated Show resolved Hide resolved
packages/@react-aria/table/src/TableKeyboardDelegate.ts Outdated Show resolved Hide resolved
packages/@react-aria/tabs/src/TabsKeyboardDelegate.ts Outdated Show resolved Hide resolved
packages/@react-spectrum/card/src/BaseLayout.tsx Outdated Show resolved Hide resolved
@rspbot
Copy link

rspbot commented Oct 26, 2023

LFDanLu
LFDanLu previously approved these changes Oct 26, 2023
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, verified that the new lint rule works as well

@devongovett
Copy link
Member

looks good aside from the undefined.JSX.Element showing up in the docs

@rspbot
Copy link

rspbot commented Oct 27, 2023

# Conflicts:
#	packages/@react-aria/interactions/stories/useFocusRing.stories.tsx
#	packages/@react-aria/tag/src/useTagGroup.ts
#	packages/@react-spectrum/form/stories/Form.stories.tsx
#	packages/@react-types/autocomplete/src/index.d.ts
#	yarn.lock
@snowystinger
Copy link
Member Author

snowystinger commented Oct 27, 2023

looks good aside from the undefined.JSX.Element showing up in the docs

@devongovett fixed

@rspbot
Copy link

rspbot commented Oct 27, 2023

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, verified that the undefined.JSX.Element are fixed. Looks like you've got some conflicts so I'll approve after those are fixed

# Conflicts:
#	packages/react-aria-components/src/Collection.tsx
#	packages/react-aria-components/src/ListBox.tsx
#	packages/react-aria-components/src/utils.tsx
@rspbot
Copy link

rspbot commented Oct 31, 2023

@rspbot
Copy link

rspbot commented Nov 2, 2023

@rspbot
Copy link

rspbot commented Nov 3, 2023

@rspbot
Copy link

rspbot commented Nov 3, 2023

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@react-aria/dnd

DragPreviewProps

 DragPreviewProps {
-  children: (Array<DragItem>) => JSX.Element
+  children: (Array<DragItem>) => React.JSX.Element
 }

useClipboard

 DragPreview {
-  children: (Array<DragItem>) => JSX.Element
+  children: (Array<DragItem>) => React.JSX.Element
 }

@react-spectrum/dnd

DragAndDropOptions

 DragAndDropOptions {
   getItems?: (Set<Key>) => Array<DragItem> = () => []
-  renderPreview?: (Set<Key>, Key) => JSX.Element
+  renderPreview?: (Set<Key>, Key) => React.JSX.Element
 }

it changed:

  • useDragAndDrop

DragAndDropHooks

 DragAndDropHooks {
   dragAndDropHooks: (DragHooks & DropHooks & {
     isVirtualDragging?: () => boolean
-  renderPreview?: (Set<Key>, Key) => JSX.Element
+  renderPreview?: (Set<Key>, Key) => React.JSX.Element
 })
 }

it changed:

  • useDragAndDrop

@react-spectrum/list

ListView

 ListView<T extends {}> {
   density?: 'compact' | 'regular' | 'spacious' = 'regular'
   dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks']
   isQuiet?: boolean
   loadingState?: LoadingState
   onAction?: (Key) => void
   overflowMode?: 'truncate' | 'wrap' = 'truncate'
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

SpectrumListViewProps

 SpectrumListViewProps<T> {
   density?: 'compact' | 'regular' | 'spacious' = 'regular'
   dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks']
   isQuiet?: boolean
   loadingState?: LoadingState
   onAction?: (Key) => void
   overflowMode?: 'truncate' | 'wrap' = 'truncate'
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

@react-spectrum/table

Column

 TableView<T extends {}> {
   density?: 'compact' | 'regular' | 'spacious' = 'regular'
   dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks']
   isQuiet?: boolean
   onAction?: (Key) => void
   onResize?: (Map<Key, ColumnSize>) => void
   onResizeEnd?: (Map<Key, ColumnSize>) => void
   onResizeStart?: (Map<Key, ColumnSize>) => void
   overflowMode?: 'wrap' | 'truncate' = 'truncate'
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

CellProps

 SpectrumTableProps<T> {
   density?: 'compact' | 'regular' | 'spacious' = 'regular'
   dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks']
   isQuiet?: boolean
   onAction?: (Key) => void
   onResize?: (Map<Key, ColumnSize>) => void
   onResizeEnd?: (Map<Key, ColumnSize>) => void
   onResizeStart?: (Map<Key, ColumnSize>) => void
   overflowMode?: 'wrap' | 'truncate' = 'truncate'
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

@react-spectrum/tag

TagGroup

 TagGroup<T extends {}> {
   actionLabel?: string
   maxRows?: number
   onAction?: () => void
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

SpectrumTagGroupProps

 SpectrumTagGroupProps<T> {
   actionLabel?: string
   maxRows?: number
   onAction?: () => void
-  renderEmptyState?: () => JSX.Element
+  renderEmptyState?: () => React.JSX.Element
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAC] 'React' has no exported member 'JSX'
5 participants