Skip to content

Commit 6d3fc05

Browse files
authored
feat: add automatic transform for jsx runtime (#5973)
1 parent 08c8700 commit 6d3fc05

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

.changeset/wise-gifts-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Update components to use jsx from react/jsx-runtime instead of createElement

packages/react/babel.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ const sharedPlugins = [
1414
]
1515

1616
function makePresets(moduleValue) {
17-
return ['@babel/preset-typescript', ['@babel/preset-react', {modules: moduleValue}]]
17+
return [
18+
'@babel/preset-typescript',
19+
[
20+
'@babel/preset-react',
21+
{
22+
modules: moduleValue,
23+
runtime: 'automatic',
24+
},
25+
],
26+
]
1827
}
1928

2029
module.exports = {

packages/react/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const baseConfig = {
7878
'@babel/preset-react',
7979
{
8080
modules: false,
81+
runtime: 'automatic',
8182
},
8283
],
8384
],

packages/react/src/Autocomplete/AutocompleteMenu.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,13 @@ function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMe
364364
text,
365365
leadingVisual: LeadingVisual,
366366
trailingVisual: TrailingVisual,
367+
// @ts-expect-error this is defined in the items above but is
368+
// missing in TS
369+
key,
367370
...itemProps
368371
} = item
369372
return (
370-
<ActionList.Item key={id} onSelect={() => onAction(item)} {...itemProps} id={id} data-id={id}>
373+
<ActionList.Item key={key ?? id} onSelect={() => onAction(item)} {...itemProps} id={id} data-id={id}>
371374
{LeadingVisual && (
372375
<ActionList.LeadingVisual>
373376
{isElement(LeadingVisual) ? LeadingVisual : <LeadingVisual />}

packages/react/src/FilteredActionList/FilteredActionListWithModernActionList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ export function FilteredActionList({
181181
<ActionList.GroupHeading variant={group.header?.variant ? group.header.variant : undefined}>
182182
{group.header?.title ? group.header.title : `Group ${group.groupId}`}
183183
</ActionList.GroupHeading>
184-
{getItemListForEachGroup(group.groupId).map((item, index) => {
185-
const key = item.key ?? item.id?.toString() ?? index.toString()
184+
{getItemListForEachGroup(group.groupId).map(({key: itemKey, ...item}, index) => {
185+
const key = itemKey ?? item.id?.toString() ?? index.toString()
186186
return <MappedActionListItem key={key} {...item} renderItem={listProps.renderItem} />
187187
})}
188188
</ActionList.Group>
189189
)
190190
})
191-
: items.map((item, index) => {
192-
const key = item.key ?? item.id?.toString() ?? index.toString()
191+
: items.map(({key: itemKey, ...item}, index) => {
192+
const key = itemKey ?? item.id?.toString() ?? index.toString()
193193
return <MappedActionListItem key={key} {...item} renderItem={listProps.renderItem} />
194194
})}
195195
</ActionList>

packages/react/src/__tests__/Pagination/Pagination.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Pagination', () => {
3131
<Pagination
3232
pageCount={10}
3333
currentPage={1}
34-
renderPage={({number, ...props}) => <ReactRouterLikeLink to={`#${number}`} {...props} />}
34+
renderPage={({key, number, ...props}) => <ReactRouterLikeLink key={key} to={`#${number}`} {...props} />}
3535
/>,
3636
)
3737

0 commit comments

Comments
 (0)