Skip to content

Commit

Permalink
Merge branch 'next-major' into mp/refactor-autocomplete-new-actionlist
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrotti authored Jul 5, 2023
2 parents ec138d0 + 3a70136 commit 413c09a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-coins-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Use createRoot instead of ReactDOM.render for React 18 compatibility.
9 changes: 4 additions & 5 deletions src/Dialog/ConfirmationDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback} from 'react'
import ReactDOM from 'react-dom'
import {createRoot} from 'react-dom/client'
import styled from 'styled-components'
import Box from '../Box'
import {ThemeProvider, useTheme, ThemeProviderProps} from '../ThemeProvider'
Expand Down Expand Up @@ -149,22 +149,21 @@ export type ConfirmOptions = Omit<ConfirmationDialogProps, 'onClose'> & {content
async function confirm(themeProps: ThemeProviderProps, options: ConfirmOptions): Promise<boolean> {
const {content, ...confirmationDialogProps} = options
return new Promise(resolve => {
const hostElement = document.createElement('div')
const root = createRoot(document.createElement('div'))
const onClose: ConfirmationDialogProps['onClose'] = gesture => {
ReactDOM.unmountComponentAtNode(hostElement)
root.unmount()
if (gesture === 'confirm') {
resolve(true)
} else {
resolve(false)
}
}
ReactDOM.render(
root.render(
<ThemeProvider {...themeProps}>
<ConfirmationDialog {...confirmationDialogProps} onClose={onClose}>
{content}
</ConfirmationDialog>
</ThemeProvider>,
hostElement,
)
})
}
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/ConfirmationDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,12 @@ describe('ConfirmationDialog', () => {
})

it('supports nested `focusTrap`s', async () => {
const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {})

const {getByText} = HTMLRender(<ShorthandHookFromActionMenu />)

fireEvent.click(getByText('Show menu'))
fireEvent.click(getByText('Show dialog'))

expect(getByText('Primary')).toEqual(document.activeElement)
expect(getByText('Secondary')).not.toEqual(document.activeElement)

expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('Warning: ReactDOM.render is no longer supported in React 18'),
)
spy.mockRestore()
})
})
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/exports.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ exports[`@primer/react/decprecated should not update exports without a semver ch

exports[`@primer/react/drafts should not update exports without a semver change 1`] = `
[
"Button",
"Component",
"Content",
"DataTable",
Expand Down
3 changes: 1 addition & 2 deletions src/drafts/MarkdownEditor/MarkdownEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {DiffAddedIcon} from '@primer/octicons-react'
import {fireEvent, render as _render, waitFor, within} from '@testing-library/react'
import {fireEvent, render as _render, waitFor, within, act} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import {UserEvent} from '@testing-library/user-event/dist/types/setup/setup'
import React, {forwardRef, useRef, useState} from 'react'
import {act} from 'react-dom/test-utils'
import MarkdownEditor, {MarkdownEditorHandle, MarkdownEditorProps, Mentionable, Reference, SavedReply} from '.'
import ThemeProvider from '../../ThemeProvider'

Expand Down

0 comments on commit 413c09a

Please sign in to comment.