From 8cab9f41558219caa7fc6483444c899e6e4178f0 Mon Sep 17 00:00:00 2001 From: Dinh Long Nguyen Date: Fri, 4 Oct 2024 19:19:11 +0700 Subject: [PATCH] fix cliend-id error for designer (#1919) --- frontend/taipy-gui/base/src/app.ts | 14 ++++++++------ .../base/src/packaging/taipy-gui-base.d.ts | 1 + frontend/taipy-gui/base/src/wsAdapter.ts | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/taipy-gui/base/src/app.ts b/frontend/taipy-gui/base/src/app.ts index e6a0731a84..fcfa348e45 100644 --- a/frontend/taipy-gui/base/src/app.ts +++ b/frontend/taipy-gui/base/src/app.ts @@ -3,7 +3,7 @@ import { sendWsMessage, TAIPY_CLIENT_ID } from "../../src/context/wsUtils"; import { uploadFile } from "../../src/workers/fileupload"; import { Socket, io } from "socket.io-client"; -import { nanoid } from 'nanoid'; +import { nanoid } from "nanoid"; import { DataManager, ModuleData, RequestDataOptions } from "./dataManager"; import { initSocket } from "./socket"; import { TaipyWsAdapter, WsAdapter } from "./wsAdapter"; @@ -26,7 +26,6 @@ export type OnEvent = type Route = [string, string]; type RequestDataCallback = (taipyApp: TaipyApp, encodedName: string, dataEventKey: string, value: unknown) => void; - export class TaipyApp { socket: Socket; _onInit: OnInitHandler | undefined; @@ -51,7 +50,7 @@ export class TaipyApp { onInit: OnInitHandler | undefined = undefined, onChange: OnChangeHandler | undefined = undefined, path: string | undefined = undefined, - socket: Socket | undefined = undefined + socket: Socket | undefined = undefined, ) { socket = socket || io("/", { autoConnect: false, path: `${this.getBaseUrl()}socket.io` }); this.onInit = onInit; @@ -168,14 +167,18 @@ export class TaipyApp { this.routes = undefined; const id = getLocalStorageValue(TAIPY_CLIENT_ID, ""); this.sendWsMessage("ID", TAIPY_CLIENT_ID, id); - this.sendWsMessage("AID", "connect", ""); - this.sendWsMessage("GR", "", ""); if (id !== "") { this.clientId = id; + this.initApp() this.updateContext(this.path); } } + initApp() { + this.sendWsMessage("AID", "connect", ""); + this.sendWsMessage("GR", "", ""); + } + sendWsMessage(type: WsMessageType, id: string, payload: unknown, context: string | undefined = undefined) { if (context === undefined) { context = this.context; @@ -235,7 +238,6 @@ export class TaipyApp { this.sendWsMessage("U", encodedName, { value: value }); } - // Request Data from taipy backend // This will trigger the backend to send the data to the frontend requestData(encodedName: string, cb: RequestDataCallback, options?: RequestDataOptions) { diff --git a/frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts b/frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts index 3966d59eff..2e3de47ff5 100644 --- a/frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts +++ b/frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts @@ -146,6 +146,7 @@ export declare class TaipyApp { set onWsStatusUpdate(handler: OnWsStatusUpdate | undefined); onWsStatusUpdateEvent(messageQueue: string[]): void; init(): void; + initApp(): void; sendWsMessage(type: WsMessageType | string, id: string, payload: unknown, context?: string | undefined): void; registerWsAdapter(wsAdapter: WsAdapter): void; getEncodedName(varName: string, module: string): string | undefined; diff --git a/frontend/taipy-gui/base/src/wsAdapter.ts b/frontend/taipy-gui/base/src/wsAdapter.ts index 45bc9a62a0..a541bdf0c4 100644 --- a/frontend/taipy-gui/base/src/wsAdapter.ts +++ b/frontend/taipy-gui/base/src/wsAdapter.ts @@ -58,6 +58,7 @@ export class TaipyWsAdapter extends WsAdapter { const { id } = message as unknown as IdMessage; storeClientId(id); taipyApp.clientId = id; + taipyApp.initApp(); taipyApp.updateContext(taipyApp.path); } else if (message.type === "GMC") { const payload = message.payload as Record;