bug: IonAlert and IonLoading components not open with react v18 and using createRoot
See original GitHub issuePrerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v4.x
- v5.x
- v6.x
- Nightly
Current Behavior
Upgraded application use to ionic v6 and react v18 and followed the official upgrade guide to react v18:
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis
// Before
import { render } from 'react-dom';
const container = document.getElementById('app');
render(<App tab="home" />, container);
// After
import { createRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(<App tab="home" />);
After updating to client renderings, the <IonAlert />
component do not open/render anymore.
Expected Behavior
Expect <IonAlert />
component to open/render
Steps to Reproduce
Following the Stackblitz example:
- Click the button
Show Alert Hook
to open the alert modal viauseIonAlert
-> Alert modal open - Click the button
Show Alert Component
to open the alert modal as a component -> Alert modal not open - Open the
index.js
file and switch the comments block to useReactDOM.render()
- Click the button
Show Alert Component
to open the alert modal as a component -> Alert modal open
Code Reproduction URL
https://stackblitz.com/edit/react-1udk9j-3drnwb?file=index.js
Ionic Info
Ionic:
Ionic CLI : 6.19.0 (/home/USERNAME/.nvm/versions/node/v16.15.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 6.1.4
Capacitor:
Capacitor CLI : 3.5.1
@capacitor/android : not installed
@capacitor/core : 3.5.1
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.5.0
System:
NodeJS : v16.15.0 (/home/USERNAME/.nvm/versions/node/v16.15.0/bin/node)
npm : 8.8.0
OS : Linux 5.10
Additional Information
Same bug as https://github.com/ionic-team/ionic-framework/issues/25118 but with a code example
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
bug: IonAlert not rendering in develop mode (yarn start) when ...
Changed initial app render to use react-dom/client createRoot, instead of ReactDOM.render, as this gives deprecation warnings in React 18.
Read more >ReactDOM.render is no longer supported in React 18 - Stack ...
As your error states, ReactDOM.render is no longer supported. So use the new createRoot. As you can see from the code below, ...
Read more >React v18.0 – React Blog
createRoot : New method to create a root to render or unmount . Use it instead of ReactDOM.render . New features in React...
Read more >How to Upgrade to React 18
This new check will automatically unmount and remount every component, whenever a component mounts for the first time, restoring the previous ...
Read more >Strict Mode - React
StrictMode currently helps with: Identifying components with unsafe lifecycles; Warning about legacy string ref API usage; Warning about deprecated findDOMNode ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reporting this issue & providing a reproduction! I am seeing the same issue. We will track this as a bug. Will need to do some exploration into the React 18 changes on my end.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.