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

feat: add support for React v18 #2481

Merged
merged 20 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/dnb-design-system-portal/gatsby-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { applyPageFocus } from '@dnb/eufemia/src/shared/helpers'
import { rootElement, pageElement } from './src/core/PortalProviders'
import ReactDOM from 'react-dom/client'

if (typeof window !== 'undefined') {
setIsTest(window.location)
Expand All @@ -17,6 +18,15 @@ function setIsTest(location) {
}
}

export const replaceHydrateFunction = () => {
// Added to solve the following errors, which prevented us from running screenshot tests
// https://github.com/gatsbyjs/gatsby/discussions/36232
return (element: React.ReactElement, container: HTMLElement) => {
const root = ReactDOM.createRoot(container)
root.render(element)
}
}

export const wrapRootElement = rootElement('browser')
export const wrapPageElement = pageElement()

Expand Down
34 changes: 18 additions & 16 deletions packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@
"algoliasearch": "4.12.0",
"classnames": "2.3.1",
"history": "5.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-live-ssr": "workspace:*"
},
"devDependencies": {
"@babel/core": "7.22.5",
"@babel/eslint-parser": "7.22.5",
"@babel/node": "7.22.5",
"@emotion/cache": "11.11.0",
"@types/react": "18.2.13",
"@types/react-dom": "18.2.6",
"@typescript-eslint/parser": "5.60.0",
"babel-jest": "29.5.0",
"camelcase": "6.2.0",
Expand All @@ -70,25 +72,25 @@
"eslint-plugin-workspaces": "0.8.0",
"front-matter": "4.0.2",
"fs-extra": "10.0.0",
"gatsby": "4.25.6",
"gatsby-plugin-algolia": "0.26.0",
"gatsby": "5.11.0",
"gatsby-plugin-algolia": "1.0.3",
"gatsby-plugin-babel-react-live": "1.4.2",
"gatsby-plugin-catch-links": "4.25.0",
"gatsby-plugin-emotion": "8.9.0",
"gatsby-plugin-catch-links": "5.11.0",
"gatsby-plugin-emotion": "8.11.0",
"gatsby-plugin-eufemia-theme-handler": "workspace:*",
"gatsby-plugin-gatsby-cloud": "4.25.0",
"gatsby-plugin-manifest": "4.25.0",
"gatsby-plugin-mdx": "4.4.0",
"gatsby-plugin-gatsby-cloud": "5.11.0",
"gatsby-plugin-manifest": "5.11.0",
"gatsby-plugin-mdx": "5.11.0",
"gatsby-plugin-meta-redirect": "1.1.1",
"gatsby-plugin-offline": "5.25.0",
"gatsby-plugin-page-creator": "4.25.0",
"gatsby-plugin-offline": "6.11.0",
"gatsby-plugin-page-creator": "5.11.0",
"gatsby-plugin-remove-serviceworker": "1.0.0",
"gatsby-plugin-sass": "5.25.0",
"gatsby-plugin-sass": "6.11.0",
"gatsby-plugin-scroll-position": "1.2.1",
"gatsby-plugin-sharp": "4.25.1",
"gatsby-react-router-scroll": "5.25.0",
"gatsby-remark-images": "6.25.0",
"gatsby-source-filesystem": "4.25.0",
"gatsby-plugin-sharp": "5.11.0",
"gatsby-react-router-scroll": "6.11.0",
"gatsby-remark-images": "7.11.0",
"gatsby-source-filesystem": "5.11.0",
"github-slugger": "1.4.0",
"is-absolute-url": "4.0.1",
"jest": "29.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function VisualTests() {
// Selects/marks some of the text in SelectionExample on second render tick
// For comparing screenshots
React.useEffect(() => {
window.requestAnimationFrame(() => {
setTimeout(() => {
try {
const range = new Range()
const textNode = document.querySelector(
Expand All @@ -26,7 +26,7 @@ export default function VisualTests() {
} catch (e) {
warn(e)
}
})
}, 10)
}, [])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Requires React and ReactDOM to be loaded. Supports `ES5`.
console.log('on_click', params)
},
})

