@my-react/react-reconciler-compact 0.0.8 → 0.0.9

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.
@@ -311,6 +311,7 @@ function requireIndex_production_1 () {
311
311
  STATE_TYPE[STATE_TYPE["__retrigger__"] = 512] = "__retrigger__";
312
312
  STATE_TYPE[STATE_TYPE["__reschedule__"] = 1024] = "__reschedule__";
313
313
  STATE_TYPE[STATE_TYPE["__recreate__"] = 2048] = "__recreate__";
314
+ STATE_TYPE[STATE_TYPE["__suspense__"] = 4096] = "__suspense__";
314
315
  })(exports.STATE_TYPE || (exports.STATE_TYPE = {}));
315
316
 
316
317
  exports.PATCH_TYPE = void 0;
@@ -1330,7 +1331,7 @@ function requireIndex_production_1 () {
1330
1331
  if (typeof element === "object" && element !== null) {
1331
1332
  nodeType = myreactSharedExports.merge(nodeType, exports.NODE_TYPE.__empty__);
1332
1333
  }
1333
- else if (element === null || element === undefined || typeof element === "boolean" || typeof element === "function") {
1334
+ else if (element === null || element === undefined || typeof element === "boolean" || typeof element === "function" || element === "") {
1334
1335
  nodeType = myreactSharedExports.merge(nodeType, exports.NODE_TYPE.__null__);
1335
1336
  }
1336
1337
  else {
@@ -1451,7 +1452,7 @@ function requireIndex_production_1 () {
1451
1452
  throw new Error("[@my-react/react] invalid symbol element type \"".concat(elementType === null || elementType === void 0 ? void 0 : elementType.toString(), "\""));
1452
1453
  }
1453
1454
  }
1454
- else if (typeof elementType === "string") {
1455
+ else if (typeof elementType === "string" && elementType !== "") {
1455
1456
  nodeType = myreactSharedExports.merge(nodeType, exports.NODE_TYPE.__plain__);
1456
1457
  }
1457
1458
  else {
@@ -1488,7 +1489,17 @@ function requireIndex_production_1 () {
1488
1489
  return new Set(Array.from(fibers || []).map(function (fiber) { return fiberToDispatchMap.get(fiber); }));
1489
1490
  };
1490
1491
  var getCurrentDispatchFromFiber = function (fiber) {
1491
- return fiberToDispatchMap.get(fiber);
1492
+ var dispatch = fiberToDispatchMap.get(fiber);
1493
+ if (dispatch)
1494
+ return dispatch;
1495
+ var parent = fiber.parent;
1496
+ while (parent) {
1497
+ var typedFiberRoot = parent;
1498
+ if (typedFiberRoot.renderDispatch) {
1499
+ return typedFiberRoot.renderDispatch;
1500
+ }
1501
+ parent = parent.parent;
1502
+ }
1492
1503
  };
1493
1504
  var getElementFromRefreshIfExist = function (element) {
1494
1505
  var _a, _b;
@@ -1539,10 +1550,10 @@ function requireIndex_production_1 () {
1539
1550
  var dispatchError = function (_params) {
1540
1551
  var fiber = _params.fiber || currentRunningFiber$3.current;
1541
1552
  if (!fiber) {
1542
- throw new Error("No fiber found for dispatching error.");
1553
+ // a normal error
1554
+ throw _params.error;
1543
1555
  }
1544
- if (myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__unmount__))
1545
- return;
1556
+ // if (include(fiber.state, STATE_TYPE.__unmount__)) return;
1546
1557
  var dispatch = getCurrentDispatchFromFiber(fiber);
1547
1558
  if (!dispatch) {
1548
1559
  throw new Error("No dispatch found for the current running fiber.");
@@ -1554,14 +1565,25 @@ function requireIndex_production_1 () {
1554
1565
  if (!fiber) {
1555
1566
  throw new Error("No fiber found for dispatching promise.");
1556
1567
  }
1557
- if (myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__unmount__))
1558
- return;
1568
+ // if (include(fiber.state, STATE_TYPE.__unmount__)) return;
1559
1569
  var dispatch = getCurrentDispatchFromFiber(fiber);
1560
1570
  if (!dispatch) {
1561
1571
  throw new Error("No dispatch found for the current running fiber.");
1562
1572
  }
1563
1573
  return dispatch.dispatchPromise(_params);
1564
1574
  };
1575
+ var dispatchSuspensePromise = function (_params) {
1576
+ var fiber = _params.fiber || currentRunningFiber$3.current;
1577
+ if (!fiber) {
1578
+ throw new Error("No fiber found for dispatching suspense promise.");
1579
+ }
1580
+ // if (include(fiber.state, STATE_TYPE.__unmount__)) return;
1581
+ var dispatch = getCurrentDispatchFromFiber(fiber);
1582
+ if (!dispatch) {
1583
+ throw new Error("No dispatch found for the current running fiber.");
1584
+ }
1585
+ return dispatch.dispatchSuspensePromise(_params);
1586
+ };
1565
1587
  var readContext = function (_params) {
1566
1588
  var fiber = currentRunningFiber$3.current;
1567
1589
  if (!fiber) {
@@ -1606,6 +1628,7 @@ function requireIndex_production_1 () {
1606
1628
  scheduler.dispatchHook = dispatchHook;
1607
1629
  scheduler.dispatchError = dispatchError;
1608
1630
  scheduler.dispatchPromise = dispatchPromise;
1631
+ scheduler.dispatchSuspensePromise = dispatchSuspensePromise;
1609
1632
  };
1610
1633
 
1611
1634
  react.__my_react_shared__.enableHMRForDev;
@@ -1809,6 +1832,16 @@ function requireIndex_production_1 () {
1809
1832
  child = child.sibling;
1810
1833
  }
1811
1834
  };
1835
+ var effectCallbackList = new myreactSharedExports.ListTree();
1836
+ var addEffectCallback = function (cb) {
1837
+ effectCallbackList.push(cb);
1838
+ };
1839
+ var flushEffectCallback = function () {
1840
+ effectCallbackList.listToFoot(function (cb) {
1841
+ cb();
1842
+ });
1843
+ effectCallbackList.clear();
1844
+ };
1812
1845
  var effect = defaultInvokeEffect;
1813
1846
  var layoutEffect = defaultInvokeLayoutEffect;
1814
1847
  var insertionEffect = defaultInvokeInsertionEffect;
@@ -1875,7 +1908,10 @@ function requireIndex_production_1 () {
1875
1908
  }
1876
1909
  currentRunningFiber$2.current = null;
1877
1910
  }
1878
- if (!myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__retrigger__)) {
1911
+ if (myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__suspense__)) {
1912
+ fiber.state = myreactSharedExports.STATE_TYPE.__recreate__;
1913
+ }
1914
+ else if (!myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__retrigger__)) {
1879
1915
  fiber.state = myreactSharedExports.STATE_TYPE.__stable__;
1880
1916
  }
1881
1917
  else {
@@ -1914,7 +1950,10 @@ function requireIndex_production_1 () {
1914
1950
  currentRunningFiber$2.current = null;
1915
1951
  triggerFiberUpdateListener(renderDispatch, fiber);
1916
1952
  }
1917
- if (!myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__retrigger__)) {
1953
+ if (myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__suspense__)) {
1954
+ fiber.state = myreactSharedExports.STATE_TYPE.__recreate__;
1955
+ }
1956
+ else if (!myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__retrigger__)) {
1918
1957
  fiber.state = myreactSharedExports.STATE_TYPE.__stable__;
1919
1958
  }
1920
1959
  else {
@@ -2114,15 +2153,12 @@ function requireIndex_production_1 () {
2114
2153
  throw new Error("[@my-react/reconciler] should not process async load list on sync mount without enableAsyncLoad, you may use a wrong renderDispatch instance");
2115
2154
  }
2116
2155
  }
2117
- // TODO update flow
2118
2156
  if (enableSuspenseRoot$3.current) {
2119
2157
  var suspenseField_2 = getInstanceFieldByInstance(renderDispatch);
2120
2158
  var list = suspenseField_2.asyncLoadList.getAll();
2121
2159
  if (list.length === 0)
2122
2160
  return;
2123
2161
  if (renderDispatch.enableAsyncLoad) {
2124
- // defaultDeleteCurrentEffect(renderDispatch, renderDispatch.rootFiber);
2125
- // defaultDeleteChildEffect(renderDispatch, renderDispatch.rootFiber);
2126
2162
  var allPendingLoadArray = list.filter(function (item) {
2127
2163
  if (myreactSharedExports.isPromise(item)) {
2128
2164
  return typeof item.status !== "string";
@@ -2169,13 +2205,6 @@ function requireIndex_production_1 () {
2169
2205
  });
2170
2206
  }); }));
2171
2207
  }
2172
- // suspenseField.isHidden = true;
2173
- // const root = renderDispatch.rootFiber;
2174
- // root.state = remove(root.state, STATE_TYPE.__stable__);
2175
- // root.state = merge(root.state, STATE_TYPE.__retrigger__);
2176
- // // TODO use hide tree to improve
2177
- // mountLoopAll(renderDispatch, root);
2178
- // suspenseField.isHidden = false;
2179
2208
  }
