Skip to content

Commit fcc18f8

Browse files
committed
Implement experimental_useFormStatus (#26722)
This hook reads the status of its ancestor form component, if it exists. ```js const {pending, data, action, method} = useFormStatus(); ``` It can be used to implement a loading indicator, for example. You can think of it as a shortcut for implementing a loading state with the useTransition hook. For now, it's only available in the experimental channel. We'll share docs once its closer to being stable. There are additional APIs that will ship alongside it. Internally it's implemented using startTransition + a context object. That's a good way to think about its behavior, but the actual implementation details may change in the future. Because form elements cannot be nested, the implementation in the reconciler does not bother to keep track of multiple nested "transition providers". So although it's implemented using generic Fiber config methods, it does currently make some assumptions based on React DOM's requirements. DiffTrain build for commit 540bab0.
1 parent 2c417e2 commit fcc18f8

File tree

13 files changed

+96
-105
lines changed

13 files changed

+96
-105
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<1734297975a5c75886dc8f61c542873e>>
10+
* @generated SignedSource<<147e07431dc4defee6d2e9faf584292a>>
1111
*/
1212

1313
'use strict';
@@ -2587,7 +2587,7 @@ function isRootDehydrated(root) {
25872587

25882588
var contextStackCursor = createCursor(null);
25892589
var contextFiberStackCursor = createCursor(null);
2590-
var rootInstanceStackCursor = createCursor(null);
2590+
var rootInstanceStackCursor = createCursor(null); // Represents the nearest host transition provider (in React DOM, a <form />)
25912591

25922592
function requiredContext(c) {
25932593
{
@@ -2641,24 +2641,21 @@ function pushHostContext(fiber) {
26412641
var context = requiredContext(contextStackCursor.current);
26422642
var nextContext = getChildHostContext(); // Don't push this Fiber's context unless it's unique.
26432643

2644-
if (context === nextContext) {
2645-
return;
2646-
} // Track the context and the Fiber that provided it.
2647-
// This enables us to pop only Fibers that provide unique contexts.
2648-
2649-
push(contextFiberStackCursor, fiber, fiber);
2650-
push(contextStackCursor, nextContext, fiber);
2644+
if (context !== nextContext) {
2645+
// Track the context and the Fiber that provided it.
2646+
// This enables us to pop only Fibers that provide unique contexts.
2647+
push(contextFiberStackCursor, fiber, fiber);
2648+
push(contextStackCursor, nextContext, fiber);
2649+
}
26512650
}
26522651

26532652
function popHostContext(fiber) {
2654-
// Do not pop unless this Fiber provided the current context.
2655-
// pushHostContext() only pushes Fibers that provide unique contexts.
2656-
if (contextFiberStackCursor.current !== fiber) {
2657-
return;
2653+
if (contextFiberStackCursor.current === fiber) {
2654+
// Do not pop unless this Fiber provided the current context.
2655+
// pushHostContext() only pushes Fibers that provide unique contexts.
2656+
pop(contextStackCursor, fiber);
2657+
pop(contextFiberStackCursor, fiber);
26582658
}
2659-
2660-
pop(contextStackCursor, fiber);
2661-
pop(contextFiberStackCursor, fiber);
26622659
}
26632660

26642661
var isHydrating = false; // This flag allows for warning supression when we expect there to be mismatches
@@ -23895,7 +23892,7 @@ function createFiberRoot(
2389523892
return root;
2389623893
}
2389723894

23898-
var ReactVersion = "18.3.0-next-6eadbe0c4-20230425";
23895+
var ReactVersion = "18.3.0-next-540bab085-20230426";
2389923896

2390023897
// Might add PROFILE later.
2390123898

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8601,7 +8601,7 @@ var devToolsConfig$jscomp$inline_1022 = {
86018601
throw Error("TestRenderer does not support findFiberByHostInstance()");
86028602
},
86038603
bundleType: 0,
8604-
version: "18.3.0-next-6eadbe0c4-20230425",
8604+
version: "18.3.0-next-540bab085-20230426",
86058605
rendererPackageName: "react-test-renderer"
86068606
};
86078607
var internals$jscomp$inline_1207 = {
@@ -8632,7 +8632,7 @@ var internals$jscomp$inline_1207 = {
86328632
scheduleRoot: null,
86338633
setRefreshHandler: null,
86348634
getCurrentFiber: null,
8635-
reconcilerVersion: "18.3.0-next-6eadbe0c4-20230425"
8635+
reconcilerVersion: "18.3.0-next-540bab085-20230426"
86368636
};
86378637
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
86388638
var hook$jscomp$inline_1208 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9027,7 +9027,7 @@ var devToolsConfig$jscomp$inline_1064 = {
90279027
throw Error("TestRenderer does not support findFiberByHostInstance()");
90289028
},
90299029
bundleType: 0,
9030-
version: "18.3.0-next-6eadbe0c4-20230425",
9030+
version: "18.3.0-next-540bab085-20230426",
90319031
rendererPackageName: "react-test-renderer"
90329032
};
90339033
var internals$jscomp$inline_1248 = {
@@ -9058,7 +9058,7 @@ var internals$jscomp$inline_1248 = {
90589058
scheduleRoot: null,
90599059
setRefreshHandler: null,
90609060
getCurrentFiber: null,
9061-
reconcilerVersion: "18.3.0-next-6eadbe0c4-20230425"
9061+
reconcilerVersion: "18.3.0-next-540bab085-20230426"
90629062
};
90639063
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
90649064
var hook$jscomp$inline_1249 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-next-6eadbe0c4-20230425";
30+
var ReactVersion = "18.3.0-next-540bab085-20230426";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
639639
);
640640
};
641641
exports.useTransition = useTransition;
642-
exports.version = "18.3.0-next-6eadbe0c4-20230425";
642+
exports.version = "18.3.0-next-540bab085-20230426";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
642642
);
643643
};
644644
exports.useTransition = useTransition;
645-
exports.version = "18.3.0-next-6eadbe0c4-20230425";
645+
exports.version = "18.3.0-next-540bab085-20230426";
646646

647647
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
648648
if (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6eadbe0c4aebf68410bb48147054ee22eec4c20c
1+
540bab085d571789f4562565eebfd0db9f36345c

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e06bc0ace400db16ad0c174d7641f083>>
10+
* @generated SignedSource<<c56d233e78e730ff1d26a9cbc8974a45>>
1111
*/
1212

1313
'use strict';
@@ -6268,7 +6268,7 @@ function isRootDehydrated(root) {
62686268

62696269
var contextStackCursor = createCursor(null);
62706270
var contextFiberStackCursor = createCursor(null);
6271-
var rootInstanceStackCursor = createCursor(null);
6271+
var rootInstanceStackCursor = createCursor(null); // Represents the nearest host transition provider (in React DOM, a <form />)
62726272

62736273
function requiredContext(c) {
62746274
{
@@ -6322,24 +6322,21 @@ function pushHostContext(fiber) {
63226322
var context = requiredContext(contextStackCursor.current);
63236323
var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
63246324

6325-
if (context === nextContext) {
6326-
return;
6327-
} // Track the context and the Fiber that provided it.
6328-
// This enables us to pop only Fibers that provide unique contexts.
6329-
6330-
push(contextFiberStackCursor, fiber, fiber);
6331-
push(contextStackCursor, nextContext, fiber);
6325+
if (context !== nextContext) {
6326+
// Track the context and the Fiber that provided it.
6327+
// This enables us to pop only Fibers that provide unique contexts.
6328+
push(contextFiberStackCursor, fiber, fiber);
6329+
push(contextStackCursor, nextContext, fiber);
6330+
}
63326331
}
63336332

63346333
function popHostContext(fiber) {
6335-
// Do not pop unless this Fiber provided the current context.
6336-
// pushHostContext() only pushes Fibers that provide unique contexts.
6337-
if (contextFiberStackCursor.current !== fiber) {
6338-
return;
6334+
if (contextFiberStackCursor.current === fiber) {
6335+
// Do not pop unless this Fiber provided the current context.
6336+
// pushHostContext() only pushes Fibers that provide unique contexts.
6337+
pop(contextStackCursor, fiber);
6338+
pop(contextFiberStackCursor, fiber);
63396339
}
6340-
6341-
pop(contextStackCursor, fiber);
6342-
pop(contextFiberStackCursor, fiber);
63436340
}
63446341

63456342
var isHydrating = false; // This flag allows for warning supression when we expect there to be mismatches
@@ -11376,11 +11373,11 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
1137611373
var version = getVersion(source._source);
1137711374
var dispatcher = ReactCurrentDispatcher$1.current; // eslint-disable-next-line prefer-const
1137811375

11379-
var _dispatcher$useState = dispatcher.useState(function () {
11376+
var _dispatcher$useState2 = dispatcher.useState(function () {
1138011377
return readFromUnsubscribedMutableSource(root, source, getSnapshot);
1138111378
}),
11382-
currentSnapshot = _dispatcher$useState[0],
11383-
setSnapshot = _dispatcher$useState[1];
11379+
currentSnapshot = _dispatcher$useState2[0],
11380+
setSnapshot = _dispatcher$useState2[1];
1138411381

1138511382
var snapshot = currentSnapshot; // Grab a handle to the state hook as well.
1138611383
// We use it to clear the pending update queue if we have a new source.
@@ -27205,7 +27202,7 @@ function createFiberRoot(
2720527202
return root;
2720627203
}
2720727204

27208-
var ReactVersion = "18.3.0-next-6eadbe0c4-20230425";
27205+
var ReactVersion = "18.3.0-next-540bab085-20230426";
2720927206

2721027207
function createPortal$1(
2721127208
children,

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<ebafb0bec3eaf52ea1b8517bbab46593>>
10+
* @generated SignedSource<<eea5199d8ea5e7e01ee9bf40f6eb4713>>
1111
*/
1212

1313
"use strict";
@@ -3869,12 +3869,12 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
38693869
var getVersion = source._getVersion,
38703870
version = getVersion(source._source),
38713871
dispatcher = ReactCurrentDispatcher$1.current,
3872-
_dispatcher$useState = dispatcher.useState(function () {
3872+
_dispatcher$useState2 = dispatcher.useState(function () {
38733873
return readFromUnsubscribedMutableSource(root, source, getSnapshot);
38743874
}),
3875-
setSnapshot = _dispatcher$useState[1],
3876-
snapshot = _dispatcher$useState[0];
3877-
_dispatcher$useState = workInProgressHook;
3875+
setSnapshot = _dispatcher$useState2[1],
3876+
snapshot = _dispatcher$useState2[0];
3877+
_dispatcher$useState2 = workInProgressHook;
38783878
var memoizedState = hook.memoizedState,
38793879
refs = memoizedState.refs,
38803880
prevGetSnapshot = refs.getSnapshot,
@@ -3927,10 +3927,10 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
39273927
}),
39283928
(hook.dispatch = setSnapshot =
39293929
dispatchSetState.bind(null, currentlyRenderingFiber$1, hook)),
3930-
(_dispatcher$useState.queue = hook),
3931-
(_dispatcher$useState.baseQueue = null),
3930+
(_dispatcher$useState2.queue = hook),
3931+
(_dispatcher$useState2.baseQueue = null),
39323932
(snapshot = readFromUnsubscribedMutableSource(root, source, getSnapshot)),
3933-
(_dispatcher$useState.memoizedState = _dispatcher$useState.baseState =
3933+
(_dispatcher$useState2.memoizedState = _dispatcher$useState2.baseState =
39343934
snapshot));
39353935
return snapshot;
39363936
}
@@ -9472,7 +9472,7 @@ var roots = new Map(),
94729472
devToolsConfig$jscomp$inline_1046 = {
94739473
findFiberByHostInstance: getInstanceFromNode,
94749474
bundleType: 0,
9475-
version: "18.3.0-next-6eadbe0c4-20230425",
9475+
version: "18.3.0-next-540bab085-20230426",
94769476
rendererPackageName: "react-native-renderer",
94779477
rendererConfig: {
94789478
getInspectorDataForViewTag: function () {
@@ -9514,7 +9514,7 @@ var internals$jscomp$inline_1277 = {
95149514
scheduleRoot: null,
95159515
setRefreshHandler: null,
95169516
getCurrentFiber: null,
9517-
reconcilerVersion: "18.3.0-next-6eadbe0c4-20230425"
9517+
reconcilerVersion: "18.3.0-next-540bab085-20230426"
95189518
};
95199519
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95209520
var hook$jscomp$inline_1278 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<c2ea9a9314e4d1947b80adea64e6d9ce>>
10+
* @generated SignedSource<<7634b64643555a5e869a82fd5e1dc828>>
1111
*/
1212

1313

@@ -3999,12 +3999,12 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
39993999
var getVersion = source._getVersion,
40004000
version = getVersion(source._source),
40014001
dispatcher = ReactCurrentDispatcher$1.current,
4002-
_dispatcher$useState = dispatcher.useState(function () {
4002+
_dispatcher$useState2 = dispatcher.useState(function () {
40034003
return readFromUnsubscribedMutableSource(root, source, getSnapshot);
40044004
}),
4005-
setSnapshot = _dispatcher$useState[1],
4006-
snapshot = _dispatcher$useState[0];
4007-
_dispatcher$useState = workInProgressHook;
4005+
setSnapshot = _dispatcher$useState2[1],
4006+
snapshot = _dispatcher$useState2[0];
4007+
_dispatcher$useState2 = workInProgressHook;
40084008
var memoizedState = hook.memoizedState,
40094009
refs = memoizedState.refs,
40104010
prevGetSnapshot = refs.getSnapshot,
@@ -4057,10 +4057,10 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
40574057
}),
40584058
(hook.dispatch = setSnapshot =
40594059
dispatchSetState.bind(null, currentlyRenderingFiber$1, hook)),
4060-
(_dispatcher$useState.queue = hook),
4061-
(_dispatcher$useState.baseQueue = null),
4060+
(_dispatcher$useState2.queue = hook),
4061+
(_dispatcher$useState2.baseQueue = null),
40624062
(snapshot = readFromUnsubscribedMutableSource(root, source, getSnapshot)),
4063-
(_dispatcher$useState.memoizedState = _dispatcher$useState.baseState =
4063+
(_dispatcher$useState2.memoizedState = _dispatcher$useState2.baseState =
40644064
snapshot));
40654065
return snapshot;
40664066
}
@@ -10181,7 +10181,7 @@ var roots = new Map(),
1018110181
devToolsConfig$jscomp$inline_1124 = {
1018210182
findFiberByHostInstance: getInstanceFromNode,
1018310183
bundleType: 0,
10184-
version: "18.3.0-next-6eadbe0c4-20230425",
10184+
version: "18.3.0-next-540bab085-20230426",
1018510185
rendererPackageName: "react-native-renderer",
1018610186
rendererConfig: {
1018710187
getInspectorDataForViewTag: function () {
@@ -10236,7 +10236,7 @@ var roots = new Map(),
1023610236
scheduleRoot: null,
1023710237
setRefreshHandler: null,
1023810238
getCurrentFiber: null,
10239-
reconcilerVersion: "18.3.0-next-6eadbe0c4-20230425"
10239+
reconcilerVersion: "18.3.0-next-540bab085-20230426"
1024010240
});
1024110241
exports.createPortal = function (children, containerTag) {
1024210242
return createPortal$1(

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<812e354f66e1eb672accd40316666e44>>
10+
* @generated SignedSource<<22b18563a8650deb3b64f41ff6b2aec7>>
1111
*/
1212

1313
'use strict';
@@ -6584,7 +6584,7 @@ function isRootDehydrated(root) {
65846584

65856585
var contextStackCursor = createCursor(null);
65866586
var contextFiberStackCursor = createCursor(null);
6587-
var rootInstanceStackCursor = createCursor(null);
6587+
var rootInstanceStackCursor = createCursor(null); // Represents the nearest host transition provider (in React DOM, a <form />)
65886588

65896589
function requiredContext(c) {
65906590
{
@@ -6638,24 +6638,21 @@ function pushHostContext(fiber) {
66386638
var context = requiredContext(contextStackCursor.current);
66396639
var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
66406640

6641-
if (context === nextContext) {
6642-
return;
6643-
} // Track the context and the Fiber that provided it.
6644-
// This enables us to pop only Fibers that provide unique contexts.
6645-
6646-
push(contextFiberStackCursor, fiber, fiber);
6647-
push(contextStackCursor, nextContext, fiber);
6641+
if (context !== nextContext) {
6642+
// Track the context and the Fiber that provided it.
6643+
// This enables us to pop only Fibers that provide unique contexts.
6644+
push(contextFiberStackCursor, fiber, fiber);
6645+
push(contextStackCursor, nextContext, fiber);
6646+
}
66486647
}
66496648

66506649
function popHostContext(fiber) {
6651-
// Do not pop unless this Fiber provided the current context.
6652-
// pushHostContext() only pushes Fibers that provide unique contexts.
6653-
if (contextFiberStackCursor.current !== fiber) {
6654-
return;
6650+
if (contextFiberStackCursor.current === fiber) {
6651+
// Do not pop unless this Fiber provided the current context.
6652+
// pushHostContext() only pushes Fibers that provide unique contexts.
6653+
pop(contextStackCursor, fiber);
6654+
pop(contextFiberStackCursor, fiber);
66556655
}
6656-
6657-
pop(contextStackCursor, fiber);
6658-
pop(contextFiberStackCursor, fiber);
66596656
}
66606657

66616658
var isHydrating = false; // This flag allows for warning supression when we expect there to be mismatches
@@ -11692,11 +11689,11 @@ function useMutableSource(hook, source, getSnapshot, subscribe) {
1169211689
var version = getVersion(source._source);
1169311690
var dispatcher = ReactCurrentDispatcher$1.current; // eslint-disable-next-line prefer-const
1169411691

11695-
var _dispatcher$useState = dispatcher.useState(function () {
11692+
var _dispatcher$useState2 = dispatcher.useState(function () {
1169611693
return readFromUnsubscribedMutableSource(root, source, getSnapshot);
1169711694
}),
11698-
currentSnapshot = _dispatcher$useState[0],
11699-
setSnapshot = _dispatcher$useState[1];
11695+
currentSnapshot = _dispatcher$useState2[0],
11696+
setSnapshot = _dispatcher$useState2[1];
1170011697

1170111698
var snapshot = currentSnapshot; // Grab a handle to the state hook as well.
1170211699
// We use it to clear the pending update queue if we have a new source.
@@ -27718,7 +27715,7 @@ function createFiberRoot(
2771827715
return root;
2771927716
}
2772027717

27721-
var ReactVersion = "18.3.0-next-6eadbe0c4-20230425";
27718+
var ReactVersion = "18.3.0-next-540bab085-20230426";
2772227719

2772327720
function createPortal$1(
2772427721
children,

0 commit comments

Comments
 (0)