Upgrade to React4XP 7

Contents

This page covers upgrading from React4XP 6 on Enonic XP 7 to React4XP 7 on Enonic XP 8. Moving to React4XP 7 requires changes to the application’s source, descriptors and build configuration.

The upgrade has two parts:

  1. The standard XP 7 to XP 8 application upgrade - YAML descriptors, the new Gradle build and the code-level breaking changes. This is identical for any XP application and is covered by the generic guide.

  2. A handful of React4XP-specific changes on top - dependency versions, build tooling, the new types and mounting the React4XP API.

Both rendering modes follow these same steps. Applications that render parts as separate entries outside the componentRegistry must also apply the legacy mode considerations before building and deploying. These parts can keep their existing rendering model when upgrading to version 7.

If you are coming from React4XP 5, first account for the changes documented in the React4XP 6 upgrade notes. The migration of React4XP-rendered pages and layouts to the component registry belongs to that upgrade; the steps here assume a working React4XP 6 application, including one using legacy parts.

Standard XP 7 to XP 8 upgrade

Upgrade the application to XP 8 exactly as you would any other XP app - convert the XML descriptors to YAML, move to the new Gradle build, and apply the code-level breaking changes. The complete, up-to-date procedure and breaking-change list live in the canonical guide, so follow that rather than repeating it here:

Upgrading from XP 7 to XP 8 - the generic application upgrade guide.

The guide also describes how to run this upgrade automatically with an AI coding agent, using the Enonic Agents Toolkit skill.

Neither the generic guide nor the skill covers the React4XP-specific steps below - apply them once the standard XP 8 upgrade builds cleanly.

React4XP specifics

On top of the standard XP 8 upgrade, a React4XP application needs the following.

Update the dependencies

Move to the version 7 React4XP packages and the XP 8 types.

package.json
"@enonic/react4xp": "7.0.0",
"@enonic/react-components": "^7.0.0",
"@enonic-types/lib-react4xp": "^7.0.0",
"@enonic-types/global": "^8.0.3",

And the React4XP library in the Gradle build:

build.gradle
dependencies {
    include 'com.enonic.lib:lib-react4xp:7.0.0'
}
Upgrade lib-react4xp and @enonic/react4xp together, and rebuild the application - assets compiled with version 6 will fail to load at SSR startup.
@enonic-types/global 8 brings in @enonic-types/core, which replaces the old @enonic/js-utils request type - see Update to the new types below.

Mount the React4XP API

XP 8 serves React4XP’s compiled assets and SSR endpoints through a react4xp web API that must be mounted in the site descriptor - and in any webapp or admin tool that renders React4XP:

src/main/resources/cms/site.yaml
kind: "Site"
apis:
  - "asset"
  - "react4xp"

Switch to the new build tooling

React4XP 7 changes how the application is compiled:

  • Server-side TypeScript is compiled with tsdown - add tsdown and @swc/core to devDependencies. React entries (.tsx) are still compiled by React4XP with Rspack.

  • React4XP uses Rspack’s native CSS support, so the old mini-css-extract-plugin is gone. CSS Modules work out of the box for .module.css and .module.scss files.

The easiest way to get the exact, up-to-date build configuration (tsdown.config.ts, react4xp.config.js, webpack.config.react4xp.js and the tsconfig.json files) is to copy them from the React4XP starter.

Update the npm scripts so the build runs tsdown (server code and client assets) and React4XP (the .tsx entries), with the type checks split into the React4XP and server projects:

package.json
"scripts": {
  "build":                "tsdown",
  "build:react4xp":       "npm explore @enonic/react4xp -- npm run build:react4xp",
  "check":                "concurrently -c auto -g --timings npm:check:types:*",
  "check:types:react4xp": "npx tsc --noEmit -p src/main/resources/react4xp/tsconfig.json",
  "check:types:server":   "npx tsc --noEmit -p src/main/resources/tsconfig.json"
}

Update to the new types

React4XP 7 builds on @enonic-types/core. In your functions and processors, replace Enonic.Xp.Http.Request from @enonic/js-utils/types/Request with Request from @enonic-types/core.

Replace removed APIs where used

Compiled assets are now served by the react4xp API instead of the react4xp XP service. render() resolves the new URLs automatically once the API is mounted. Update custom code that uses the removed APIs:

  • The react4xp-dependencies XP service, which returned dependency URLs over HTTP, has been removed. Server-side, getComponentChunkUrls from /lib/enonic/react4xp still provides dependency URLs.

  • serviceUrl from /lib/enonic/react4xp has been removed. Use assetUrl from the same library to build URLs to compiled assets.

Legacy mode considerations

Apply this section if individual parts call render() from their own implementation, with each part compiled as a separate React entry outside the componentRegistry. The shared dependency, build, type and API changes above also apply to these parts.

Part implementations and entries

Keep the call to render() in each part’s implementation. The standard XP 8 upgrade moves the implementation and descriptor from site/ to cms/. Use the XP 8 GET function convention and the request type described above:

src/main/resources/cms/parts/example/example.ts
import {render} from '/lib/enonic/react4xp';
import {getComponent} from '/lib/xp/portal';
import type {Request} from '@enonic-types/core';

export function GET(request: Request) {
    const component = getComponent();
    const props = {};

    return render(component, props, request);
}

The React entry does not move along with the implementation. When render() receives a component object, it derives the entry name from the component descriptor as site/parts/<name>/<name>. React4XP still compiles entries below src/main/resources/site/, even though XP 8 itself ignores that folder. Keep it for the legacy entries:

src/main/resources/
├── cms/
│   └── parts/
│       └── example/
│           ├── example.ts        (1)
│           └── example.yaml
└── site/
    └── parts/
        └── example/
            └── example.tsx       (2)
1 The part implementation, moved to cms/ by the standard upgrade.
2 The React entry, left in site/ so its jsxPath stays site/parts/example/example.

Alternatively, move the entry to one of the entryDirs configured in react4xp.config.js and pass its jsxPath to render() explicitly. For example, use render('example', props, request) for react4xp/entries/example.tsx.

Site mappings

Legacy parts use XP’s regular component rendering. If the application also uses the React4XP site mapping, preserve the exclusion for content rendered with legacy parts. The inverted pattern from site.xml becomes invertPattern: true in site.yaml:

src/main/resources/cms/site.yaml
kind: "Site"
mappings:
  - controller: "/cms/app.js"
    order: 10
    pattern: "/r4xp5.*"       (1)
    invertPattern: true
  - controller: "/cms/component.js"
    service: "component"
    order: 10
apis:
  - "asset"
  - "react4xp"                (2)
1 Content rendered with legacy parts must live under a path matching this pattern. Adjust it to fit your site.
2 Mount the React4XP API for legacy parts too; render() uses it to resolve asset URLs.

If the application only uses legacy rendering and has no React4XP site mappings, keep them absent. It still needs the apis configuration shown above.

Build and deploy

Make a production build and deploy it to your sandbox:

enonic project build
enonic project deploy

You can also run the project in development mode, which watches for changes and automatically deploys them to the sandbox:

enonic dev

Contents

Contents