@wixc3/react-board
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -8,3 +8,2 @@ "use strict"; | ||
const react_1 = __importDefault(require("react")); | ||
const react_dom_1 = __importDefault(require("react-dom")); | ||
const board_core_1 = require("@wixc3/board-core"); | ||
@@ -24,7 +23,4 @@ const react_error_handled_render_1 = require("./react-error-handled-render"); | ||
} | ||
await (0, react_error_handled_render_1.reactErrorHandledRendering)(element, target); | ||
return (0, react_error_handled_render_1.reactErrorHandledRendering)(element, target); | ||
}, target); | ||
}, | ||
cleanup(target) { | ||
react_dom_1.default.unmountComponentAtNode(target); | ||
} })); | ||
@@ -31,0 +27,0 @@ return res; |
@@ -1,2 +0,3 @@ | ||
export declare const reactErrorHandledRendering: (element: JSX.Element, container: HTMLElement) => Promise<void>; | ||
import React from 'react'; | ||
export declare const reactErrorHandledRendering: (element: React.ReactElement, container: HTMLElement) => Promise<() => void>; | ||
//# sourceMappingURL=react-error-handled-render.d.ts.map |
@@ -9,5 +9,12 @@ "use strict"; | ||
const react_dom_1 = __importDefault(require("react-dom")); | ||
const reactErrorHandledRendering = (element, container) => new Promise((resolve, reject) => { | ||
react_dom_1.default.render(react_1.default.createElement(ErrorBoundary, { reportError: reject }, element), container, resolve); | ||
}); | ||
const client_1 = __importDefault(require("react-dom/client")); | ||
const reactErrorHandledRendering = async (element, container) => { | ||
const reactRoot = client_1.default.createRoot | ||
? client_1.default.createRoot(container) | ||
: createReactLegacyRoot(container); | ||
await new Promise((resolve, reject) => { | ||
reactRoot.render(react_1.default.createElement(ErrorBoundary, { onMount: resolve, reportError: reject }, element)); | ||
}); | ||
return () => reactRoot.unmount(); | ||
}; | ||
exports.reactErrorHandledRendering = reactErrorHandledRendering; | ||
@@ -26,9 +33,21 @@ class ErrorBoundary extends react_1.default.Component { | ||
} | ||
componentDidMount() { | ||
var _a, _b; | ||
(_b = (_a = this.props).onMount) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
} | ||
render() { | ||
if (this.state.hasError) { | ||
return null; | ||
} | ||
return this.props.children; | ||
return this.state.hasError ? null : this.props.children; | ||
} | ||
} | ||
// react-dom@<=17 didn't have createRoot, so we polyfill one that uses previous APIs | ||
function createReactLegacyRoot(container) { | ||
return { | ||
render(children) { | ||
react_dom_1.default.render(children, container); | ||
}, | ||
unmount() { | ||
react_dom_1.default.unmountComponentAtNode(container); | ||
}, | ||
}; | ||
} | ||
//# sourceMappingURL=react-error-handled-render.js.map |
{ | ||
"name": "@wixc3/react-board", | ||
"description": "Library for creation of React component boards", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"main": "dist/index.js", | ||
@@ -11,3 +11,3 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@wixc3/board-core": "^1.2.0" | ||
"@wixc3/board-core": "^2.0.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15781
220
+ Added@wixc3/board-core@2.6.0(transitive)
- Removed@wixc3/board-core@1.2.0(transitive)
Updated@wixc3/board-core@^2.0.0