@@ -8,6 +8,7 @@ import bundler from "@code-editor/esbuild-services";
88import assert from "assert" ;
99import { useDispatch } from "core/dispatch" ;
1010import { useTargetContainer } from "hooks" ;
11+ import { WidgetKey } from "@reflect-ui/core" ;
1112
1213const esbuild_base_html_code = `<div id="root"></div>` ;
1314
@@ -27,6 +28,8 @@ export function EditorPreviewDataProvider({
2728 const [ state ] = useEditorState ( ) ;
2829 const dispatch = useDispatch ( ) ;
2930
31+ const { target, root } = useTargetContainer ( ) ;
32+
3033 const updateBuildingState = useCallback (
3134 ( isBuilding : boolean ) => {
3235 dispatch ( {
@@ -67,9 +70,13 @@ export function EditorPreviewDataProvider({
6770
6871 const onEsbuildReactPreviewResult = useCallback (
6972 ( {
73+ key,
74+ initialSize,
7075 bundledjs,
7176 componentName,
7277 } : {
78+ key : WidgetKey ;
79+ initialSize : { width : number ; height : number } ;
7380 bundledjs : string ;
7481 componentName : string ;
7582 } ) => {
@@ -78,17 +85,14 @@ export function EditorPreviewDataProvider({
7885 data : {
7986 loader : "vanilla-esbuild-template" ,
8087 viewtype : "unknown" ,
81- widgetKey : state . currentPreview ?. widgetKey , // TODO: fixme
88+ widgetKey : key ,
8289 componentName : componentName ,
8390 fallbackSource : state . currentPreview ?. fallbackSource ,
8491 source : {
8592 html : esbuild_base_html_code ,
8693 javascript : bundledjs ,
8794 } ,
88- initialSize : {
89- width : undefined ,
90- height : undefined ,
91- } ,
95+ initialSize : initialSize ,
9296 isBuilding : false ,
9397 meta : {
9498 bundler : "esbuild-wasm" ,
@@ -102,8 +106,6 @@ export function EditorPreviewDataProvider({
102106 [ dispatch ]
103107 ) ;
104108
105- const { target, root } = useTargetContainer ( ) ;
106-
107109 const _is_mode_requires_preview_build =
108110 state . canvasMode === "fullscreen-preview" ||
109111 state . canvasMode === "isolated-view" ;
@@ -187,6 +189,14 @@ export function EditorPreviewDataProvider({
187189 if ( d . err == null ) {
188190 if ( d . code ) {
189191 onEsbuildReactPreviewResult ( {
192+ key : new WidgetKey ( {
193+ originName : target . name ,
194+ id : target . id ,
195+ } ) ,
196+ initialSize : {
197+ width : target . width ,
198+ height : target . height ,
199+ } ,
190200 bundledjs : d . code ,
191201 componentName : componentName ,
192202 } ) ;
0 commit comments