-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
chore: update for React 19 compatibility #4247
Conversation
View Deployment
|
268a9d4
to
81ac375
Compare
Playwright test resultsDetails 23 tests across 10 suites |
8d9644f
to
095e1e6
Compare
6bfdf8d
to
287f12e
Compare
829c2a6
to
f1844d8
Compare
ceb870b
to
ad2bd77
Compare
d01f2c9
to
0bcd5f3
Compare
0bcd5f3
to
d875a76
Compare
36ada48
to
47a5f5c
Compare
UMD users need to pay attention.Starting from Univer 0.6.0, with the support for React 191, UMD users may need additional adaptation. <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script>
/**
* Fix `Uncaught TypeError: client.createRoot is not a function`
* If using UMD React < 18, you might need the following code.
*/
(function (global) {
'use strict';
if (!global.ReactDOM) {
throw new Error('ReactDOM must be loaded before ReactCreateRoot.');
}
var ReactDOM = global.ReactDOM;
if (!ReactDOM.createRoot) {
ReactDOM.createRoot = function (container) {
return {
render: (element) => {
ReactDOM.render(element, container);
},
};
};
}
})(this);
/**
* Fix `Uncaught TypeError: jsxRuntime.jsx is not a function`
* If using UMD React, you might need the following code.
* Reference: https://unpkg.com/[email protected]/cjs/react-jsx-runtime.production.min.js
*/
(function (global) {
'use strict';
if (!global.React) {
throw new Error('React must be loaded before ReactJSXRuntime.');
}
var React = global.React;
if (!React.jsx || !React.jsxs) {
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true,
};
var ReactCurrentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
function createReactElement(type, config, maybeKey) {
var props = {};
var key = null;
var ref = null;
if (maybeKey !== undefined) {
key = '' + maybeKey;
}
if (config.key !== undefined) {
key = '' + config.key;
}
if (config.ref !== undefined) {
ref = config.ref;
}
for (var propName in config) {
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
props[propName] = config[propName];
}
}
if (type && type.defaultProps) {
var defaultProps = type.defaultProps;
for (var propName in defaultProps) {
if (props[propName] === undefined) {
props[propName] = defaultProps[propName];
}
}
}
return {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
ref: ref,
props: props,
_owner: ReactCurrentOwner.current,
};
}
React.jsx = createReactElement;
React.jsxs = createReactElement;
}
})(this);
</script> Footnotes
|
TODO
BREAKING CHANGES
In React 16, the
render
method is imported from"react-dom"
, while in React 19, thecreateRoot
method is imported from"react-dom/client"
. This creates a path compatibility issue. Therefore, in projects using React 16, you need to use an alias to mapreact-dom/client
to a polyfill.vite.config.ts
export default defineConfig({ plugins: [react()], resolve: { alias: { + "react-dom/client": path.resolve(__dirname, './src/client.ts'), } } }
src/client.ts
Additional Compatibility Note
In React 19 projects, certain components may trigger the following warnings. We will fix these issues gradually in future UI refactoring efforts.
Please don’t worry, this will not affect the functionality of your application.
Pull Request Checklist