@plasmicapp/react-web 0.2.306 → 0.2.309

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.
@@ -1981,6 +1981,7 @@ function findStateCell(root, pathStr, repetitionIndex) {
1981
1981
  };
1982
1982
  }
1983
1983
 
1984
+ var defer = setTimeout;
1984
1985
  function isNum$1(value) {
1985
1986
  return typeof value === "symbol" ? false : !isNaN(+value);
1986
1987
  }
@@ -2271,6 +2272,22 @@ function useDollarState(specs) {
2271
2272
  rest[_i - 1] = arguments[_i];
2272
2273
  }
2273
2274
  var _a = extractDollarStateParametersBackwardCompatible.apply(void 0, __spreadArray([], __read(rest), false)), env = _a.env, opts = _a.opts;
2275
+ var _b = __read(React__default.useState(), 2), setState = _b[1];
2276
+ var mountedRef = React__default.useRef(false);
2277
+ var isMounted = React__default.useCallback(function () { return mountedRef.current; }, []);
2278
+ React__default.useEffect(function () {
2279
+ mountedRef.current = true;
2280
+ return function () { return (mountedRef.current = false); };
2281
+ }, []);
2282
+ var pendingUpdate = React__default.useRef(false);
2283
+ var forceUpdate = React__default.useCallback(function () {
2284
+ return defer(function () {
2285
+ if (isMounted()) {
2286
+ setState([]);
2287
+ pendingUpdate.current = false;
2288
+ }
2289
+ });
2290
+ }, []);
2274
2291
  var $$state = React__default.useRef((function () {
2275
2292
  var rootSpecTree = buildTree(specs);
2276
2293
  return {
@@ -2279,7 +2296,7 @@ function useDollarState(specs) {
2279
2296
  stateValues: proxy({}),
2280
2297
  env: envFieldsAreNonNill(env),
2281
2298
  specs: [],
2282
- registrationsQueue: proxy([]),
2299
+ registrationsQueue: [],
2283
2300
  stateInitializationEnv: { stack: [], visited: new Set() },
2284
2301
  };
2285
2302
  })()).current;
@@ -2316,14 +2333,18 @@ function useDollarState(specs) {
2316
2333
  ? envFieldsAreNonNill(overrideEnv)
2317
2334
  : $$state.env;
2318
2335
  if (!deepEqual(stateCell.initialValue, f(__assign({ $state: $state }, env)))) {
2319
- $$state.registrationsQueue.push(mkUntrackedValue({
2336
+ $$state.registrationsQueue.push({
2320
2337
  node: node,
2321
2338
  path: realPath,
2322
2339
  f: f,
2323
2340
  overrideEnv: overrideEnv
2324
2341
  ? envFieldsAreNonNill(overrideEnv)
2325
2342
  : undefined,
2326
- }));
2343
+ });
2344
+ if (!pendingUpdate.current) {
2345
+ pendingUpdate.current = true;
2346
+ forceUpdate();
2347
+ }
2327
2348
  }
2328
2349
  } }, ((opts === null || opts === void 0 ? void 0 : opts.inCanvas)
2329
2350
  ? {
@@ -2394,9 +2415,16 @@ function useDollarState(specs) {
2394
2415
  getStateCells($state, $$state.rootSpecTree).forEach(function (stateCell) {
2395
2416
  var _a;
2396
2417
  if (stateCell.initFunc) {
2397
- var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, __assign({ $state: $state }, ((_a = stateCell.overrideEnv) !== null && _a !== void 0 ? _a : envFieldsAreNonNill(env))));
2398
- if (!deepEqual(newInit, stateCell.initialValue)) {
2399
- resetSpecs.push({ stateCell: stateCell });
2418
+ try {
2419
+ var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, __assign({ $state: $state }, ((_a = stateCell.overrideEnv) !== null && _a !== void 0 ? _a : envFieldsAreNonNill(env))));
2420
+ if (!deepEqual(newInit, stateCell.initialValue)) {
2421
+ resetSpecs.push({ stateCell: stateCell });
2422
+ }
2423
+ }
2424
+ catch (_b) {
2425
+ // Exception may be thrown from initFunc -- for example, if it tries to access $queries
2426
+ // that are still loading. We swallow those here, since we're only interested in
2427
+ // checking if the init value has changed, not in handling these errors.
2400
2428
  }
2401
2429
  }
2402
2430
  });
@@ -2413,7 +2441,7 @@ function useDollarState(specs) {
2413
2441
  stateCell.overrideEnv = overrideEnv;
2414
2442
  reInitializeState(stateCell);
2415
2443
  }
2416
- }, [$$state.registrationsQueue.length]);
2444
+ });
2417
2445
  // immediately initialize exposed non-private states
2418
2446
  useIsomorphicLayoutEffect(function () {
2419
2447
  $$state.specTreeLeaves.forEach(function (node) {
@@ -2426,7 +2454,6 @@ function useDollarState(specs) {
2426
2454
  }, []);
2427
2455
  // Re-render if any value changed in one of these objects
2428
2456
  useSnapshot($$state.stateValues, { sync: true });
2429
- useSnapshot($$state.registrationsQueue, { sync: true });
2430
2457
  return $state;
2431
2458
  }
2432
2459