diff --git a/packages/react-web/src/states/valtio.tsx b/packages/react-web/src/states/valtio.tsx index 6886de01147..01dda709e86 100644 --- a/packages/react-web/src/states/valtio.tsx +++ b/packages/react-web/src/states/valtio.tsx @@ -323,7 +323,9 @@ function create$StateProxy( // We need to call the onChangeProp during initialization process so that the parent // state can be updated with the correct value. We will provide an addtionnal parameter // to the onChangeProp function to indicate that the call is made during initialization. - $$state.env.$props[nextSpec.onChangeProp]?.(value, isInitOnChange); + $$state.env.$props[nextSpec.onChangeProp]?.(value, { + _plasmic_state_init_: isInitOnChange, + }); if (isInitOnChange) { $$state.initializedLeafPaths.add(pathKey); diff --git a/platform/wab/src/wab/client/components/canvas/canvas-rendering.ts b/platform/wab/src/wab/client/components/canvas/canvas-rendering.ts index f1cfd351a0c..6a77d8285f0 100755 --- a/platform/wab/src/wab/client/components/canvas/canvas-rendering.ts +++ b/platform/wab/src/wab/client/components/canvas/canvas-rendering.ts @@ -1627,7 +1627,9 @@ function renderTplComponent( mergeEventHandlers( props, builtinEventHandlers, - getComponentStateOnChangePropNames(ctx.ownerComponent, node) + !isTplCodeComponent(node) + ? getComponentStateOnChangePropNames(ctx.ownerComponent, node) + : new Set() ); } @@ -2248,7 +2250,7 @@ function mergeEventHandlers( attrBuiltinEventHandlers: any[], userAttr: any[] ) => { - return async (...args: unknown[]) => { + return async (...args: any[]) => { for (const handler of attrBuiltinEventHandlers) { await handler.apply(null, args); } @@ -2257,7 +2259,8 @@ function mergeEventHandlers( if ( onChangeAttrs.has(toJsIdentifier(attr)) && args.length > 1 && - args[1] + args[1] && + args[1]._plasmic_state_init_ ) { return; } diff --git a/platform/wab/src/wab/shared/codegen/react-p/index.ts b/platform/wab/src/wab/shared/codegen/react-p/index.ts index 533ff92bdcf..9421ed2263e 100644 --- a/platform/wab/src/wab/shared/codegen/react-p/index.ts +++ b/platform/wab/src/wab/shared/codegen/react-p/index.ts @@ -1483,7 +1483,7 @@ function mergeEventHandlers( // which is a boolean indicating whether the onChange event is triggered during the state initialization phase. const maybeHaltUserAttr = (attr: string) => { if (onChangeAttrs.has(toJsIdentifier(attr))) { - return `if(eventArgs.length > 1 && eventArgs[1]) { + return `if(eventArgs.length > 1 && eventArgs[1] && eventArgs[1]._plasmic_state_init_) { return; }`; } @@ -1933,7 +1933,9 @@ export function serializeTplComponentBase( mergeEventHandlers( attrs, builtinEventHandlers, - getComponentStateOnChangePropNames(ctx.component, node) + !isTplCodeComponent(node) + ? getComponentStateOnChangePropNames(ctx.component, node) + : new Set() ); }