sweetalert2 / sweetalert2-react-content

Official SweetAlert2 enhancer adding support for React elements as content
MIT License
695 stars 47 forks source link

BREAKING CHANGE: Upgrade to React 18 #189

Closed limonte closed 2 years ago

limonte commented 2 years ago

REACT 18 SUPPORT 🎉

React 18 is now available: https://reactjs.org/blog/2022/03/29/react-v18.html

This PR enables support for React 18 and disables support for earlier versions (16 and 17), so this is the breaking change and the new major will be released.

From the technical side, there are only changes with the new rendering API ReactDOM.createRoot(). Everything else is the same.

One detail worth mentioning is this one:

didOpen: (popup) => {
  setTimeout(() => {
    superDidOpen(popup)
  })
},

Without setTimeout we can't guarantee that everything will be rendered in didOpen callback.

The What about the render callback? chapter in https://github.com/reactwg/react-18/discussions/5 explains why setTimeout is needed:

In the New Root API, we’ve removed this callback.

With partial hydration and progressive SSR, the timing for this callback would not match what the user expects. To avoid the confusion moving forward, we recommend using requestIdleCallback, setTimeout, or a ref callback on the root.


Other changes

  1. Dev environment is now using Vite instead of plain html file, which enables HMR and smooth dev experience (yarn dev)
  2. Tests are moved from jest to Cypress, which enables great abilities to visually see and debug tests (yarn cypress:open). All the tests are the same as before.
limonte commented 2 years ago

@zenflow I'd be great to get your feedback on this PR, thank you in advance! 🙏

limonte commented 2 years ago

@zenflow I'll go ahead and release this change, but if you have any feedback please leave it and I'll fix that separately, thanks!

limonte commented 2 years ago

:tada: This PR is included in version 5.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: