Skip to content

Commit

Permalink
fix(states): Only check for state initialization in code components
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 697f7b2316ea65830cccfdd04dd912ef9f90c3bd
  • Loading branch information
FMota0 authored and actions-user committed Dec 18, 2024
1 parent 41b4090 commit ddccf1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/react-web/src/states/valtio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,9 @@ function renderTplComponent(
mergeEventHandlers(
props,
builtinEventHandlers,
getComponentStateOnChangePropNames(ctx.ownerComponent, node)
!isTplCodeComponent(node)
? getComponentStateOnChangePropNames(ctx.ownerComponent, node)
: new Set()
);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -2257,7 +2259,8 @@ function mergeEventHandlers(
if (
onChangeAttrs.has(toJsIdentifier(attr)) &&
args.length > 1 &&
args[1]
args[1] &&
args[1]._plasmic_state_init_
) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions platform/wab/src/wab/shared/codegen/react-p/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}`;
}
Expand Down Expand Up @@ -1933,7 +1933,9 @@ export function serializeTplComponentBase(
mergeEventHandlers(
attrs,
builtinEventHandlers,
getComponentStateOnChangePropNames(ctx.component, node)
!isTplCodeComponent(node)
? getComponentStateOnChangePropNames(ctx.component, node)
: new Set()
);
}

Expand Down

0 comments on commit ddccf1a

Please sign in to comment.