[crud] Rename useResourceEffect flag

Rename the flag in preparation for the overload.
This commit is contained in:
Lauren Tan
2025-01-24 11:52:17 -05:00
parent 1e059a3935
commit a9e2debed3
18 changed files with 56 additions and 56 deletions
@@ -657,7 +657,7 @@ describe('ReactDOMServerHooks', () => {
describe('useResourceEffect', () => {
gate(flags => {
if (flags.enableUseResourceEffectHook) {
if (flags.enableUseEffectCRUDOverload) {
const yields = [];
itRenders(
'should ignore resource effects on the server',
+3 -3
View File
@@ -18,7 +18,7 @@ import {
ResourceEffectIdentityKind,
ResourceEffectUpdateKind,
} from './ReactFiberHooks';
import {enableUseResourceEffectHook} from 'shared/ReactFeatureFlags';
import {enableUseEffectCRUDOverload} from 'shared/ReactFeatureFlags';
// These indirections exists so we can exclude its stack frame in DEV (and anything below it).
// TODO: Consider marking the whole bundle instead of these boundaries.
@@ -184,11 +184,11 @@ const callCreate = {
'react-stack-bottom-frame': function (
effect: Effect,
): (() => void) | {...} | void | null {
if (!enableUseResourceEffectHook) {
if (!enableUseEffectCRUDOverload) {
if (effect.resourceKind != null) {
if (__DEV__) {
console.error(
'Expected only SimpleEffects when enableUseResourceEffectHook is disabled, ' +
'Expected only SimpleEffects when enableUseEffectCRUDOverload is disabled, ' +
'got %s',
effect.resourceKind,
);
+8 -8
View File
@@ -22,7 +22,7 @@ import {
enableProfilerCommitHooks,
enableProfilerNestedUpdatePhase,
enableSchedulingProfiler,
enableUseResourceEffectHook,
enableUseEffectCRUDOverload,
enableViewTransition,
} from 'shared/ReactFeatureFlags';
import {
@@ -160,7 +160,7 @@ export function commitHookEffectListMount(
// Mount
let destroy;
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
if (effect.resourceKind === ResourceEffectIdentityKind) {
if (__DEV__) {
effect.inst.resource = runWithFiberInDEV(
@@ -200,7 +200,7 @@ export function commitHookEffectListMount(
if ((flags & HookInsertion) !== NoHookEffect) {
setIsRunningInsertionEffect(true);
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
if (effect.resourceKind == null) {
destroy = runWithFiberInDEV(
finishedWork,
@@ -219,7 +219,7 @@ export function commitHookEffectListMount(
setIsRunningInsertionEffect(false);
}
} else {
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
if (effect.resourceKind == null) {
const create = effect.create;
const inst = effect.inst;
@@ -230,7 +230,7 @@ export function commitHookEffectListMount(
if (effect.resourceKind != null) {
if (__DEV__) {
console.error(
'Expected only SimpleEffects when enableUseResourceEffectHook is disabled, ' +
'Expected only SimpleEffects when enableUseEffectCRUDOverload is disabled, ' +
'got %s',
effect.resourceKind,
);
@@ -262,7 +262,7 @@ export function commitHookEffectListMount(
} else if ((effect.tag & HookInsertion) !== NoFlags) {
hookName = 'useInsertionEffect';
} else if (
enableUseResourceEffectHook &&
enableUseEffectCRUDOverload &&
effect.resourceKind != null
) {
hookName = 'useResourceEffect';
@@ -338,7 +338,7 @@ export function commitHookEffectListUnmount(
const inst = effect.inst;
const destroy = inst.destroy;
if (destroy !== undefined) {
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
if (effect.resourceKind == null) {
inst.destroy = undefined;
}
@@ -358,7 +358,7 @@ export function commitHookEffectListUnmount(
setIsRunningInsertionEffect(true);
}
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
if (
effect.resourceKind === ResourceEffectIdentityKind &&
effect.inst.resource != null
+12 -12
View File
@@ -38,7 +38,7 @@ import {
enableSchedulingProfiler,
enableTransitionTracing,
enableUseEffectEventHook,
enableUseResourceEffectHook,
enableUseEffectCRUDOverload,
enableLegacyCache,
disableLegacyMode,
enableNoCloningMemoCache,
@@ -3938,7 +3938,7 @@ export const ContextOnlyDispatcher: Dispatcher = {
if (enableUseEffectEventHook) {
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(ContextOnlyDispatcher: Dispatcher).useResourceEffect = throwInvalidHookError;
}
@@ -3971,7 +3971,7 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMount: Dispatcher).useResourceEffect = mountResourceEffect;
}
@@ -4004,7 +4004,7 @@ const HooksDispatcherOnUpdate: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdate: Dispatcher).useResourceEffect =
updateResourceEffect;
}
@@ -4038,7 +4038,7 @@ const HooksDispatcherOnRerender: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerender: Dispatcher).useResourceEffect =
updateResourceEffect;
}
@@ -4242,7 +4242,7 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -4430,7 +4430,7 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -4617,7 +4617,7 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -4804,7 +4804,7 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -5016,7 +5016,7 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -5229,7 +5229,7 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
@@ -5442,7 +5442,7 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
+1 -1
View File
@@ -396,7 +396,7 @@ export type Dispatcher = {
): void,
// TODO: Non-nullable once `enableUseEffectEventHook` is on everywhere.
useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
// TODO: Non-nullable once `enableUseResourceEffectHook` is on everywhere.
// TODO: Non-nullable once `enableUseEffectCRUDOverload` is on everywhere.
useResourceEffect?: (
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
@@ -3311,7 +3311,7 @@ describe('ReactHooksWithNoopRenderer', () => {
});
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
describe('useResourceEffect', () => {
class Resource {
isDeleted: false;
@@ -3333,12 +3333,12 @@ describe('ReactHooksWithNoopRenderer', () => {
}
}
// @gate !enableUseResourceEffectHook
// @gate !enableUseEffectCRUDOverload
it('is null when flag is disabled', async () => {
expect(useResourceEffect).toBeUndefined();
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('validates create return value', async () => {
function App({id}) {
useResourceEffect(() => {
@@ -3359,7 +3359,7 @@ describe('ReactHooksWithNoopRenderer', () => {
);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('validates non-empty update deps', async () => {
function App({id}) {
useResourceEffect(
@@ -3386,7 +3386,7 @@ describe('ReactHooksWithNoopRenderer', () => {
]);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('simple mount and update', async () => {
function App({id, username}) {
const opts = useMemo(() => {
@@ -3443,7 +3443,7 @@ describe('ReactHooksWithNoopRenderer', () => {
assertLog(['destroy(2, Jack)']);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('simple mount with no update', async () => {
function App({id, username}) {
const opts = useMemo(() => {
@@ -3480,7 +3480,7 @@ describe('ReactHooksWithNoopRenderer', () => {
assertLog(['destroy(1, Jack)']);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('calls update on every render if no deps are specified', async () => {
function App({id, username}) {
const opts = useMemo(() => {
@@ -3523,7 +3523,7 @@ describe('ReactHooksWithNoopRenderer', () => {
assertLog(['update(2, Lauren)']);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('does not unmount previous useResourceEffect between updates', async () => {
function App({id}) {
useResourceEffect(
@@ -3562,7 +3562,7 @@ describe('ReactHooksWithNoopRenderer', () => {
assertLog(['update(0)']);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('unmounts only on deletion', async () => {
function App({id}) {
useResourceEffect(
@@ -3596,7 +3596,7 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(ReactNoop).toMatchRenderedOutput(null);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('unmounts on deletion', async () => {
function Wrapper(props) {
return <App {...props} />;
@@ -3650,7 +3650,7 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(ReactNoop).toMatchRenderedOutput(null);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('handles errors in create on mount', async () => {
function App({id}) {
useResourceEffect(
@@ -3700,7 +3700,7 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(ReactNoop).toMatchRenderedOutput(null);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('handles errors in create on update', async () => {
function App({id}) {
useResourceEffect(
@@ -3744,7 +3744,7 @@ describe('ReactHooksWithNoopRenderer', () => {
}).rejects.toThrow('Oops error!');
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('handles errors in destroy on update', async () => {
function App({id, username}) {
const opts = useMemo(() => {
@@ -3800,7 +3800,7 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(ReactNoop).toMatchRenderedOutput(null);
});
// @gate enableUseResourceEffectHook && enableActivity
// @gate enableUseEffectCRUDOverload && enableActivity
it('composes with activity', async () => {
function App({id, username}) {
const opts = useMemo(() => {
@@ -3873,7 +3873,7 @@ describe('ReactHooksWithNoopRenderer', () => {
assertLog(['destroy(0, Lauren)']);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('composes with suspense', async () => {
function TextBox({text}) {
return <AsyncText text={text} ms={0} />;
@@ -3991,7 +3991,7 @@ describe('ReactHooksWithNoopRenderer', () => {
);
});
// @gate enableUseResourceEffectHook
// @gate enableUseEffectCRUDOverload
it('composes with other kinds of effects', async () => {
let rerender;
function App({id, username}) {
+2 -2
View File
@@ -40,7 +40,7 @@ import {createFastHash} from './ReactServerStreamConfig';
import {
enableUseEffectEventHook,
enableUseResourceEffectHook,
enableUseEffectCRUDOverload,
} from 'shared/ReactFeatureFlags';
import is from 'shared/objectIs';
import {
@@ -866,7 +866,7 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
if (enableUseEffectEventHook) {
HooksDispatcher.useEffectEvent = useEffectEvent;
}
if (enableUseResourceEffectHook) {
if (enableUseEffectCRUDOverload) {
HooksDispatcher.useResourceEffect = supportsClientAPIs
? noop
: clientHookNotSupported;
+2 -2
View File
@@ -65,7 +65,7 @@ import {addTransitionType} from './ReactTransitionType';
import {act} from './ReactAct';
import {captureOwnerStack} from './ReactOwnerStack';
import * as ReactCompilerRuntime from './ReactCompilerRuntime';
import {enableUseResourceEffectHook} from 'shared/ReactFeatureFlags';
import {enableUseEffectCRUDOverload} from 'shared/ReactFeatureFlags';
const Children = {
map,
@@ -134,4 +134,4 @@ export {
};
export const experimental_useResourceEffect: typeof useResourceEffect | void =
enableUseResourceEffectHook ? useResourceEffect : undefined;
enableUseEffectCRUDOverload ? useResourceEffect : undefined;
+2 -2
View File
@@ -18,7 +18,7 @@ import {REACT_CONSUMER_TYPE} from 'shared/ReactSymbols';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {enableUseResourceEffectHook} from 'shared/ReactFeatureFlags';
import {enableUseEffectCRUDOverload} from 'shared/ReactFeatureFlags';
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
@@ -208,7 +208,7 @@ export function useResourceEffect(
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
if (!enableUseResourceEffectHook) {
if (!enableUseEffectCRUDOverload) {
throw new Error('Not implemented.');
}
const dispatcher = resolveDispatcher();
+1 -1
View File
@@ -155,7 +155,7 @@ export const enableInfiniteRenderLoopDetection = false;
/**
* Experimental new hook for better managing resources in effects.
*/
export const enableUseResourceEffectHook = false;
export const enableUseEffectCRUDOverload = false;
// -----------------------------------------------------------------------------
// Ready for next major.
@@ -25,6 +25,6 @@ export const enableShallowPropDiffing = __VARIANT__;
export const passChildrenWhenCloningPersistedNodes = __VARIANT__;
export const enableFabricCompleteRootInCommitPhase = __VARIANT__;
export const enableSiblingPrerendering = __VARIANT__;
export const enableUseResourceEffectHook = __VARIANT__;
export const enableUseEffectCRUDOverload = __VARIANT__;
export const enableOwnerStacks = __VARIANT__;
export const enableRemoveConsolePatches = __VARIANT__;
@@ -25,7 +25,7 @@ export const {
enableObjectFiber,
enablePersistedModeClonedFlag,
enableShallowPropDiffing,
enableUseResourceEffectHook,
enableUseEffectCRUDOverload,
passChildrenWhenCloningPersistedNodes,
enableSiblingPrerendering,
enableOwnerStacks,
@@ -64,7 +64,7 @@ export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;
export const enableSiblingPrerendering = true;
export const enableUseResourceEffectHook = false;
export const enableUseEffectCRUDOverload = false;
export const enableHydrationLaneScheduling = true;
@@ -65,7 +65,7 @@ export const renameElementSymbol = true;
export const enableShallowPropDiffing = false;
export const enableSiblingPrerendering = true;
export const enableUseResourceEffectHook = false;
export const enableUseEffectCRUDOverload = false;
export const enableYieldingBeforePassive = true;
@@ -63,7 +63,7 @@ export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;
export const enableFabricCompleteRootInCommitPhase = false;
export const enableSiblingPrerendering = true;
export const enableUseResourceEffectHook = true;
export const enableUseEffectCRUDOverload = true;
export const enableHydrationLaneScheduling = true;
export const enableYieldingBeforePassive = false;
export const enableThrottledScheduling = false;
@@ -75,7 +75,7 @@ export const enableOwnerStacks = false;
export const enableShallowPropDiffing = false;
export const enableSiblingPrerendering = true;
export const enableUseResourceEffectHook = false;
export const enableUseEffectCRUDOverload = false;
export const enableHydrationLaneScheduling = true;
@@ -36,7 +36,7 @@ export const enableSchedulingProfiler = __VARIANT__;
export const enableInfiniteRenderLoopDetection = __VARIANT__;
export const enableSiblingPrerendering = __VARIANT__;
export const enableUseResourceEffectHook = __VARIANT__;
export const enableUseEffectCRUDOverload = __VARIANT__;
export const enableRemoveConsolePatches = __VARIANT__;
// TODO: These flags are hard-coded to the default values used in open source.
@@ -29,7 +29,7 @@ export const {
enableSiblingPrerendering,
enableTransitionTracing,
enableTrustedTypesIntegration,
enableUseResourceEffectHook,
enableUseEffectCRUDOverload,
favorSafetyOverHydrationPerf,
renameElementSymbol,
retryLaneExpirationMs,