Skip to content

Commit f08b8ba

Browse files
committed
Refactor legacy update queue
Refactors legacy update queue to incoporate rebasing fix. Uses nearly the same approach as the hook update queue but has to handle a few other cases.
1 parent f39dc72 commit f08b8ba

File tree

6 files changed

+302
-292
lines changed

6 files changed

+302
-292
lines changed

packages/create-subscription/src/__tests__/createSubscription-test.internal.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('createSubscription', () => {
160160

161161
it('should still work if unsubscription is managed incorrectly', async () => {
162162
const Subscription = createSubscription({
163-
getCurrentValue: source => undefined,
163+
getCurrentValue: source => source.value,
164164
subscribe: (source, callback) => {
165165
source.then(callback);
166166
// (Can't unsubscribe from a Promise)
@@ -174,8 +174,18 @@ describe('createSubscription', () => {
174174
}
175175

176176
let resolveA, resolveB;
177-
const promiseA = new Promise(resolve => (resolveA = resolve));
178-
const promiseB = new Promise(resolve => (resolveB = resolve));
177+
const promiseA = new Promise(resolve => {
178+
resolveA = v => {
179+
resolve(v);
180+
promiseA.value = v;
181+
};
182+
});
183+
const promiseB = new Promise(resolve => {
184+
resolveB = v => {
185+
resolve(v);
186+
promiseB.value = v;
187+
};
188+
});
179189

180190
// Subscribe first to Promise A then Promise B
181191
ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,20 +1142,33 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
11421142

11431143
function logUpdateQueue(updateQueue: UpdateQueue<mixed>, depth) {
11441144
log(' '.repeat(depth + 1) + 'QUEUED UPDATES');
1145-
const firstUpdate = updateQueue.firstUpdate;
1146-
if (!firstUpdate) {
1145+
const last = updateQueue.baseQueue;
1146+
if (last === null) {
11471147
return;
11481148
}
1149+
const first = last.next;
1150+
let update = first;
1151+
if (update !== null) {
1152+
do {
1153+
log(
1154+
' '.repeat(depth + 1) + '~',
1155+
'[' + update.expirationTime + ']',
1156+
);
1157+
} while (update !== null && update !== first);
1158+
}
11491159

1150-
log(
1151-
' '.repeat(depth + 1) + '~',
1152-
'[' + firstUpdate.expirationTime + ']',
1153-
);
1154-
while (firstUpdate.next) {
1155-
log(
1156-
' '.repeat(depth + 1) + '~',
1157-
'[' + firstUpdate.expirationTime + ']',
1158-
);
1160+
const lastPending = updateQueue.shared.pending;
1161+
if (lastPending !== null) {
1162+
const firstPending = lastPending.next;
1163+
let pendingUpdate = firstPending;
1164+
if (pendingUpdate !== null) {
1165+
do {
1166+
log(
1167+
' '.repeat(depth + 1) + '~',
1168+
'[' + pendingUpdate.expirationTime + ']',
1169+
);
1170+
} while (pendingUpdate !== null && pendingUpdate !== firstPending);
1171+
}
11591172
}
11601173
}
11611174

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,7 @@ function dispatchAction<S, A>(
12991299
// This is the first update. Create a circular list.
13001300
update.next = update;
13011301
} else {
1302-
const first = pending.next;
1303-
if (first !== null) {
1304-
// Still circular.
1305-
update.next = first;
1306-
}
1302+
update.next = pending.next;
13071303
pending.next = update;
13081304
}
13091305
queue.pending = update;

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ export function checkForWrongSuspensePriorityInDEV(sourceFiber: Fiber) {
28582858
// has triggered any high priority updates
28592859
const updateQueue = current.updateQueue;
28602860
if (updateQueue !== null) {
2861-
let update = updateQueue.firstUpdate;
2861+
let update = updateQueue.baseQueue;
28622862
while (update !== null) {
28632863
const priorityLevel = update.priority;
28642864
if (

0 commit comments

Comments
 (0)