Skip to content

Commit 9da2673

Browse files
authored
Merge pull request #648 from raheeliftikhar5/sdk-rerendering-fix
Fix apps re-rendering issue with SDK
2 parents 9d0cab1 + d19c210 commit 9da2673

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

client/packages/lowcoder-sdk/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useRef } from "react";
22
import ReactDOM, { flushSync } from "react-dom";
3+
import { createRoot } from "react-dom/client";
34
import { AppViewInstance, bootstrapAppAt, LowcoderAppView } from "./src/index";
45

56
const url = new URL(location.href);
@@ -70,7 +71,9 @@ async function bootstrap() {
7071
});
7172

7273
// React
73-
ReactDOM.render(<ReactDemoApp />, document.querySelector("#app2"));
74+
const container = document.querySelector("#app2");
75+
const root = createRoot(container!);
76+
root.render(<ReactDemoApp />);
7477
}
7578

7679
bootstrap();

client/packages/lowcoder-sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lowcoder-sdk",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"type": "module",
55
"files": [
66
"src",

client/packages/lowcoder/src/appView/AppViewInstance.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RootComp } from "comps/comps/rootComp";
44
import { setGlobalSettings } from "comps/utils/globalSettings";
55
import { sdkConfig } from "constants/sdkConfig";
66
import _ from "lodash";
7-
import { createRoot } from "react-dom/client";
7+
import { Root } from "react-dom/client";
88
import { StyleSheetManager } from "styled-components";
99
import { ModuleDSL, ModuleDSLIoInput } from "types/dsl";
1010
import { AppView } from "./AppView";
@@ -40,7 +40,7 @@ export class AppViewInstance<I = any, O = any> {
4040
webUrl: "https://app.lowcoder.cloud",
4141
};
4242

43-
constructor(private appId: string, private node: Element, options: AppViewInstanceOptions = {}) {
43+
constructor(private appId: string, private node: Element, private root: Root, options: AppViewInstanceOptions = {}) {
4444
Object.assign(this.options, options);
4545
if (this.options.baseUrl) {
4646
sdkConfig.baseURL = this.options.baseUrl;
@@ -137,8 +137,7 @@ export class AppViewInstance<I = any, O = any> {
137137

138138
private async render() {
139139
const data = await this.dataPromise;
140-
const root = createRoot(this.node);
141-
root.render(
140+
this.root.render(
142141
<StyleSheetManager target={this.node as HTMLElement}>
143142
<AppView
144143
appId={this.appId}

client/packages/lowcoder/src/appView/bootstrapAt.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { loadComps } from "comps";
22
import { AppViewInstance, AppViewInstanceOptions } from "./AppViewInstance";
3+
import { createRoot } from "react-dom/client";
34

45
loadComps();
56

@@ -12,5 +13,5 @@ export async function bootstrapAppAt<I>(
1213
console.error("node must be not null.");
1314
return;
1415
}
15-
return new AppViewInstance(appId, node, options);
16+
return new AppViewInstance(appId, node, createRoot(node), options);
1617
}

0 commit comments

Comments
 (0)