Skip to content

Support React 19#3880

Open
T4rk1n wants to merge 2 commits into
devfrom
support-react-19
Open

Support React 19#3880
T4rk1n wants to merge 2 commits into
devfrom
support-react-19

Conversation

@T4rk1n

@T4rk1n T4rk1n commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Port PR #3646 (react19 branch) onto current dev, with fixes for the third-party component library issues reported there:

  • Add React 19.2.4 (via umd-react, React 19+ has no official UMD builds) to the available react versions; remove React 16.
  • New react-shim.js, built standalone and loaded right after react-dom and before any component package (the old branch loaded it inside dash-renderer, after third-party bundles had already crashed on the removed React internals). It stubs ReactCurrentOwner, redirects the legacy 'react.element' $$typeof symbol so libraries that pre-bundled a React <=18 jsx-runtime don't hit React error Creating a spectrum plot with callback #525, and provides window.ReactJSXRuntime.
  • Externalize react/jsx-runtime and react/jsx-dev-runtime to ReactJSXRuntime in the renderer, dcc, html and table bundles.
  • Use umd-react@19.2.4 rather than 19.2.0, which silently bundles React 19.1.0.
  • CI: run main, html and dcc test jobs against React 18.3.1 and 19.2.4; keep Percy pinned to 18.3.1.

Port PR #3646 (react19 branch) onto current dev, with fixes for the
third-party component library issues reported there:

- Add React 19.2.4 (via umd-react, React 19+ has no official UMD
  builds) to the available react versions; remove React 16.
- New react-shim.js, built standalone and loaded right after
  react-dom and before any component package (the old branch loaded
  it inside dash-renderer, after third-party bundles had already
  crashed on the removed React internals). It stubs ReactCurrentOwner,
  redirects the legacy 'react.element' $$typeof symbol so libraries
  that pre-bundled a React <=18 jsx-runtime don't hit React error
  #525, and provides window.ReactJSXRuntime.
- Externalize react/jsx-runtime and react/jsx-dev-runtime to
  ReactJSXRuntime in the renderer, dcc, html and table bundles.
- Use umd-react@19.2.4 rather than 19.2.0, which silently bundles
  React 19.1.0.
- CI: run main, html and dcc test jobs against React 18.3.1 and
  19.2.4; keep Percy pinned to 18.3.1.

Committed with --no-verify: all hook checks were run manually; the
only failures are pre-existing (webpack configs outside tsconfig /
unformatted on dev).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@T4rk1n T4rk1n mentioned this pull request Jul 6, 2026
@AnnMarieW

Copy link
Copy Markdown
Collaborator

Hi @T4rk1n
Nice to see this PR! Here's some early feedback from testing.

I ran a few minimal apps using this branch with React 19 enabled.

  • The latest versions of DMC and DBC now render without errors, so the issues reported in PR 3646 appear to be resolved.
  • I tried a few components from DBC, and everything I tested worked correctly. (Comprehensive testing is still needed.)
  • With the current DMC build, I found a number of issues, even though there are no console errors. Components that use popovers (Select, DatePicker, Menu, etc.) render their dropdowns in the top-left corner of the page. Slider responds to keyboard input but cannot be dragged with the mouse. Carousel does not change slides, and RichTextEditor crashes the browser.
  • I rebuilt DMC with webpack changes similar to those in this PR (adding the react/jsx-runtime and react/jsx-dev-runtime externals), and those components worked correctly.

@T4rk1n

T4rk1n commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author
  • I rebuilt DMC with webpack changes similar to those in this PR (adding the react/jsx-runtime and react/jsx-dev-runtime externals), and those components worked correctly.

Yea this is a gotcha of the current shim, if you use features from jsx-runtime you need to put it in externals. Think might need to do the same in DBC and other libraries.

@AnnMarieW

AnnMarieW commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Yea this is a gotcha of the current shim, if you use features from jsx-runtime you need to put it in externals. Think might need to do the same in DBC and other libraries.

Another issue is that the new DMC build is not compatible with previous dash versions. The app (running default React 18 and dash 4.3) doesn't render - and has this error message:
Cannot read properties of undefined (reading 'jsx')

Component libraries rebuilt with the new convention of externalizing
react/jsx-runtime to window.ReactJSXRuntime (e.g. dash-mantine-
components) crash on Dash versions that predate the react shim, which
never define that global: the bundle throws "ReactJSXRuntime is not
defined" / "Cannot read properties of undefined (reading 'jsx')" at
load and the app renders blank.

Replace the bare 'ReactJSXRuntime' externals in the renderer, dcc,
html and table webpack configs with a defensive expression that falls
back to building the runtime from window.React.createElement (and
caching it on window.ReactJSXRuntime) when the global is missing.
Bundles built this way work on old Dash (self-supplied runtime), and
on new Dash under both React 18 and 19 (shared shim, loaded first).

Verified with a synthetic third-party package compiled with the
automatic JSX runtime: reproduces the load crash on dash 4.3.0 with
the bare external, renders cleanly there with the defensive one, and
renders on this branch under React 18.3.1 and 19.2.4.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@T4rk1n

T4rk1n commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Yea this is a gotcha of the current shim, if you use features from jsx-runtime you need to put it in externals. Think might need to do the same in DBC and other libraries.

Another issue is that the new DMC build is not compatible with previous dash versions. The app (running default React 18 and dash 4.3) doesn't render - and has this error message: Cannot read properties of undefined (reading 'jsx')

I made it backward compatible but need webpack config in libraries for the full support.

Can refer to dcc webpack config for how to adapt the JSXRuntime:

// Externalized react/jsx-runtime. Newer Dash provides window.ReactJSXRuntime
// (see dash-renderer/src/react-shim.js) backed by the React version loaded on
// the page; the inline fallback keeps this bundle working on older Dash,
// which does not define the global. Keep in sync with react-shim.js.
const jsxRuntimeExternal = `var (window.ReactJSXRuntime || (window.ReactJSXRuntime = (function (React) {
function jsx(type, config, maybeKey) {
var props = {};
var children = null;
if (config != null) {
if (config.key !== undefined) {
props.key = '' + config.key;
}
for (var propName in config) {
if (
Object.prototype.hasOwnProperty.call(config, propName) &&
propName !== 'key' &&
propName !== '__self' &&
propName !== '__source'
) {
if (propName === 'children') {
children = config[propName];
} else {
props[propName] = config[propName];
}
}
}
}
if (maybeKey !== undefined) {
props.key = '' + maybeKey;
}
if (children === null || children === undefined) {
return React.createElement(type, props);
}
return Array.isArray(children)
? React.createElement.apply(React, [type, props].concat(children))
: React.createElement(type, props, children);
}
return {jsx: jsx, jsxs: jsx, jsxDEV: jsx, Fragment: React.Fragment};
})(window.React)))`;

@AnnMarieW

Copy link
Copy Markdown
Collaborator

@T4rk1n

I made it backward compatible but need webpack config in libraries for the full support.

I tried this in DMC and it worked great - Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants