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

[DNM] React 19 #12374

Merged
merged 42 commits into from
Feb 10, 2025
Merged

[DNM] React 19 #12374

merged 42 commits into from
Feb 10, 2025

Conversation

amoore108
Copy link
Contributor

@amoore108 amoore108 commented Feb 6, 2025

Resolves JIRA https://jira.dev.bbc.co.uk/browse/WORLDSERVICE-139

Overall changes

  • Updates React to version 19
  • Adds react-is version pin per https://github.com/jestjs/jest/issues/15402
  • Amends some spread operator conditions per https://github.com/facebook/react/issues/29902. This seems to be a React issue with the classic runtime we're using. Updating to automatic runtime may fix this, but historically this broke Opera Mini, so this is a workaround to keep us on the classic runtime
  • Updates various tests that failed after the update. These are minor and again probably related to internal changes to way React is working in v19

Testing

  • Check Express app on Preview
  • Check Next.js app on Preview
  • Check canonical, AMP and Lite modes
  • Test Opera Mini

Helpful Links

Add Links to useful resources related to this PR if applicable.

Coding Standards

Repository use guidelines

@amoore108 amoore108 self-assigned this Feb 6, 2025
<meta
content="width=device-width, initial-scale=1, minimum-scale=1"
data-react-helmet="true"
name="viewport"
/>
<script
Copy link
Contributor Author

Choose a reason for hiding this comment

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

React 19 changes some behaviour of <head> related tags, which likely accounts for this snapshot diff: https://react.dev/blog/2024/12/05/react-19#support-for-async-scripts

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is OK - it's just changing the order of the content in the snapshot by the looks of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I'll check and compare the ordering to see if there is any impact.

@@ -15,12 +15,14 @@ Cypress.Commands.add('hasNoscriptImgAtiUrl', atiUrl => {

// Should be moved into integration/pages/index.js once all pages have Chartbeat
Cypress.Commands.add('hasScriptWithChartbeatSrc', () => {
cy.reload(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't particularly like this, or the { retries: 3 } on the individual Chartbeat tests, but I've tried everything to get them to work and couldn't find a better solution.

Feel like it may have something to do with how React 19 takes over <script /> tags, but can't be sure.

@amoore108 amoore108 changed the title React 19 [DNM] React 19 Feb 7, 2025
src/app/components/Image/index.tsx Show resolved Hide resolved
<meta
content="width=device-width, initial-scale=1, minimum-scale=1"
data-react-helmet="true"
name="viewport"
/>
<script
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is OK - it's just changing the order of the content in the snapshot by the looks of it?

.github/dependabot.yml Show resolved Hide resolved
@pvaliani pvaliani self-requested a review February 7, 2025 16:07
@@ -39,7 +39,7 @@ const PlayButton = ({
type="button"
css={styles.button}
onClick={onClick}
{...(className && { className })}
{...(className ? { className } : undefined)}
Copy link
Contributor

Choose a reason for hiding this comment

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

So, basically this (and similar changes) are making sure we are following the correct spread pattern for React 19 because in 19 dev mode crashes when false is evaluated during spread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see any crashes as such, tests just failed quite spectacularly without these changes. Not to say it wouldn't cause the app to crash though, it very well could do without noticing as we still display the server render if the app crashes.

@@ -1,4 +1,4 @@
import React from 'react';
import React, { type JSX } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to import React here for storybook if we're removing it from imports in components below?

i.e in the Next app at ws-nextjs-app/pages/[service]/send/[id]/MessageBox/ErrorSummaryBox.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea we'll need to here. Other components that don't import will likely be importing something like:

/** @jsx jsx */
import { jsx } from '@emotion/react';

which means Emotion will be taking control of JSX rendering.

Copy link
Contributor

@pvaliani pvaliani left a comment

Choose a reason for hiding this comment

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

Looks good and runs fine for me locally. Would be interesting to see what the affect on performance this upgrade might have immediately.

Took a capture of mundo if we want to do a pagespeed insights comparison:
https://pagespeed.web.dev/analysis/https-www-bbc-com-mundo/s30x4axjui?form_factor=mobile

Nice job man

.eslintrc.js Outdated Show resolved Hide resolved
@amoore108 amoore108 marked this pull request as ready for review February 10, 2025 11:05
@amoore108 amoore108 merged commit 7529531 into latest Feb 10, 2025
11 checks passed
@amoore108 amoore108 deleted the react-19 branch February 10, 2025 11:15
amoore108 added a commit that referenced this pull request Feb 10, 2025
@amoore108 amoore108 mentioned this pull request Feb 10, 2025
amoore108 added a commit that referenced this pull request Feb 10, 2025
amoore108 added a commit that referenced this pull request Feb 10, 2025
amoore108 added a commit that referenced this pull request Feb 11, 2025
* Revert "Revert "[DNM] React 19 (#12374)" (#12384)"

This reverts commit 15d7529.

* Set `async:false` on bundle script

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

Successfully merging this pull request may close these issues.

3 participants