ReactDOM.render(MyButton, document.getElementById('app'))
const root = createRoot(document.getElementById('app'))
root.render(MyButton)
</script>
</body>
```
Expand Down Expand Up @@ -102,7 +102,8 @@ Because `importmap` is still not supported by the majority of browsers, we use a
}
)

ReactDOM.render(MyButton, document.getElementById('app'))
const root = createRoot(document.getElementById('app'))
root.render(MyButton)
</script>
</body>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default function ListComponents() {
}
}
}
sort: { fields: [frontmatter___order, frontmatter___title] }
sort: [
{ frontmatter: { order: ASC } }
{ frontmatter: { title: ASC } }
]
) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export default function ListElements() {
frontmatter: { title: { ne: "" }, draft: { ne: true } }
internal: { contentFilePath: { glob: "**/uilib/elements/*" } }
}
sort: { fields: [frontmatter___order, frontmatter___title] }
sort: [
{ frontmatter: { order: ASC } }
{ frontmatter: { title: ASC } }
]
) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default function ListFragments() {
contentFilePath: { glob: "**/uilib/components/fragments/*" }
}
}
sort: { fields: [frontmatter___order, frontmatter___title] }
sort: [
{ frontmatter: { order: ASC } }
{ frontmatter: { title: ASC } }
]
) {
edges {
node {
Expand Down
15 changes: 7 additions & 8 deletions packages/dnb-eufemia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"what-input": "5.2.10"
},
"peerDependencies": {
"react": "^17",
"react-dom": "^17"
"react": "^17 || ^18",
"react-dom": "^17 || ^18"
},
"devDependencies": {
"@babel/cli": "7.22.5",
Expand Down Expand Up @@ -154,10 +154,9 @@
"@svgr/core": "6.5.1",
"@svgr/plugin-jsx": "6.5.1",
"@svgr/plugin-svgo": "6.5.1",
"@testing-library/dom": "8.11.0",
"@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "7.0.2",
"@testing-library/user-event": "13.5.0",
"@testing-library/dom": "9.3.1",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "14.4.3",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.2.6",
"@types/jest-axe": "3.5.5",
Expand Down Expand Up @@ -227,8 +226,8 @@
"prettier-package-json": "2.6.0",
"process": "0.11.10",
"prop-types": "15.7.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-to-typescript-definitions": "3.1.1",
"regenerator-runtime": "0.13.9",
"repo-utils": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ describe('Autocomplete', () => {
setupPageScreenshot({
each: true,
url: '/uilib/components/autocomplete/demos',
pageViewport: {
width: 1280,
height: 1024, // The height influences this test: data-visual-test="autocomplete-drawer-search"
},
})

it('have to match different sizes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2121,44 +2121,27 @@ describe('Autocomplete component', () => {
'one more item',
]

render(<Autocomplete data={mockData} {...mockProps} />)

// open
keydown(40) // down
render(<Autocomplete {...mockProps} data={mockData} />)

document.querySelector('input').focus()
fireEvent.focus(document.querySelector('input'))

// focus the first item
keydown(40) // down

// focus the second item
keydown(40) // down

const runTabs = () => {
userEvent.tab()

expect(Array.from(document.activeElement.classList)).toContain(
'first-anchor'
)

userEvent.tab()
await userEvent.tab()

expect(Array.from(document.activeElement.classList)).toContain(
'second-anchor'
)

userEvent.tab()

expect(Array.from(document.activeElement.classList)).toContain(
'dnb-input__input'
)
}
expect(Array.from(document.activeElement.classList)).toContain(
'first-anchor'
)

// run first round
runTabs()
await userEvent.tab()

// run second round
runTabs()
expect(Array.from(document.activeElement.classList)).toContain(
'second-anchor'
)
})

it('will keep focus on input when opening', () => {
Expand Down
Loading