Skip to content

Commit

Permalink
feat: support react17 in customLayout function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Feb 7, 2025
1 parent 68a81be commit 74af0b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "feat: support react17 in customLayout function",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class VTableReactAttributePlugin extends ReactAttributePlugin {
container = checkFrozenContainer(graphic);
}

if (!(element && ReactDOM && ReactDOM.createRoot)) {
if (!(element && ReactDOM && (ReactDOM.createRoot || ReactDOM.render))) {
return;
}
const id = isNil(react.id) ? `${graphic.id ?? graphic._uid}_react` : react.id;
Expand All @@ -60,18 +60,36 @@ export class VTableReactAttributePlugin extends ReactAttributePlugin {
const { wrapContainer, nativeContainer } = this.getWrapContainer(stage, container);

if (wrapContainer) {
const root = ReactDOM.createRoot(wrapContainer);
root.render(element);

if (!this.htmlMap) {
this.htmlMap = {};
}

this.htmlMap[id] = { root, wrapContainer, nativeContainer, container, renderId: this.renderId, graphic };
if (ReactDOM.createRoot) {
const root = ReactDOM.createRoot(wrapContainer);
root.render(element);
this.htmlMap[id] = { root, wrapContainer, nativeContainer, container, renderId: this.renderId, graphic };
} else {
ReactDOM.render(element, wrapContainer);

this.htmlMap[id] = {
wrapContainer,
nativeContainer,
container,
renderId: this.renderId,
unmount: () => {
ReactDOM.unmountComponentAtNode(wrapContainer);
},
graphic
};
}
}
} else {
// update react element
this.htmlMap[id].root.render(element);
if (ReactDOM.createRoot) {
this.htmlMap[id].root.render(element);
} else {
ReactDOM.render(element, this.htmlMap[id].wrapContainer);
}
}

if (!this.htmlMap || !this.htmlMap[id]) {
Expand Down

0 comments on commit 74af0b1

Please sign in to comment.