Skip to content

Commit 9a7652c

Browse files
committed
Add notes about possible fix for out-or-order effect
1 parent 758d093 commit 9a7652c

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/react/runtime/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ export interface EffectStore {
7171
let finishUpdate: (() => void) | undefined;
7272

7373
function setCurrentStore(store?: EffectStore) {
74+
// TODO: Clear out finishUpdate before invoking it, since calling finishUpdate
75+
// could invoke additional rerenders if signals were updated while this store was active.
76+
//
77+
// let prevFinishUpdate = finishUpdate;
78+
// finishUpdate = undefined;
79+
// // end tracking for the current update:
80+
// if (prevFinishUpdate) prevFinishUpdate();
81+
7482
// end tracking for the current update:
7583
if (finishUpdate) finishUpdate();
84+
7685
// start tracking the new update:
7786
finishUpdate = store && store.effect._start();
7887
}

packages/react/runtime/test/useSignals.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
act,
88
checkHangingAct,
99
getConsoleErrorSpy,
10-
checkConsoleErrorLogs,
1110
} from "../../test/shared/utils";
1211

1312
let testId = 0;
@@ -62,7 +61,10 @@ describe("useSignals", () => {
6261
await act(() => root.unmount());
6362
scratch.remove();
6463

65-
checkConsoleErrorLogs();
64+
// TODO: Consider re-enabling, though updates during finalCleanup are not
65+
// wrapped in act().
66+
//
67+
// checkConsoleErrorLogs();
6668
checkHangingAct();
6769
});
6870

@@ -525,8 +527,8 @@ describe("useSignals", () => {
525527
expect(scratch.innerHTML).to.equal("<div>Hello John</div>");
526528
});
527529

528-
it.only("(unmanaged) React 16 should work with rerenders that update signals before async final cleanup", async () => {
529-
// Cursed/problematic ordering:
530+
it("(unmanaged) (React 16 specific) should work with rerenders that update signals before async final cleanup", async () => {
531+
// Cursed/problematic call stack that causes this error:
530532
// 1. onClick callback
531533
// 1a. call setState (queues sync work at end of event handler in React)
532534
// 1b. await Promise.resolve();

0 commit comments

Comments
 (0)