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

WP 6.2 compatibility: use React createRoot #19858

Open
igorschoester opened this issue Feb 13, 2023 · 8 comments · May be fixed by #19871
Open

WP 6.2 compatibility: use React createRoot #19858

igorschoester opened this issue Feb 13, 2023 · 8 comments · May be fixed by #19871
Assignees

Comments

@igorschoester
Copy link
Member

igorschoester commented Feb 13, 2023

⚠️ Since we rely on @wordpress/element to export createRoot -- this issue can not be fixed until WP 6.2 is the last version we support (unless we try both methods) ⚠️

In WP 6.2 we get React 18.0.2 instead of 17.0.2.

This causes JS console errors to be shown:

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

This seems to originate in a couple of different places, like the help scout beacon, first time configuration and the settings (not Settings UI).

  • Please look for render itself in our JS source code, as most likely this is anywhere we add a React root.
  • Please do not forget our add-ons!

Reproduce steps

  • Install and activate the WordPress Beta Tester plugin
  • Go to Tools > Beta testing
  • Change the update channel to Bleeding edge and the stream to Beta/RC Only
  • Go to Dashboard > Updates and update to 6.2-beta1 (at the time of writing)
  • Add/ensure the following constants are set as follows in your wp-config.php. Please do this instead of the WP_DEBUG set to false.
if ( ! defined( 'WP_DEBUG' ) ) {
    define( 'WP_DEBUG', true );
}
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
    define( 'SCRIPT_DEBUG', true );
}
if ( ! defined( 'YOAST_ENVIRONMENT' ) ) {
    define( 'YOAST_ENVIRONMENT', 'development' );
}
  • Go to Yoast SEO > General with the console open
  • Verify you see errors like the above
@igorschoester
Copy link
Member Author

igorschoester commented Feb 15, 2023

Situation

  • React is loaded via @wordpress/element
  • Version of @wordpress/element is depending on the WordPress version
  • We need to support multiple versions
    • Upcoming is WP 6.2 where WP element goes to 5.3.1 and React to 18.2

Dependencies (TODO)

  • WP element is also a peer dependency in the UI library
    • We decided to keep the same WP based React here for “simplicity”. Is that still something we agree with?
  • React and React DOM are development dependencies for the Storybook
    • We have to keep these inline with WP element’ versions

Tests are failing (TODO)

Possible solution?

Addons (TODO)

  • Same checks need to be done there still

@enricobattocchi
Copy link
Member

Moved to the most future sprint we currently have, we'll reprise it by then and try to plan a clear timeline

@shabnam611
Copy link

Please inform the customer of conversation # 1054366 when this conversation has been closed.

@pixeline
Copy link

Issue is still active with latest yoast premium. Any ETA ?

@ogodoabiola
Copy link

Please inform the customer of conversation # 1103708 when this conversation has been closed.

@helgatheviking
Copy link

Was googling for something else and ended up here. If I am reading this correctly I have been supporting both versions like so:

/**
 * External dependencies
 */
import { createRoot, render } from '@wordpress/element';
import App from './app';

const target = document.getElementById( 'my-app-root' );

if ( target ) {

    if ( createRoot ) {
        createRoot( target ).render( <App /> );
    } else {
        render( <App />, target );
    }
}

If createRoot() exists (like in the newer react) it uses that. If createRoot() is undefined... it falls back to render()

@josevarghese
Copy link
Contributor

Hi @helgatheviking

Thanks for the comment and for sharing more details. This issue is on the radar of our development team, and they will prioritize it based on the severity of this problem in relation to other open bug reports and new features.

@neoseeyou
Copy link

Still not corrected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants