Skip to content

Refactor to use React createRoot#22430

Merged
thijsoo merged 3 commits intotrunkfrom
649-free-refactor-to-use-react-createroot
Jul 21, 2025
Merged

Refactor to use React createRoot#22430
thijsoo merged 3 commits intotrunkfrom
649-free-refactor-to-use-react-createroot

Conversation

@igorschoester
Copy link
Copy Markdown
Contributor

@igorschoester igorschoester commented Jul 15, 2025

Context

  • For React 18+ compatibility, we will need to refactor our React apps to use createRoot.

Summary

This PR can be summarized in the following changelog entry:

  • Refactors our React apps to use createRoot instead of render.

Relevant technical choices:

I divided the commits into 2: our own pages and the helpers that are used elsewhere too.
The latter did not work without fixing the state. Here is the commit message:

The registration after is too soon, the new render is not there right away like before:

  • the constructor now uses the file scope for the initial value of the state

The setState in registerComponent was using stale state:

  • use the callback function with current state instead of relying on this.state

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Be sure to have script debugging enabled on your site/server: define( 'SCRIPT_DEBUG', true );
  • Have your console open to verify the React warning is no longer there:
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
  • Deactivate Premium, we'll have to retest with after to be sure our slots etc work still
    • Or check each test with/without Premium, whatever you prefer
      Do a smoke test on each page/location.
      Here is a list following the touched code:
  • Check our academy page: /wp-admin/admin.php?page=wpseo_page_academy
  • Can't check addon-installation, behind old feature flag
  • Check our dashboard widget (Posts overview) on the WP dashboard: /wp-admin/index.php
  • Check the Wincher dashboard widget (Top keyphrases) on the same page as above
  • Check our dashboard page: /wp-admin/admin.php?page=wpseo_dashboard
  • Check the helpscout beacon, which is on the dashboard also
  • Check the indexation in the tools page: /wp-admin/admin.php?page=wpseo_tools
    • Hint: you can reset indexables via our test helper
  • Check the "settings header", for example on the tools page (you are still there? 😁 )
    • Specifically, this is for the FREE webinar/Black Friday banners that can only be there when you don't have Premium
  • Check the introductions, this can be on any of our admin pages
    • At the time of writing we have a Google Docs add-on introduction
    • To make sure you get to see it again: remove the _yoast_wpseo_introductions database row with your user ID in the user meta table
  • Check the plans page: /wp-admin/admin.php?page=wpseo_licenses
  • Check the settings page: /wp-admin/admin.php?page=wpseo_page_settings
  • Check the support page: /wp-admin/admin.php?page=wpseo_page_support

Now for the roots commit, this is slightly more elaborate in what all is in there.
Specifically the thing that I had to fix here was the registration mechanism with which add-ons add things on top of Free.
Suggestion: check socials and/or other Premium content and upsells.

  • Activate Premium, Video and News
  • Check the classic editor integration
  • Check the Elementor integration
  • Check the block editor integration: metabox and sidebar
  • Check the integrations page: /wp-admin/admin.php?page=wpseo_integrations
  • Check the workouts page: /wp-admin/admin.php?page=wpseo_workouts

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes https://github.com/Yoast/reserved-tasks/issues/649

@igorschoester igorschoester added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Jul 15, 2025
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 15, 2025

Pull Request Test Coverage Report for Build e1bf432bfdc91c097241f28004ccf48677bf5b50

Details

  • 0 of 20 (0.0%) changed or added relevant lines in 14 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.005%) to 52.6%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/js/src/academy/initialize.js 0 1 0.0%
packages/js/src/addon-installation.js 0 1 0.0%
packages/js/src/dashboard-widget.js 0 1 0.0%
packages/js/src/general/initialize.js 0 1 0.0%
packages/js/src/initializers/settings-header.js 0 1 0.0%
packages/js/src/introductions/initialize.js 0 1 0.0%
packages/js/src/plans/initialize.js 0 1 0.0%
packages/js/src/settings/initialize.js 0 1 0.0%
packages/js/src/support/initialize.js 0 1 0.0%
packages/js/src/wincher-dashboard-widget.js 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
packages/js/src/indexation.js 1 0.0%
Totals Coverage Status
Change from base Build d6da65444e3c2ae6c64b3ba68264ab05063bf4aa: 0.005%
Covered Lines: 30934
Relevant Lines: 59644

💛 - Coveralls

The registration after is too soon, the new render is not there right away like before:
* the constructor now uses the file scope for the initial value of the state

The setState in registerComponent was using stale state:
* use the callback function with current state instead of relying on this.state
We call the renderRoot multiple times. Splitting the creation from the render to fix the following warning:
Warning: You are calling ReactDOMClient.createRoot() on a container that has already been passed to createRoot() before. Instead, call root.render() on the existing root instead if you want to update it.
@igorschoester igorschoester force-pushed the 649-free-refactor-to-use-react-createroot branch from 8b308a9 to fe0d899 Compare July 15, 2025 12:51
@thijsoo thijsoo added this to the 25.7 milestone Jul 21, 2025
Copy link
Copy Markdown
Contributor

@thijsoo thijsoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 CR + ACC

@thijsoo thijsoo merged commit 623608f into trunk Jul 21, 2025
22 checks passed
@thijsoo thijsoo deleted the 649-free-refactor-to-use-react-createroot branch July 21, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants