1- import React , { useEffect , useState } from "react" ;
1+ import React , { useCallback , useEffect , useRef , useState } from "react" ;
22import styled from "@emotion/styled" ;
33import { useRouter } from "next/router" ;
44import { DefaultEditorWorkspaceLayout } from "layouts/default-editor-workspace-layout" ;
@@ -67,6 +67,10 @@ export function Editor() {
6767 const targetted =
6868 find_node_by_id_under_entry ( targetId , root ?. entry ) ?? root ?. entry ;
6969
70+ const targetStateRef = useRef ( ) ;
71+ //@ts -ignore
72+ targetStateRef . current = targetted ;
73+
7074 useEffect ( ( ) => {
7175 // ------------------------------------------------------------
7276 // other platforms are not supported yet
@@ -88,6 +92,20 @@ export function Editor() {
8892 // ------------------------------------------------------------
8993 } , [ state . design ?. key , fat . accessToken ] ) ;
9094
95+ const on_result = ( result : Result ) => {
96+ //@ts -ignore
97+ if ( result . id == targetStateRef ?. current ?. id ) {
98+ setResult ( result ) ;
99+ }
100+ } ;
101+
102+ const on_preview_result = ( result : Result ) => {
103+ //@ts -ignore
104+ if ( result . id == targetStateRef ?. current ?. id ) {
105+ setPreview ( result ) ;
106+ }
107+ } ;
108+
91109 useEffect ( ( ) => {
92110 const __target = targetted ;
93111 if ( __target && framework_config ) {
@@ -102,12 +120,6 @@ export function Editor() {
102120 disable_components : ! enable_components ,
103121 } ;
104122
105- const on_result = ( result : Result ) => {
106- if ( result . id == targetted . id ) {
107- setResult ( result ) ;
108- }
109- } ;
110-
111123 // build code without assets fetch
112124 designToCode ( {
113125 input : _input ,
@@ -140,12 +152,6 @@ export function Editor() {
140152 disable_components : true ,
141153 } ;
142154
143- const on_preview_result = ( result : Result ) => {
144- if ( result . id == targetId ) {
145- setPreview ( result ) ;
146- }
147- } ;
148-
149155 // ----- for preview -----
150156 designToCode ( {
151157 input : _input ,
0 commit comments