Repository navigation
feat: support React 18 and 19 - #8093
Open
martinjagodic wants to merge 6 commits into
Open
martinjagodic wants to merge 6 commits into
martinjagodic wants to merge 6 commits into
Conversation
decap-cms-core listed react and react-dom in dependencies as well as
peerDependencies. A package manager can then install a second copy of
React next to the host app's, which breaks hooks ("Invalid hook call")
and context. React is now a peer only, as it is everywhere else.
react-is goes too. Its only use was isElement() in the preview pane,
and react-is 16 does not recognise React 19 elements (they use a new
$$typeof symbol), so a preview template registered as an element was
passed to createElement() and failed. React's own isValidElement works
on every React version.
Published packages now declare react and react-dom peers as `^18.0.0 || ^19.0.0`. The range lives in a named pnpm catalog, `catalogs.peer`, and every package references it as `catalog:peer`, so there is one place to change it and pnpm pack/publish writes the literal range into the published manifest. The default catalog keeps pinning React 19, which the workspace installs, builds and tests against. decap-cms-backend-forgejo and decap-cms-widget-richtext had literal `^19.1.0` peers instead of the catalog; they use `catalog:peer` too. The decap-cms bundle keeps react and react-dom (19) as dependencies: it bundles them for the script-tag install.
The webpack alias that points react-dom/server at the legacy browser renderer hardcoded React 19's file name. React 18 names the production build `react-dom-server-legacy.browser.production.min.js`, so building against React 18 failed in the markdown and richtext widgets with "Can't resolve 'react-dom/server'". Look for either name, and fall back to no alias if neither exists.
The ListControl mocks are custom elements. React 19 renders a `true`
prop on one as an empty attribute and leaves `false` out, while React
18 writes both as strings, so `toHaveAttribute('collapsed')` passed on
React 18 whatever the value. Read the attribute through a helper that
understands both.
Editor checks its propTypes itself because React 19 stopped doing so.
React 18 still does, so the warning the spec expects is logged twice
there; assert on the message instead of an exact call count.
Add a build-unit-react-18 job next to build-unit. It overrides react and react-dom to ^18.3.1 in pnpm-workspace.yaml, installs without the frozen lockfile, checks that no React 19 is left, and runs the unit tests and the build. An override is needed rather than a catalog change: the peers pnpm auto-installs for workspace packages stay locked to 19, which already satisfies `^18.0.0 || ^19.0.0`. Snapshots are rewritten instead of compared in this job, since they record React 19's serialization of the tests' mock custom elements. Lint, type-check and e2e stay on React 19 only.
decap-cms bundles React into dist/decap-cms.js, so it only needs react and react-dom to build. As runtime dependencies they pinned ^19.1.0 next to decap-cms-app's new `^18.0.0 || ^19.0.0` peer, and npm could no longer resolve the tree: `npm i decap-cms` failed with ERESOLVE (react-redux 7 peers on React <= 18 and npm now had an 18 to choose), and installing decap-cms together with decap-cms-app, as scripts/smoke-install-packed.mjs does, looped in the resolver. As devDependencies they still build the bundle, which still contains React 19, and npm resolves the peers on its own.
✅ Deploy Preview for decap-cms ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Decap now officially supports both React 18 and React 19. Published packages accept either as a peer,
decap-cms-corestops installing its own React, and CI runs the unit tests and the build against React 18 as well. The workspace itself still installs, builds and tests on React 19, and thedecap-cmsscript-tag bundle still ships React 19.Peer range
Every published package that declared a
react/react-dompeer now declares^18.0.0 || ^19.0.0.The range lives in a named pnpm catalog,
catalogs.peerinpnpm-workspace.yaml, and the manifests reference it ascatalog:peer:decap-cms-backend-forgejoanddecap-cms-widget-richtexthad already drifted to literal^19.1.0peers, which is what writing the range into 37 manifests by hand leads to.react/react-dom^19.1.0, so the workspace's own install stays on React 19. The peers pnpm auto-installs for workspace packages resolve to the same 19.2.0 (one React copy in the lockfile).pnpm pack/pnpm publishresolve named catalogs the same as the default one. Checked by packingdecap-cms-core,decap-cms-widget-richtextanddecap-cms: the tarball manifests contain"react": "^18.0.0 || ^19.0.0"and nocatalog:/workspace:strings.pnpm run test:package-integritypasses, and so doesscripts/smoke-install-packed.mjs(npm and pnpm).Dependency fix
decap-cms-corelistedreactandreact-domindependenciesas well aspeerDependencies, which can install a second React next to the host app's ("Invalid hook call"). They are peers only now.The only other published package with React in
dependencieswas thedecap-cmsbundle. It bundles React 19 for the script-tag install, so it only needs React to build, and React is now adevDependencythere (the bundle still contains React 19.2.0). This was required, not tidying: withreact@^19.1.0as a runtime dependency next to the new^18 || ^19peers,npm i decap-cmsfailed with ERESOLVE (react-redux 7 peers on React ≤ 18, and npm now had an 18 it could pick), andscripts/smoke-install-packed.mjs, which installsdecap-cmsanddecap-cms-apptogether, looped in npm's resolver until killed.One npm behaviour change to know about:
npm i decap-cms-appwithout naming React now auto-installs React 18.3.1, because several third-party peers (table below) allow 18 but not 19.npm i decap-cms-app react react-dom, which is what the README says, still gets React 19, and pinningreact@18gets 18; both install cleanly with a single React copy.react-isis also gone from core. Its only use wasisElement()in the preview pane, andreact-is16 does not recognise React 19 elements (new$$typeofsymbol), so a preview template registered as an element was handed tocreateElement()and failed on React 19 today. React's ownisValidElementworks on both.React 18 test results
Run in a throwaway worktree with
react/react-domoverridden to 18.3.1 (single copy in the lockfile):decap-cms-widget-markdownanddecap-cms-widget-richtextwithCan't resolve 'react-dom/server'. The webpack alias added in perf: drop duplicate and unused code from the decap-cms bundle #8032 hardcoded React 19's file name for the legacy server renderer; React 18 names it.production.min.js. Fixed inscripts/webpack.jsby looking for either name. After that the whole build passes and thedecap-cmsbundle contains React 18.3.1.classNamebecomes aclassnameattribute, booleans become"true"/"false"strings), plus one exactconsole.errorcount that React 18 doubles because it still checks propTypes itself. Thecollapsedassertions inListControl.spec.jspassed on React 18 regardless of the value, so they now read the attribute through a helper that understands both. With that, the only remaining differences are 31 snapshots, which the React 18 CI job rewrites instead of comparing. Everything else passes (2304 tests).babel-plugin-inline-react-svg),I18n(react-polyglot) andReactMarkdown, and the duplicated propTypes warnings in components that callPropTypes.checkPropTypesmanually for React 19. Both are harmless.use(),useActionState,useOptimistic,useFormStatus, context-as-provider, ref cleanup functions, or function components takingrefas a plain prop (the oneref-forwarding wrapper usesforwardRef). Rendering usescreateRootfromreact-dom/client, which React 18 has.Third-party runtime dependencies with a React peer
Direct runtime dependencies of published packages, with the installed version's declared peer range:
reactpeer^16.8.3 || ^17 || ^18^16.9.0 || ^17.0.0 || ^18(optional)16.x || 17.x || 18.x(also react-dom)^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.0.0^16.0.0-0(also react-dom)^16.3.0 || ^17.0.0>=15.5 <=17.x>=18... || ^18 || ^19... || ^18.0.0 || ^19.0.0... || ^18.0.0 || ^19.0.0... || ^18.0.0 || ^19.0.0... || ^18.0.0 || ^19.0.0>= 16.14>= 16.3>=15>=16>=16.8.0>=16.8.0>=16.6.0*>=16.8.0>=16.8.0>=18.2.0>=18.0.0None of the ones that exclude 19 is new: they are the existing peer mismatches
smoke-install-packed.mjsalready allows (KNOWN_NPM_LS_INVALID). React 18 makes nothing worse, and three of them (react-split-pane, react-aria-menubutton, react-codemirror2) already exclude 18 too but work on it, as the demo smoke test shows. No majors were upgraded here; react-redux 8+/9, a newer react-scroll-sync and replacements for the unmaintained react-split-pane, react-aria-menubutton and react-codemirror2 are follow-ups.CI
New
build-unit-react-18job in.github/workflows/nodejs.yml, next tobuild-unit(ubuntu, Node 24, no e2e):react: ^18.3.1andreact-dom: ^18.3.1tooverridesinpnpm-workspace.yaml. An override, not a catalog change: the peers pnpm auto-installs for workspace packages stay locked to 19 otherwise, since 19 already satisfies^18.0.0 || ^19.0.0.pnpm install --no-frozen-lockfile, then fails if any React 19 is left in the lockfile.pnpm run test:unit --updateSnapshot(snapshots are compared in the React 19 job) andpnpm run build.Lint and type-check stay on React 19 only, since the types are
@types/react19. The job is not a required check until it is added to branch protection.Docs
packages/decap-cms-app/README.mdnow says React 18 and React 19 are both supported. That is the only doc onmainthat mentions a React version. #8092 (not merged) says "React 19" in three places that should become "React 18 or 19" once both are in:AGENTS.md(decap-cms-app"with React 19 as a peer dependency"),context7.json("decap-cms-app needs React 19 from npm."), andpackages/decap-cms-app/README.md("Install it with React 19:"). "React 19 has no UMD builds" stays true. The two PRs merge cleanly in either order.Release impact
lerna will bump these 38 packages (their
package.jsonchanged, andpackage.jsonis not inignoreChanges):decap-cms,decap-cms-app,decap-cms-core,decap-cms-default-exports,decap-cms-editor-component-image,decap-cms-lib-turbo,decap-cms-media-library-s3,decap-cms-ui-auth,decap-cms-ui-default, everydecap-cms-backend-*(aws-cognito-github-proxy, azure, bitbucket, forgejo, git-gateway, gitea, github, gitlab, proxy, test, turbo-github, turbo-gitlab) and everydecap-cms-widget-*(boolean, code, colorstring, datetime, file, image, list, map, markdown, number, object, relation, richtext, select, string, text, uuid). Thefeat:commit makes the 37 peer-range packages minor bumps;decap-cmsgets a patch from itsfix:commit (and would be bumped as their dependent anyway).scripts/webpack.jsand the workflow are outsidepackages/and bump nothing.Test plan
pnpm run lint-quiet,pnpm run type-check,pnpm run test:uniton React 19pnpm run test:package-integrity; packed manifests contain the literal peer rangenode scripts/smoke-install-packed.mjs(npm, yarn 4, yarn 1, pnpm)npm iof the packed tarballs:decap-cmsalone,decap-cms-appalone, and with explicitreact@^19/react@^18build-unit-react-18green (unit tests 32s, build 4.5 min)