2180
2209
  else {
2181
2210
  throw new Error("[@my-react/reconciler] should not process async load list on sync mount without enableAsyncLoad, you may use a wrong renderDispatch instance");
@@ -2302,66 +2331,12 @@ function requireIndex_production_1 () {
2302
2331
  }
2303
2332
  // TODO update flow
2304
2333
  if (enableSuspenseRoot$2.current) {
2305
- var suspenseField_1 = getInstanceFieldByInstance(renderDispatch);
2306
- var list = suspenseField_1.asyncLoadList.getAll();
2334
+ var suspenseField = getInstanceFieldByInstance(renderDispatch);
2335
+ var list = suspenseField.asyncLoadList.getAll();
2307
2336
  if (list.length === 0)
2308
2337
  return;
2309
2338
  if (renderDispatch.enableAsyncLoad) {
2310
- // defaultDeleteCurrentEffect(renderDispatch, renderDispatch.rootFiber);
2311
- // defaultDeleteChildEffect(renderDispatch, renderDispatch.rootFiber);
2312
- var allPendingLoadArray = list.filter(function (item) {
2313
- if (myreactSharedExports.isPromise(item)) {
2314
- return typeof item.status !== "string";
2315
- }
2316
- else {
2317
- return !item._loading && !item._loaded && !item._error;
2318
- }
2319
- });
2320
- if (allPendingLoadArray.length) {
2321
- allPendingLoadArray.forEach(function (item) { var _a; return (_a = item._list) === null || _a === void 0 ? void 0 : _a.forEach(function (node) { return defaultDeleteCurrentEffect(renderDispatch, node); }); });
2322
- Promise.all(allPendingLoadArray.map(function (item) { return __awaiter(void 0, void 0, void 0, function () {
2323
- var allFiber;
2324
- var _a;
2325
- return __generator(this, function (_b) {
2326
- switch (_b.label) {
2327
- case 0:
2328
- if (!myreactSharedExports.isPromise(item)) return [3 /*break*/, 2];
2329
- return [4 /*yield*/, renderDispatch.processPromise(item)];
2330
- case 1:
2331
- _b.sent();
2332
- return [3 /*break*/, 4];
2333
- case 2: return [4 /*yield*/, renderDispatch.processLazy(item)];
2334
- case 3:
2335
- _b.sent();
2336
- _b.label = 4;
2337
- case 4:
2338
- allFiber = new Set(item._list);
2339
- (_a = item._list) === null || _a === void 0 ? void 0 : _a.clear();
2340
- allFiber.forEach(function (node) {
2341
- node.state = myreactSharedExports.STATE_TYPE.__recreate__;
2342
- var renderScheduler = currentScheduler$d.current;
2343
- var updater = {
2344
- type: myreactSharedExports.UpdateQueueType.suspense,
2345
- trigger: node,
2346
- isSync: true,
2347
- isForce: true,
2348
- payLoad: [item],
2349
- };
2350
- renderScheduler.dispatchState(updater);
2351
- });
2352
- suspenseField_1.asyncLoadList.uniDelete(item);
2353
- return [2 /*return*/];
2354
- }
2355
- });
2356
- }); }));
2357
- }
2358
- // suspenseField.isHidden = true;
2359
- // const root = renderDispatch.rootFiber;
2360
- // root.state = remove(root.state, STATE_TYPE.__stable__);
2361
- // root.state = merge(root.state, STATE_TYPE.__retrigger__);
2362
- // // TODO use hide tree to improve
2363
- // mountLoopAll(renderDispatch, root);
2364
- // suspenseField.isHidden = false;
2339
+ throw new Error("[@my-react/reconciler] not implemented yet");
2365
2340
  }
2366
2341
  else {
2367
2342
  throw new Error("[@my-react/reconciler] should not process async load list on sync mount without enableAsyncLoad, you may use a wrong renderDispatch instance");
@@ -2905,7 +2880,7 @@ function requireIndex_production_1 () {
2905
2880
  var allQueue = fiber.updateQueue;
2906
2881
  var node = allQueue === null || allQueue === void 0 ? void 0 : allQueue.head;
2907
2882
  var needUpdate = true;
2908
- var isSync = false;
2883
+ var isSync = true;
2909
2884
  var isForce = false;
2910
2885
  var isImmediate = false;
2911
2886
  var isRetrigger = false;
@@ -3136,7 +3111,7 @@ function requireIndex_production_1 () {
3136
3111
  var allQueue = fiber.updateQueue;
3137
3112
  var node = allQueue === null || allQueue === void 0 ? void 0 : allQueue.head;
3138
3113
  var needUpdate = false;
3139
- var isSync = false;
3114
+ var isSync = true;
3140
3115
  var isForce = false;
3141
3116
  var isImmediate = false;
3142
3117
  var isRetrigger = false;
@@ -3256,7 +3231,7 @@ function requireIndex_production_1 () {
3256
3231
  var renderScheduler = currentScheduler$c.current;
3257
3232
  var node = allQueue === null || allQueue === void 0 ? void 0 : allQueue.head;
3258
3233
  var needUpdate = true;
3259
- var isSync = false;
3234
+ var isSync = true;
3260
3235
  var isForce = false;
3261
3236
  var isImmediate = false;
3262
3237
  var isRetrigger = false;
@@ -3579,6 +3554,7 @@ function requireIndex_production_1 () {
3579
3554
 
3580
3555
  var globalLoop$2 = react.__my_react_internal__.globalLoop, currentScheduler$a = react.__my_react_internal__.currentScheduler;
3581
3556
  var scheduleUpdateFromRoot = function (renderDispatch) {
3557
+ flushEffectCallback();
3582
3558
  var allLive = renderDispatch.pendingUpdateFiberArray.getAll().filter(function (f) { return myreactSharedExports.exclude(f.state, myreactSharedExports.STATE_TYPE.__unmount__); });
3583
3559
  renderDispatch.pendingUpdateFiberArray.clear();
3584
3560
  if (allLive.length) {
@@ -3684,7 +3660,7 @@ function requireIndex_production_1 () {
3684
3660
  return myreactSharedExports.include(renderDispatch.runtimeFiber.nextWorkingFiber.state, myreactSharedExports.STATE_TYPE.__triggerSync__ | myreactSharedExports.STATE_TYPE.__triggerSyncForce__);
3685
3661
  // include(renderDispatch.runtimeFiber.nextWorkingFiber.state, STATE_TYPE.__retrigger__)
3686
3662
  }
3687
- function updateConCurrentNextFrame(renderDispatch) {
3663
+ function updateConcurrentNextFrame(renderDispatch) {
3688
3664
  var renderScheduler = currentScheduler$9.current;
3689
3665
  var hasSync = updateLoopConcurrentFromRoot(renderDispatch);
3690
3666
  if (renderDispatch.runtimeFiber.nextWorkingFiber) {
@@ -3697,7 +3673,7 @@ function requireIndex_production_1 () {
3697
3673
  updateSyncFromRoot(renderDispatch);
3698
3674
  }
3699
3675
  else {
3700
- updateConCurrentNextFrame(renderDispatch);
3676
+ updateConcurrentNextFrame(renderDispatch);
3701
3677
  }
3702
3678
  });
3703
3679
  }
@@ -3705,8 +3681,7 @@ function requireIndex_production_1 () {
3705
3681
  else {
3706
3682
  processAsyncLoadListOnUpdate(renderDispatch);
3707
3683
  finishUpdateConcurrentFromRoot(renderDispatch);
3708
- renderScheduler.microTask(function callScheduleNext() {
3709
- // TODO! flash all effect
3684
+ renderScheduler.macroTask(function callScheduleNext() {
3710
3685
  globalLoop$1.current = false;
3711
3686
  scheduleNext(renderDispatch);
3712
3687
  });
@@ -3726,7 +3701,7 @@ function requireIndex_production_1 () {
3726
3701
  updateSyncFromRoot(renderDispatch);
3727
3702
  }
3728
3703
  else {
3729
- updateConCurrentNextFrame(renderDispatch);
3704
+ updateConcurrentNextFrame(renderDispatch);
3730
3705
  }
3731
3706
  });
3732
3707
  }
@@ -3734,8 +3709,7 @@ function requireIndex_production_1 () {
3734
3709
  else {
3735
3710
  processAsyncLoadListOnUpdate(renderDispatch);
3736
3711
  finishUpdateConcurrentFromRoot(renderDispatch);
3737
- renderScheduler.microTask(function callScheduleNext() {
3738
- // TODO! flash all effect
3712
+ renderScheduler.macroTask(function callScheduleNext() {
3739
3713
  globalLoop$1.current = false;
3740
3714
  scheduleNext(renderDispatch);
3741
3715
  });
@@ -3776,7 +3750,9 @@ function requireIndex_production_1 () {
3776
3750
  if (!field)
3777
3751
  throw new Error("[@my-react/react] hook instance not found, look like a bug for @my-react");
3778
3752
  var typedField = field;
3779
- typedField.dispatch = function (action) { return hookNode._update({ payLoad: action, isForce: false, isSync: enableSyncFlush.current }); };
3753
+ typedField.dispatch = function dispatchAction(action) {
3754
+ hookNode._update({ payLoad: action, isForce: false, isSync: enableSyncFlush.current });
3755
+ };
3780
3756
  };
3781
3757
 
3782
3758
  var currentComponentFiber$3 = react.__my_react_internal__.currentComponentFiber;
@@ -3812,12 +3788,22 @@ function requireIndex_production_1 () {
3812
3788
  };
3813
3789
  var defaultOptimisticReducer = function (state) { return state; };
3814
3790
  var createHookNode = function (renderDispatch, _a, fiber) {
3815
- var _b;
3791
+ var _b, _c;
3816
3792
  var type = _a.type, value = _a.value, reducer = _a.reducer, deps = _a.deps;
3817
3793
  var currentHook = (_b = currentHookTreeNode$2.current) === null || _b === void 0 ? void 0 : _b.value;
3818
3794
  var currentHookIndex = currentHookNodeIndex$2.current;
3795
+ var currentIsReCreate = myreactSharedExports.include(fiber.state, myreactSharedExports.STATE_TYPE.__recreate__);
3819
3796
  if (currentHook) {
3820
- throw new Error("[@my-react/react] should not have a hookList for current node, this is a bug for @my-react");
3797
+ if (currentIsReCreate) {
3798
+ if (currentHookIndex === 0) {
3799
+ defaultDeleteChildEffect(renderDispatch, fiber);
3800
+ defaultDeleteCurrentEffect(renderDispatch, fiber);
3801
+ fiber.hookList.clear();
3802
+ }
3803
+ }
3804
+ else {
3805
+ throw new Error("[@my-react/react] should not have a hookList for current node, this is a bug for @my-react");
3806
+ }
3821
3807
  }
3822
3808
  var hookNode = new MyReactHookNode(type, value, reducer || defaultReducer, deps);
3823
3809
  initInstance(hookNode);
@@ -3841,6 +3827,10 @@ function requireIndex_production_1 () {
3841
3827
  if (hookNode.type === myreactSharedExports.HOOK_TYPE.useRef || hookNode.type === myreactSharedExports.HOOK_TYPE.useCallback || hookNode.type === myreactSharedExports.HOOK_TYPE.useDeferredValue) {
3842
3828
  hookNode.result = hookNode.value;
3843
3829
  }
3830
+ // cache ref state from recreate
3831
+ if (hookNode.type === myreactSharedExports.HOOK_TYPE.useRef && currentHook && currentHook.type === myreactSharedExports.HOOK_TYPE.useRef) {
3832
+ hookNode.result = currentHook.result;
3833
+ }
3844
3834
  if (hookNode.type === myreactSharedExports.HOOK_TYPE.useId) {
3845
3835
  hookNode.result = "\u00AB-".concat(currentHookIndex, "-").concat(renderDispatch.uniqueIdCount++, "-\u00BB");
3846
3836
  hookNode.cancel = function () { return renderDispatch.uniqueIdCount--; };
@@ -3863,12 +3853,13 @@ function requireIndex_production_1 () {
3863
3853
  return safeCallWithCurrentFiber({
3864
3854
  fiber: fiber,
3865
3855
  action: function safeCallGetSnapshot() {
3866
- var _a;
3867
3856
  return renderDispatch.isAppMounted
3868
3857
  ? storeApi_1.getSnapshot.call(null)
3869
- : storeApi_1.getServerSnapshot
3870
- ? (_a = storeApi_1.getServerSnapshot) === null || _a === void 0 ? void 0 : _a.call(null)
3871
- : storeApi_1.getSnapshot.call(null);
3858
+ : // SEE https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L33
3859
+ // : storeApi.getServerSnapshot
3860
+ // ? storeApi.getServerSnapshot?.call(null)
3861
+ // : storeApi.getSnapshot.call(null);
3862
+ storeApi_1.getSnapshot.call(null);
3872
3863
  },
3873
3864
  });
3874
3865
  };
@@ -3962,6 +3953,7 @@ function requireIndex_production_1 () {
3962
3953
  },
3963
3954
  };
3964
3955
  }
3956
+ currentHookTreeNode$2.current = (_c = currentHookTreeNode$2.current) === null || _c === void 0 ? void 0 : _c.next;
3965
3957
  return hookNode;
3966
3958
  };
3967
3959
 
@@ -4506,7 +4498,8 @@ function requireIndex_production_1 () {
4506
4498
  renderDispatch.pendingUpdate(fiber);
4507
4499
  }
4508
4500
  }
4509
- if (nextRef && prevRef !== nextRef) {
4501
+ if (prevRef !== nextRef) {
4502
+ fiber.refPrevious = prevRef;
4510
4503
  renderDispatch.pendingRef(fiber);
4511
4504
  }
4512
4505
  if (fiber !== prevFiber) {
@@ -4659,8 +4652,8 @@ function requireIndex_production_1 () {
4659
4652
  return updateFiberNode(renderDispatch, { fiber: draftFiber_1, parent: parentFiber, prevFiber: prevFiberChild }, newElement);
4660
4653
  }
4661
4654
  else {
4662
- renderDispatch.generateChangedList(parentFiber);
4663
- renderDispatch.pendingUnmount(parentFiber, draftFiber_1);
4655
+ draftFiber_1 && renderDispatch.generateChangedList(parentFiber);
4656
+ draftFiber_1 && renderDispatch.pendingUnmount(parentFiber, draftFiber_1);
4664
4657
  return createFragmentWithUpdate(renderDispatch, newChild, parentFiber);
4665
4658
  }
4666
4659
  }
@@ -4677,7 +4670,7 @@ function requireIndex_production_1 () {
4677
4670
  }
4678
4671
  else {
4679
4672
  draftFiber && renderDispatch.pendingUnmount(parentFiber, draftFiber);
4680
- renderDispatch.generateChangedList(parentFiber);
4673
+ draftFiber && renderDispatch.generateChangedList(parentFiber);
4681
4674
  return createFiberNode(renderDispatch, { parent: parentFiber, type: "position" }, newChild);
4682
4675
  }
4683
4676
  };
@@ -4692,9 +4685,13 @@ function requireIndex_production_1 () {
4692
4685
  var isUpdate = myreactSharedExports.exclude(parentFiber.state, myreactSharedExports.STATE_TYPE.__create__);
4693
4686
  var isHMR = myreactSharedExports.include(parentFiber.state, myreactSharedExports.STATE_TYPE.__hmr__);
4694
4687
  var isRetrigger = myreactSharedExports.include(parentFiber.state, myreactSharedExports.STATE_TYPE.__retrigger__);
4688
+ var isSuspense = myreactSharedExports.include(parentFiber.state, myreactSharedExports.STATE_TYPE.__suspense__);
4695
4689
  // is current is retrigger update, skip update children
4696
4690
  if (isRetrigger)
4697
4691
  return;
4692
+ // if is suspense, skip update children
4693
+ if (isSuspense)
4694
+ return;
4698
4695
  if (isUpdate || isHMR) {
4699
4696
  var _a = getExistingChildren(parentFiber), existingChildrenMap = _a.existingChildrenMap, existingChildrenArray = _a.existingChildrenArray;
4700
4697
  parentFiber.child = null;
@@ -4780,6 +4777,11 @@ function requireIndex_production_1 () {
4780
4777
  };
4781
4778
 
4782
4779
  var currentHookTreeNode = react.__my_react_internal__.currentHookTreeNode, currentHookNodeIndex$1 = react.__my_react_internal__.currentHookNodeIndex, currentScheduler$4 = react.__my_react_internal__.currentScheduler;
4780
+ var triggerState = myreactSharedExports.STATE_TYPE.__triggerSync__ |
4781
+ myreactSharedExports.STATE_TYPE.__triggerSyncForce__ |
4782
+ myreactSharedExports.STATE_TYPE.__triggerConcurrent__ |
4783
+ myreactSharedExports.STATE_TYPE.__triggerConcurrentForce__ |
4784
+ myreactSharedExports.STATE_TYPE.__retrigger__;
4783
4785
  var processFunction = function (fiber) {
4784
4786
  var _a;
4785
4787
  currentHookTreeNode.current = (_a = fiber.hookList) === null || _a === void 0 ? void 0 : _a.head;
@@ -4791,14 +4793,20 @@ function requireIndex_production_1 () {
4791
4793
  children = safeCallWithCurrentFiber({
4792
4794
  fiber: fiber,
4793
4795
  action: function safeCallForwardRefFunctionalComponent() {
4794
- var _a, _b;
4796
+ var _a, _b, _c, _d;
4795
4797
  var re = undefined;
4796
4798
  try {
4797
4799
  re = typedElementTypeWithRef_1(fiber.pendingProps, fiber.ref);
4798
4800
  }
4799
4801
  catch (e) {
4800
4802
  if (myreactSharedExports.isPromise(e)) {
4801
- re = (_b = (_a = currentScheduler$4.current) === null || _a === void 0 ? void 0 : _a.dispatchPromise) === null || _b === void 0 ? void 0 : _b.call(_a, { fiber: fiber, promise: e });
4803
+ var currentIsTrigger = myreactSharedExports.include(fiber.state, triggerState);
4804
+ if (currentIsTrigger) {
4805
+ re = (_b = (_a = currentScheduler$4.current) === null || _a === void 0 ? void 0 : _a.dispatchSuspensePromise) === null || _b === void 0 ? void 0 : _b.call(_a, { fiber: fiber, promise: e });
4806
+ }
4807
+ else {
4808
+ re = (_d = (_c = currentScheduler$4.current) === null || _c === void 0 ? void 0 : _c.dispatchPromise) === null || _d === void 0 ? void 0 : _d.call(_c, { fiber: fiber, promise: e });
4809
+ }
4802
4810
  }
4803
4811
  else {
4804
4812
  throw e;
@@ -4812,14 +4820,20 @@ function requireIndex_production_1 () {
4812
4820
  children = safeCallWithCurrentFiber({
4813
4821
  fiber: fiber,
4814
4822
  action: function safeCallFunctionalComponent() {
4815
- var _a, _b;
4823
+ var _a, _b, _c, _d;
4816
4824
  var re = undefined;
4817
4825
  try {
4818
4826
  re = typedElementType(fiber.pendingProps);
4819
4827
  }
4820
4828
  catch (e) {
4821
4829
  if (myreactSharedExports.isPromise(e)) {
4822
- re = (_b = (_a = currentScheduler$4.current) === null || _a === void 0 ? void 0 : _a.dispatchPromise) === null || _b === void 0 ? void 0 : _b.call(_a, { fiber: fiber, promise: e });
4830
+ var currentIsTrigger = myreactSharedExports.include(fiber.state, triggerState);
4831
+ if (currentIsTrigger) {
4832
+ re = (_b = (_a = currentScheduler$4.current) === null || _a === void 0 ? void 0 : _a.dispatchSuspensePromise) === null || _b === void 0 ? void 0 : _b.call(_a, { fiber: fiber, promise: e });
4833
+ }
4834
+ else {
4835
+ re = (_d = (_c = currentScheduler$4.current) === null || _c === void 0 ? void 0 : _c.dispatchPromise) === null || _d === void 0 ? void 0 : _d.call(_c, { fiber: fiber, promise: e });
4836
+ }
4823
4837
  }
4824
4838
  else {
4825
4839
  throw e;
@@ -4905,7 +4919,7 @@ function requireIndex_production_1 () {
4905
4919
  return null;
4906
4920
  }
4907
4921
  else {
4908
- // TODO update flow
4922
+ // TODO update flow
4909
4923
  if (enableSuspenseRoot$1.current && !renderDispatch.isAppMounted) {
4910
4924
  var suspenseField = getInstanceFieldByInstance(renderDispatch);
4911
4925
  suspenseField.asyncLoadList.uniPush(typedElementType);
@@ -5293,6 +5307,9 @@ function requireIndex_production_1 () {
5293
5307
  RenderDispatchEvent.prototype.dispatchPromise = function (_params) {
5294
5308
  throw new Error("Method not implemented.");
5295
5309
  };
5310
+ RenderDispatchEvent.prototype.dispatchSuspensePromise = function (_params) {
5311
+ throw new Error("Method not implemented.");
5312
+ };
5296
5313
  RenderDispatchEvent.prototype.trigger = function (_fiber, _state, cb) {
5297
5314
  return triggerUpdateOnFiber(_fiber, _state, cb);
5298
5315
  };
@@ -5823,12 +5840,23 @@ function requireIndex_production_1 () {
5823
5840
  layoutEffect(_dispatch, _fiber);
5824
5841
  });
5825
5842
  afterSyncUpdate();
5826
- var renderScheduler = currentScheduler$2.current;
5827
- renderScheduler.microTask(function invokeEffectListTask() {
5843
+ function invokeEffectListTask() {
5828
5844
  _list.listToFoot(function invokeEffectList(_fiber) {
5829
5845
  effect(_dispatch, _fiber);
5830
5846
  });
5831
- });
5847
+ }
5848
+ addEffectCallback(invokeEffectListTask);
5849
+ var renderScheduler = currentScheduler$2.current;
5850
+ if (_dispatch.enableConcurrentMode) {
5851
+ renderScheduler.macroTask(function flushEffect() {
5852
+ flushEffectCallback();
5853
+ });
5854
+ }
5855
+ else {
5856
+ renderScheduler.microTask(function flushEffect() {
5857
+ flushEffectCallback();
5858
+ });
5859
+ }
5832
5860
  };
5833
5861
  var defaultDispatchMount = defaultDispatchMountLatest;
5834
5862
 
@@ -5912,15 +5940,25 @@ function requireIndex_production_1 () {
5912
5940
  }
5913
5941
  });
5914
5942
  afterSyncUpdate();
5915
- var renderScheduler = currentScheduler$1.current;
5916
- // TODO before next update flow, make sure all the effect has done
5917
- renderScheduler.microTask(function invokeEffectListTask() {
5943
+ function invokeEffectListTask() {
5918
5944
  _list.listToFoot(function invokeEffectList(_fiber) {
5919
5945
  if (myreactSharedExports.exclude(_fiber.state, myreactSharedExports.STATE_TYPE.__unmount__) && !_dispatch.isAppUnmounted) {
5920
5946
  effect(_dispatch, _fiber);
5921
5947
  }
5922
5948
  });
5923
- });
5949
+ }
5950
+ addEffectCallback(invokeEffectListTask);
5951
+ var renderScheduler = currentScheduler$1.current;
5952
+ if (_dispatch.enableConcurrentMode) {
5953
+ renderScheduler.macroTask(function flushEffect() {
5954
+ flushEffectCallback();
5955
+ });
5956
+ }
5957
+ else {
5958
+ renderScheduler.microTask(function flushEffect() {
5959
+ flushEffectCallback();
5960
+ });
5961
+ }
5924
5962
  };
5925
5963
 
5926
5964
  var enableSuspenseRoot = react.__my_react_shared__.enableSuspenseRoot;
@@ -5981,7 +6019,9 @@ function requireIndex_production_1 () {
5981
6019
  promise._loading = true;
5982
6020
  promise.status = "pending";
5983
6021
  var renderScheduler_1 = currentScheduler.current;
5984
- renderDispatch.processPromise(promise).then(function () {
6022
+ renderDispatch
6023
+ .processPromise(promise)
6024
+ .then(function () {
5985
6025
  fiber.state = myreactSharedExports.STATE_TYPE.__recreate__;
5986
6026
  promise._list.delete(fiber);
5987
6027
  promise._loading = false;
@@ -5993,10 +6033,45 @@ function requireIndex_production_1 () {
5993
6033
  payLoad: promise,
5994
6034
  };
5995
6035
  renderScheduler_1.dispatchState(updater);
5996
- });
6036
+ })
6037
+ .catch(function (e) { return renderScheduler_1.dispatchError({ fiber: fiber, error: e }); });
5997
6038
  return null;
5998
6039
  }
5999
6040
  };
6041
+ var processSuspensePromise = function (renderDispatch, fiber, promise) {
6042
+ var _a, _b;
6043
+ defaultDeleteCurrentEffect(renderDispatch, fiber);
6044
+ fiber.state = myreactSharedExports.STATE_TYPE.__suspense__;
6045
+ if (promise.status === "rejected") {
6046
+ (_b = (_a = currentScheduler.current).dispatchError) === null || _b === void 0 ? void 0 : _b.call(_a, { fiber: fiber, error: promise._reason });
6047
+ return null;
6048
+ }
6049
+ if (promise.status === "fulfilled") ;
6050
+ promise._list = promise._list || new Set();
6051
+ promise._list.add(fiber);
6052
+ if (promise._loading)
6053
+ return null;
6054
+ promise._loading = true;
6055
+ promise.status = "pending";
6056
+ var renderScheduler = currentScheduler.current;
6057
+ renderDispatch
6058
+ .processPromise(promise)
6059
+ .then(function () {
6060
+ fiber.state = myreactSharedExports.STATE_TYPE.__recreate__;
6061
+ promise._list.delete(fiber);
6062
+ promise._loading = false;
6063
+ var updater = {
6064
+ type: myreactSharedExports.UpdateQueueType.promise,
6065
+ trigger: fiber,
6066
+ isSync: true,
6067
+ isForce: true,
6068
+ payLoad: promise,
6069
+ };
6070
+ renderScheduler.dispatchState(updater);
6071
+ })
6072
+ .catch(function (e) { return renderScheduler.dispatchError({ fiber: fiber, error: e }); });
6073
+ return null;
6074
+ };
6000
6075
 
6001
6076
  var CustomRenderDispatch = /** @class */ (function (_super) {
6002
6077
  __extends(CustomRenderDispatch, _super);
@@ -6007,7 +6082,7 @@ function requireIndex_production_1 () {
6007
6082
  _this.isAppMounted = false;
6008
6083
  _this.isAppCrashed = false;
6009
6084
  _this.isAppUnmounted = false;
6010
- _this.version = "0.3.17";
6085
+ _this.version = "0.3.18";
6011
6086
  _this.mode = "production";
6012
6087
  _this.renderMode = "render";
6013
6088
  _this.pendingCommitFiberList = null;
@@ -6419,7 +6494,7 @@ function requireIndex_production_1 () {
6419
6494
  });
6420
6495
  }); };
6421
6496
 
6422
- var version = "0.3.17";
6497
+ var version = "0.3.18";
6423
6498
 
6424
6499
  exports.CustomRenderDispatch = CustomRenderDispatch;
6425
6500
  exports.MyReactFiberNode = MyReactFiberNode;
@@ -6428,6 +6503,7 @@ function requireIndex_production_1 () {
6428
6503
  exports.RenderDispatchEvent = RenderDispatchEvent;
6429
6504
  exports.WrapperByLazyScope = WrapperByLazyScope;
6430
6505
  exports.WrapperBySuspenseScope = WrapperBySuspenseScope;
6506
+ exports.addEffectCallback = addEffectCallback;
6431
6507
  exports.afterSyncFlush = afterSyncFlush;
6432
6508
  exports.afterSyncUpdate = afterSyncUpdate;
6433
6509
  exports.applyTriggerFiberCb = applyTriggerFiberCb;
@@ -6477,6 +6553,7 @@ function requireIndex_production_1 () {
6477
6553
  exports.enableLogForCurrentFlowIsRunning = enableLogForCurrentFlowIsRunning;
6478
6554
  exports.enableValidMyReactElement = enableValidMyReactElement;
6479
6555
  exports.fiberToDispatchMap = fiberToDispatchMap;
6556
+ exports.flushEffectCallback = flushEffectCallback;
6480
6557
  exports.generateFiberToListWithAction = generateFiberToListWithAction;
6481
6558
  exports.generateFiberToMountList = generateFiberToMountList;
6482
6559
  exports.generateFiberToUnmountList = generateFiberToUnmountList;
@@ -6566,6 +6643,7 @@ function requireIndex_production_1 () {
6566
6643
  exports.processProvider = processProvider;
6567
6644
  exports.processState = processState;
6568
6645
  exports.processSuspense = processSuspense;
6646
+ exports.processSuspensePromise = processSuspensePromise;
6569
6647
  exports.resetLogScope = resetLogScope;
6570
6648
  exports.runtimeNextWork = runtimeNextWork;
6571
6649
  exports.runtimeNextWorkDev = runtimeNextWorkDev;
@@ -6842,6 +6920,7 @@ function requireIndex_production () {
6842
6920
  STATE_TYPE[STATE_TYPE["__retrigger__"] = 512] = "__retrigger__";
6843
6921
  STATE_TYPE[STATE_TYPE["__reschedule__"] = 1024] = "__reschedule__";
6844
6922
  STATE_TYPE[STATE_TYPE["__recreate__"] = 2048] = "__recreate__";
6923
+ STATE_TYPE[STATE_TYPE["__suspense__"] = 4096] = "__suspense__";
6845
6924
  })(exports.STATE_TYPE || (exports.STATE_TYPE = {}));
6846
6925
 
6847
6926
  exports.PATCH_TYPE = void 0;
@@ -7320,27 +7399,51 @@ var delGlobalDispatch = function (dispatch) {
7320
7399
  * @internal
7321
7400
  */
7322
7401
  var setRef = function (_fiber, config) {
7323
- var _a, _b;
7324
7402
  if (myreactSharedExports.include(_fiber.patch, myreactSharedExports.PATCH_TYPE.__ref__)) {
7403
+ var cleanUp = function () {
7404
+ var refPrevious = _fiber.refPrevious;
7405
+ myreactReconcilerExports.safeCallWithCurrentFiber({
7406
+ fiber: _fiber,
7407
+ action: function safeCallRefPrevious() {
7408
+ if (typeof refPrevious === "object" && refPrevious !== null) {
7409
+ refPrevious.current = null;
7410
+ }
7411
+ else if (typeof refPrevious === "function") {
7412
+ refPrevious === null || refPrevious === void 0 ? void 0 : refPrevious(null);
7413
+ }
7414
+ },
7415
+ });
7416
+ _fiber.refPrevious = undefined;
7417
+ var refCleanup = _fiber.refCleanup;
7418
+ myreactReconcilerExports.safeCallWithCurrentFiber({
7419
+ fiber: _fiber,
7420
+ action: function safeCallRefCleanup() {
7421
+ if (typeof refCleanup === "function") {
7422
+ refCleanup();
7423
+ }
7424
+ },
7425
+ });
7426
+ _fiber.refCleanup = undefined;
7427
+ };
7325
7428
  if (myreactSharedExports.include(_fiber.type, myreactReconcilerExports.NODE_TYPE.__plain__)) {
7326
7429
  if (_fiber.nativeNode) {
7430
+ cleanUp();
7327
7431
  var ref_1 = _fiber.ref;
7328
- if (typeof ref_1 === "object" && ref_1 !== null) {
7329
- ref_1.current = (_a = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _a === void 0 ? void 0 : _a.call(config, _fiber.nativeNode);
7330
- }
7331
- else if (typeof ref_1 === "function") {
7332
- myreactReconcilerExports.safeCallWithCurrentFiber({
7333
- fiber: _fiber,
7334
- action: function safeCallSetRef() {
7335
- var _a, _b;
7336
- (_a = _fiber.refCleanup) === null || _a === void 0 ? void 0 : _a.call(_fiber);
7432
+ myreactReconcilerExports.safeCallWithCurrentFiber({
7433
+ fiber: _fiber,
7434
+ action: function safeCallSetRef() {
7435
+ var _a, _b;
7436
+ if (typeof ref_1 === "object" && ref_1 !== null) {
7437
+ ref_1.current = (_a = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _a === void 0 ? void 0 : _a.call(config, _fiber.nativeNode);
7438
+ }
7439
+ else if (typeof ref_1 === "function") {
7337
7440
  var refCleanUp = ref_1((_b = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _b === void 0 ? void 0 : _b.call(config, _fiber.nativeNode));
7338
7441
  if (typeof refCleanUp === "function") {
7339
7442
  _fiber.refCleanup = refCleanUp;
7340
7443
  }
7341
- },
7342
- });
7343
- }
7444
+ }
7445
+ },
7446
+ });
7344
7447
  }
7345
7448
  else {
7346
7449
  throw new Error("[@my-react/react] plain element do not have a native node");
@@ -7348,23 +7451,23 @@ var setRef = function (_fiber, config) {
7348
7451
  }
7349
7452
  else if (myreactSharedExports.include(_fiber.type, myreactReconcilerExports.NODE_TYPE.__class__)) {
7350
7453
  if (_fiber.instance) {
7454
+ cleanUp();
7351
7455
  var ref_2 = _fiber.ref;
7352
- if (typeof ref_2 === "object" && ref_2 !== null) {
7353
- ref_2.current = (_b = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _b === void 0 ? void 0 : _b.call(config, _fiber.instance);
7354
- }
7355
- else if (typeof ref_2 === "function") {
7356
- myreactReconcilerExports.safeCallWithCurrentFiber({
7357
- fiber: _fiber,
7358
- action: function safeCallSetRef() {
7359
- var _a, _b;
7360
- (_a = _fiber.refCleanup) === null || _a === void 0 ? void 0 : _a.call(_fiber);
7456
+ myreactReconcilerExports.safeCallWithCurrentFiber({
7457
+ fiber: _fiber,
7458
+ action: function safeCallSetRef() {
7459
+ var _a, _b;
7460
+ if (typeof ref_2 === "object" && ref_2 !== null) {
7461
+ ref_2.current = (_a = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _a === void 0 ? void 0 : _a.call(config, _fiber.instance);
7462
+ }
7463
+ else if (typeof ref_2 === "function") {
7361
7464
  var refCleanUp = ref_2((_b = config === null || config === void 0 ? void 0 : config.getPublicInstance) === null || _b === void 0 ? void 0 : _b.call(config, _fiber.instance));
7362
7465
  if (typeof refCleanUp === "function") {
7363
7466
  _fiber.refCleanup = refCleanUp;
7364
7467
  }
7365
- },
7366
- });
7367
- }
7468
+ }
7469
+ },
7470
+ });
7368
7471
  }
7369
7472
  else {
7370
7473
  throw new Error("[@my-react/react-dom] class component do not have a instance");
@@ -7830,11 +7933,15 @@ var ReconcilerDispatchMount = function (_dispatch, _fiber, config) {
7830
7933
  myreactReconcilerExports.layoutEffect(_dispatch, _fiber);
7831
7934
  });
7832
7935
  myreactReconcilerExports.afterSyncUpdate();
7833
- var renderScheduler = currentScheduler$2.current;
7834
- renderScheduler.microTask(function invokeEffectListTask() {
7936
+ function invokeEffectListTask() {
7835
7937
  _list.listToFoot(function invokeEffectList(_fiber) {
7836
7938
  myreactReconcilerExports.effect(_dispatch, _fiber);
7837
7939
  });
7940
+ }
7941
+ myreactReconcilerExports.addEffectCallback(invokeEffectListTask);
7942
+ var renderScheduler = currentScheduler$2.current;
7943
+ renderScheduler.macroTask(function flushEffect() {
7944
+ myreactReconcilerExports.flushEffectCallback();
7838
7945
  });
7839
7946
  };
7840
7947
 
@@ -7931,15 +8038,25 @@ var ReconcilerDispatchUpdate = function (_dispatch, _list, config) {
7931
8038
  }
7932
8039
  });
7933
8040
  myreactReconcilerExports.afterSyncUpdate();
7934
- var renderScheduler = currentScheduler$1.current;
7935
- // TODO before next update flow, make sure all the effect has done
7936
- renderScheduler.microTask(function invokeEffectListTask() {
8041
+ function invokeEffectListTask() {
7937
8042
  _list.listToFoot(function invokeEffectList(_fiber) {
7938
8043
  if (myreactSharedExports.exclude(_fiber.state, myreactSharedExports.STATE_TYPE.__unmount__) && !_dispatch.isAppUnmounted) {
7939
8044
  myreactReconcilerExports.effect(_dispatch, _fiber);
7940
8045
  }
7941
8046
  });
7942
- });
8047
+ }
8048
+ myreactReconcilerExports.addEffectCallback(invokeEffectListTask);
8049
+ var renderScheduler = currentScheduler$1.current;
8050
+ if (_dispatch.enableConcurrentMode) {
8051
+ renderScheduler.macroTask(function flushEffect() {
8052
+ myreactReconcilerExports.flushEffectCallback();
8053
+ });
8054
+ }
8055
+ else {
8056
+ renderScheduler.microTask(function flushEffect() {
8057
+ myreactReconcilerExports.flushEffectCallback();
8058
+ });
8059
+ }
7943
8060
  };
7944
8061
 
7945
8062
  require$$0.__my_react_internal__.currentComponentFiber;
@@ -8045,6 +8162,9 @@ var createDispatch = function (rootNode, rootFiber, rootElement, config, flag) {
8045
8162
  ReconcilerDispatch.prototype.dispatchPromise = function (_params) {
8046
8163
  return myreactReconcilerExports.processPromise(this, _params.fiber, _params.promise);
8047
8164
  };
8165
+ ReconcilerDispatch.prototype.dispatchSuspensePromise = function (_params) {
8166
+ return myreactReconcilerExports.processSuspensePromise(this, _params.fiber, _params.promise);
8167
+ };
8048
8168
  ReconcilerDispatch.prototype.dispatchError = function (_params) {
8049
8169
  myreactReconcilerExports.triggerError(this, _params.fiber, _params.error);
8050
8170
  return void 0;
@@ -8146,7 +8266,7 @@ var Reconciler = function (_config) {
8146
8266
  }
8147
8267
  enableDebugFiled.current = false;
8148
8268
  enableScopeTreeLog.current = false;
8149
- // enableFiberForLog.current = false;
8269
+ myreactReconcilerExports.enableFiberForLog.current = false;
8150
8270
  return _container;
8151
8271
  };
8152
8272
  var updateContainer = function (_element, _container, _ignore, _cb) {
@@ -8239,7 +8359,7 @@ var Reconciler = function (_config) {
8239
8359
  };
8240
8360
  };
8241
8361
 
8242
- var version = "0.0.8";
8362
+ var version = "0.0.9";
8243
8363
  var createReconciler = Reconciler;
8244
8364
 
8245
8365
  exports.createReconciler = createReconciler;