-
Notifications
You must be signed in to change notification settings - Fork 258
Migrate JSX runtime in Express + Next.js apps #13313
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
base: latest
Are you sure you want to change the base?
Conversation
…configs not updated
…ice added & themeProvider + (loadable) service config required
…o single-services-list
…single-services-list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the JSX runtime from classic to automatic across both Express and Next.js applications. The change removes the need for manual React imports and Emotion JSX pragmas while enabling future framework upgrades. The migration removes Babel configuration from the Next.js app in favor of the built-in SWC compiler, improving build performance and reducing maintenance overhead.
Key changes:
- Switched JSX runtime to
automaticwith@emotion/reactas the import source - Removed
/** @jsx jsx */pragmas and manualReact/jsximports from all components - Removed Babel configuration from Next.js app, leveraging SWC compiler instead
- Updated type imports to use
typekeyword for better tree-shaking
Reviewed changes
Copilot reviewed 284 out of 876 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| babel.config.main.js | Updated to use automatic JSX runtime with Emotion import source for Express app |
| package.json | Removed @emotion/babel-preset-css-prop, added babel-plugin-transform-rename-import |
| Multiple component files | Removed JSX pragmas and React imports, updated to automatic runtime |
| docs/Coding-Standards/Styles.mdx | Updated documentation to reflect new JSX runtime requirements |
| .eslintrc.js | Disabled React-in-JSX-scope ESLint rules for automatic runtime |
| scripts/bundleSize/bundleSizeConfig.js | Updated bundle size thresholds for production builds |
src/app/components/PortraitVideoCarousel/PortraitVideoPromo/index.tsx
Outdated
Show resolved
Hide resolved
ws-nextjs-app/pages/api/local/[service]/[pageType]/[id]/[[...optionalParams]]/index.api.ts
Show resolved
Hide resolved
pvaliani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant work on this
Summary
Changes the JSX runtime/transform from
classictoautomaticto help enable future upgrades to the likes of Turbopack and the Next.js App RouterThis is an 'under-the-hood' change with minor user-facing benefit, but allows for slightly better developer experience as it removes the need to have the
/** @jsx jsx */pragma defined at the top of components that use Emotioncssstyles. It also removes the need to explicitly importReactand the Emotionjsxfunction into components.The Babel config is also removed from the Next.js app. This hands over compliation to Next itself, meaning we leverage its built in SWC compiler to improve build and local dev speed, as well as removing dev overhead maintaining Babel configuration and its dependencies. I also observed some minor improvements to the overall size of JS transferred and decompressed in production builds.
Terminal output from starting the Next.js app should also be a lot cleaner. Babel messages are no longer there since its not being used.
Local benchmarks for Next.js app
yarn build- Compilation improvements, other steps slightly slower, but imperceptibleFrom first running
yarn devto rendering an article pageUnit test speed improvements with
next/jest:Visiting http://localhost:7081/gahuza/articles/c5y51yxeg53o with
yarn build + yarn start(production build)~5% improvement on data over the wire
~8% improvement after decompression
Code Changes
classictoautomaticin the Express app. The Next.js app does this automatically.importSourceto@emotion/reactin Express Babel andtsconfigto allow Emotion to control JSX behaviour:simorgh/babel.config.main.js
Lines 62 to 65 in 7321aba
simorgh/tsconfig.json
Lines 17 to 18 in 7321aba
/** @jsx jsx */pragma requirement for components styled with Emotioncssfunctionjsxfrom@emotion/reactfrom all components as this is handled byimportSource: @emotion/reactin the Express app andcompiler: { emotion: true }in the Next appReactfrom all components as this is no longer needed under the new runtimebabelconfig from Next.js app, instead deferring to its built-in compilerimportSource: @emotion/react, so it assumed Emotion was used in any instance of JSX being used. Emotion isn't supported in the App Router yet. Moving this back to the Pages Router fixes this problem, so I just moved the other APIs back as well as theres no benefit having a mixed economynext/jestto build Jest configs in the Next app. This is required since we're now using SWC instead of Babel: https://nextjs.org/docs/pages/guides/testing/jest#manual-setup:simorgh/ws-nextjs-app/jest.config.ts
Line 9 in 3487d88
swc-loaderin Cypress instead of Babel:simorgh/ws-nextjs-app/cypress.config.ts
Line 54 in 443d018
transform-rename-importplugin, moving it to the Express app instead of being in the Next.js app. This is more future-proof as we move page types over to Next, but also required here since we aren't using Babel in Next anymore:simorgh/babel.config.main.js
Lines 8 to 11 in 7321aba
Developer Checklist
Testing
Ready-For-Test, Local)Ready-For-Test, Test)Ready-For-Test, Preview)Ready-For-Test, Live)Additional Testing Steps
Useful Links