Skip to content

Commit

Permalink
Fix mount-or-update check in rerenderOptimistic (#27277)
Browse files Browse the repository at this point in the history
I noticed this was wrong because it should call updateWorkInProgressHook
before it checks if currentHook is null.

DiffTrain build for [9a01c8b](9a01c8b)
  • Loading branch information
acdlite committed Aug 28, 2023
1 parent b1f8e0d commit a7a6a73
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 94 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ab31a9ed28d340172440e4b12e27d2af689249b3
9a01c8b54e91c588391070c65701342e4e361ea7
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-classic-b5d591d4";
var ReactVersion = "18.3.0-www-classic-5ee47d9f";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-ad388db9";
var ReactVersion = "18.3.0-www-modern-85b0d0c8";

// ATTENTION
// When adding new symbols to this file,
Expand Down
17 changes: 11 additions & 6 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-217d7ffa";
var ReactVersion = "18.3.0-www-classic-a63d3ca6";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -9287,13 +9287,17 @@ function mountOptimistic(passthrough, reducer) {
}

function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}

function updateOptimisticImpl(hook, current, passthrough, reducer) {
// Optimistic updates are always rebased on top of the latest value passed in
// as an argument. It's called a passthrough because if there are no pending
// updates, it will be returned as-is.
//
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.

var resolvedReducer =
Expand All @@ -9309,12 +9313,13 @@ function rerenderOptimistic(passthrough, reducer) {
// So instead of a forked re-render implementation that knows how to handle
// render phase udpates, we can use the same implementation as during a
// regular mount or update.
var hook = updateWorkInProgressHook();

if (currentHook !== null) {
// This is an update. Process the update queue.
return updateOptimistic(passthrough, reducer);
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
} // This is a mount. No updates to process.

var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough;
Expand Down
17 changes: 11 additions & 6 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-modern-a127d0ff";
var ReactVersion = "18.3.0-www-modern-cf21fab9";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -9043,13 +9043,17 @@ function mountOptimistic(passthrough, reducer) {
}

function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}

function updateOptimisticImpl(hook, current, passthrough, reducer) {
// Optimistic updates are always rebased on top of the latest value passed in
// as an argument. It's called a passthrough because if there are no pending
// updates, it will be returned as-is.
//
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.

var resolvedReducer =
Expand All @@ -9065,12 +9069,13 @@ function rerenderOptimistic(passthrough, reducer) {
// So instead of a forked re-render implementation that knows how to handle
// render phase udpates, we can use the same implementation as during a
// regular mount or update.
var hook = updateWorkInProgressHook();

if (currentHook !== null) {
// This is an update. Process the update queue.
return updateOptimistic(passthrough, reducer);
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
} // This is a mount. No updates to process.

var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough;
Expand Down
16 changes: 10 additions & 6 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,9 @@ function mountOptimistic(passthrough) {
}
function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}
function updateOptimisticImpl(hook, current, passthrough, reducer) {
hook.baseState = hook.memoizedState = passthrough;
return updateReducerImpl(
hook,
Expand All @@ -3003,10 +3006,11 @@ function updateOptimistic(passthrough, reducer) {
);
}
function rerenderOptimistic(passthrough, reducer) {
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
reducer = updateWorkInProgressHook();
reducer.baseState = reducer.memoizedState = passthrough;
return [passthrough, reducer.queue.dispatch];
var hook = updateWorkInProgressHook();
if (null !== currentHook)
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
hook.baseState = hook.memoizedState = passthrough;
return [passthrough, hook.queue.dispatch];
}
function pushEffect(tag, create, inst, deps) {
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
Expand Down Expand Up @@ -10091,7 +10095,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-classic-b5d591d4",
version: "18.3.0-www-classic-5ee47d9f",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1303 = {
Expand Down Expand Up @@ -10122,7 +10126,7 @@ var internals$jscomp$inline_1303 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-b5d591d4"
reconcilerVersion: "18.3.0-www-classic-5ee47d9f"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1304 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
16 changes: 10 additions & 6 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,9 @@ function mountOptimistic(passthrough) {
}
function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}
function updateOptimisticImpl(hook, current, passthrough, reducer) {
hook.baseState = hook.memoizedState = passthrough;
return updateReducerImpl(
hook,
Expand All @@ -2809,10 +2812,11 @@ function updateOptimistic(passthrough, reducer) {
);
}
function rerenderOptimistic(passthrough, reducer) {
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
reducer = updateWorkInProgressHook();
reducer.baseState = reducer.memoizedState = passthrough;
return [passthrough, reducer.queue.dispatch];
var hook = updateWorkInProgressHook();
if (null !== currentHook)
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
hook.baseState = hook.memoizedState = passthrough;
return [passthrough, hook.queue.dispatch];
}
function pushEffect(tag, create, inst, deps) {
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
Expand Down Expand Up @@ -9756,7 +9760,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-de287969",
version: "18.3.0-www-modern-91e39875",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1283 = {
Expand Down Expand Up @@ -9787,7 +9791,7 @@ var internals$jscomp$inline_1283 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-de287969"
reconcilerVersion: "18.3.0-www-modern-91e39875"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1284 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
17 changes: 11 additions & 6 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13827,13 +13827,17 @@ function mountOptimistic(passthrough, reducer) {
}

function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}

function updateOptimisticImpl(hook, current, passthrough, reducer) {
// Optimistic updates are always rebased on top of the latest value passed in
// as an argument. It's called a passthrough because if there are no pending
// updates, it will be returned as-is.
//
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.

var resolvedReducer =
Expand All @@ -13849,12 +13853,13 @@ function rerenderOptimistic(passthrough, reducer) {
// So instead of a forked re-render implementation that knows how to handle
// render phase udpates, we can use the same implementation as during a
// regular mount or update.
var hook = updateWorkInProgressHook();

if (currentHook !== null) {
// This is an update. Process the update queue.
return updateOptimistic(passthrough, reducer);
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
} // This is a mount. No updates to process.

var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough;
Expand Down Expand Up @@ -33964,7 +33969,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-18629a7a";
var ReactVersion = "18.3.0-www-classic-76b0eed2";

function createPortal$1(
children,
Expand Down
17 changes: 11 additions & 6 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -13768,13 +13768,17 @@ function mountOptimistic(passthrough, reducer) {
}

function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}

function updateOptimisticImpl(hook, current, passthrough, reducer) {
// Optimistic updates are always rebased on top of the latest value passed in
// as an argument. It's called a passthrough because if there are no pending
// updates, it will be returned as-is.
//
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.

var resolvedReducer =
Expand All @@ -13790,12 +13794,13 @@ function rerenderOptimistic(passthrough, reducer) {
// So instead of a forked re-render implementation that knows how to handle
// render phase udpates, we can use the same implementation as during a
// regular mount or update.
var hook = updateWorkInProgressHook();

if (currentHook !== null) {
// This is an update. Process the update queue.
return updateOptimistic(passthrough, reducer);
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
} // This is a mount. No updates to process.

var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
// Reset the base state and memoized state to the passthrough. Future
// updates will be applied on top of this.

hook.baseState = hook.memoizedState = passthrough;
Expand Down Expand Up @@ -33809,7 +33814,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-a127d0ff";
var ReactVersion = "18.3.0-www-modern-cf21fab9";

function createPortal$1(
children,
Expand Down
18 changes: 11 additions & 7 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3808,6 +3808,9 @@ function mountOptimistic(passthrough) {
}
function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}
function updateOptimisticImpl(hook, current, passthrough, reducer) {
hook.baseState = hook.memoizedState = passthrough;
return updateReducerImpl(
hook,
Expand All @@ -3816,10 +3819,11 @@ function updateOptimistic(passthrough, reducer) {
);
}
function rerenderOptimistic(passthrough, reducer) {
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
reducer = updateWorkInProgressHook();
reducer.baseState = reducer.memoizedState = passthrough;
return [passthrough, reducer.queue.dispatch];
var hook = updateWorkInProgressHook();
if (null !== currentHook)
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
hook.baseState = hook.memoizedState = passthrough;
return [passthrough, hook.queue.dispatch];
}
function pushEffect(tag, create, inst, deps) {
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
Expand Down Expand Up @@ -16669,7 +16673,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1783 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-c01203f3",
version: "18.3.0-www-classic-d2e8c11b",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2140 = {
Expand Down Expand Up @@ -16699,7 +16703,7 @@ var internals$jscomp$inline_2140 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-c01203f3"
reconcilerVersion: "18.3.0-www-classic-d2e8c11b"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2141 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16938,4 +16942,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
);
};
exports.unstable_runWithPriority = runWithPriority;
exports.version = "18.3.0-www-classic-c01203f3";
exports.version = "18.3.0-www-classic-d2e8c11b";
18 changes: 11 additions & 7 deletions compiled/facebook-www/ReactDOM-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,9 @@ function mountOptimistic(passthrough) {
}
function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook();
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
}
function updateOptimisticImpl(hook, current, passthrough, reducer) {
hook.baseState = hook.memoizedState = passthrough;
return updateReducerImpl(
hook,
Expand All @@ -3709,10 +3712,11 @@ function updateOptimistic(passthrough, reducer) {
);
}
function rerenderOptimistic(passthrough, reducer) {
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
reducer = updateWorkInProgressHook();
reducer.baseState = reducer.memoizedState = passthrough;
return [passthrough, reducer.queue.dispatch];
var hook = updateWorkInProgressHook();
if (null !== currentHook)
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
hook.baseState = hook.memoizedState = passthrough;
return [passthrough, hook.queue.dispatch];
}
function pushEffect(tag, create, inst, deps) {
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
Expand Down Expand Up @@ -16199,7 +16203,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1742 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-de287969",
version: "18.3.0-www-modern-91e39875",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2104 = {
Expand Down Expand Up @@ -16230,7 +16234,7 @@ var internals$jscomp$inline_2104 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-de287969"
reconcilerVersion: "18.3.0-www-modern-91e39875"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2105 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16397,4 +16401,4 @@ exports.unstable_createEventHandle = function (type, options) {
return eventHandle;
};
exports.unstable_runWithPriority = runWithPriority;
exports.version = "18.3.0-www-modern-de287969";
exports.version = "18.3.0-www-modern-91e39875";
Loading

0 comments on commit a7a6a73

Please sign in to comment.