@plasmicapp/react-web 0.2.357 → 0.2.359

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,4 +66,5 @@ export interface Internal$State {
66
66
  stack: string[];
67
67
  visited: Set<string>;
68
68
  };
69
+ initializedLeafPaths: Set<string>;
69
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/react-web",
3
- "version": "0.2.357",
3
+ "version": "0.2.359",
4
4
  "description": "plasmic library for rendering in the presentational style",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
@@ -168,5 +168,5 @@
168
168
  "react": ">=16.8.0",
169
169
  "react-dom": ">=16.8.0"
170
170
  },
171
- "gitHead": "879304149b902b453a47fe674997fcad01ae4af8"
171
+ "gitHead": "53a85fd08ce84bfb2ed052a7ed9a662ad15bf8e8"
172
172
  }
@@ -1018,7 +1018,7 @@ function subscribeToValtio($$state, statePath, node) {
1018
1018
  }
1019
1019
  }
1020
1020
  function initializeStateValue($$state, initialStateCell, proxyRoot) {
1021
- var _a, _b, _c;
1021
+ var _a;
1022
1022
  var initialStateName = initialStateCell.node.getSpec().path;
1023
1023
  var stateAccess = new Set();
1024
1024
  $$state.stateInitializationEnv.visited.add(initialStateName);
@@ -1075,16 +1075,12 @@ function initializeStateValue($$state, initialStateCell, proxyRoot) {
1075
1075
  : clonedValue;
1076
1076
  set(proxyRoot, initialStateCell.path, value);
1077
1077
  }
1078
- catch (_d) {
1078
+ catch (_b) {
1079
1079
  // Setting the state to undefined to make sure it gets re-initialized
1080
1080
  // in case it changes values.
1081
1081
  initialStateCell.initialValue = undefined;
1082
1082
  set(proxyRoot, initialStateCell.path, undefined);
1083
1083
  }
1084
- //immediately fire onChange
1085
- if (initialSpec.onChangeProp) {
1086
- (_c = (_b = $$state.env.$props)[initialSpec.onChangeProp]) === null || _c === void 0 ? void 0 : _c.call(_b, initialValue);
1087
- }
1088
1084
  $$state.stateInitializationEnv.visited.delete(initialStateName);
1089
1085
  $$state.stateInitializationEnv.stack.pop();
1090
1086
  return initialValue;
@@ -1150,7 +1146,15 @@ function create$StateProxy($$state, leafHandlers) {
1150
1146
  (_b = (_a = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) === null || _b === void 0 ? void 0 : _b.call(_a, target, property, value, receiver);
1151
1147
  Reflect.set(target, property, value, receiver);
1152
1148
  if (nextSpec === null || nextSpec === void 0 ? void 0 : nextSpec.onChangeProp) {
1153
- (_d = (_c = $$state.env.$props)[nextSpec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, value);
1149
+ var pathKey = JSON.stringify(nextPath);
1150
+ var isInitOnChange = !$$state.initializedLeafPaths.has(pathKey);
1151
+ // We need to call the onChangeProp during initialization process so that the parent
1152
+ // state can be updated with the correct value. We will provide an addtionnal parameter
1153
+ // to the onChangeProp function to indicate that the call is made during initialization.
1154
+ (_d = (_c = $$state.env.$props)[nextSpec.onChangeProp]) === null || _d === void 0 ? void 0 : _d.call(_c, value, isInitOnChange);
1155
+ if (isInitOnChange) {
1156
+ $$state.initializedLeafPaths.add(pathKey);
1157
+ }
1154
1158
  }
1155
1159
  }
1156
1160
  if (!nextNode) {
@@ -1275,6 +1279,7 @@ function useDollarState(specs) {
1275
1279
  specs: [],
1276
1280
  registrationsQueue: [],
1277
1281
  stateInitializationEnv: { stack: [], visited: new Set() },
1282
+ initializedLeafPaths: new Set(),
1278
1283
  };
1279
1284
  })()).current;
1280
1285
  $$state.env = envFieldsAreNonNill(env);
@@ -1425,7 +1430,9 @@ function useDollarState(specs) {
1425
1430
  var spec = node.getSpec();
1426
1431
  if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
1427
1432
  var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
1428
- initializeStateValue($$state, stateCell, $state);
1433
+ if (stateCell.initialValue === UNINITIALIZED) {
1434
+ initializeStateValue($$state, stateCell, $state);
1435
+ }
1429
1436
  }
1430
1437
  });
1431
1438
  }, []);