Skip to content

Fix apps re-rendering issue with SDK #648

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

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/packages/lowcoder-sdk/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRef } from "react";
import ReactDOM, { flushSync } from "react-dom";
import { createRoot } from "react-dom/client";
import { AppViewInstance, bootstrapAppAt, LowcoderAppView } from "./src/index";

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

// React
ReactDOM.render(<ReactDemoApp />, document.querySelector("#app2"));
const container = document.querySelector("#app2");
const root = createRoot(container!);
root.render(<ReactDemoApp />);
}

bootstrap();
2 changes: 1 addition & 1 deletion client/packages/lowcoder-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lowcoder-sdk",
"version": "2.3.0",
"version": "2.3.1",
"type": "module",
"files": [
"src",
Expand Down
7 changes: 3 additions & 4 deletions client/packages/lowcoder/src/appView/AppViewInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RootComp } from "comps/comps/rootComp";
import { setGlobalSettings } from "comps/utils/globalSettings";
import { sdkConfig } from "constants/sdkConfig";
import _ from "lodash";
import { createRoot } from "react-dom/client";
import { Root } from "react-dom/client";
import { StyleSheetManager } from "styled-components";
import { ModuleDSL, ModuleDSLIoInput } from "types/dsl";
import { AppView } from "./AppView";
Expand Down Expand Up @@ -40,7 +40,7 @@ export class AppViewInstance<I = any, O = any> {
webUrl: "https://app.lowcoder.cloud",
};

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

private async render() {
const data = await this.dataPromise;
const root = createRoot(this.node);
root.render(
this.root.render(
<StyleSheetManager target={this.node as HTMLElement}>
<AppView
appId={this.appId}
Expand Down
3 changes: 2 additions & 1 deletion client/packages/lowcoder/src/appView/bootstrapAt.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { loadComps } from "comps";
import { AppViewInstance, AppViewInstanceOptions } from "./AppViewInstance";
import { createRoot } from "react-dom/client";

loadComps();

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