Skip to content

Commit

Permalink
[crud] Remove useResourceEffect
Browse files Browse the repository at this point in the history
Removes useResourceEffect.
  • Loading branch information
poteto committed Feb 3, 2025
1 parent b7cbc29 commit f339670
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 227 deletions.
22 changes: 0 additions & 22 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {

Dispatcher.useId();

if (typeof Dispatcher.useResourceEffect === 'function') {
Dispatcher.useResourceEffect(() => ({}), []);
}
if (typeof Dispatcher.useEffectEvent === 'function') {
Dispatcher.useEffectEvent((args: empty) => {});
}
Expand Down Expand Up @@ -741,24 +738,6 @@ function useHostTransitionStatus(): TransitionStatus {
return status;
}

function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
nextHook();
hookLog.push({
displayName: null,
primitive: 'ResourceEffect',
stackError: new Error(),
value: create,
debugInfo: null,
dispatcherHookName: 'ResourceEffect',
});
}

function useEffectEvent<Args, F: (...Array<Args>) => mixed>(callback: F): F {
nextHook();
hookLog.push({
Expand Down Expand Up @@ -798,7 +777,6 @@ const Dispatcher: DispatcherType = {
useActionState,
useHostTransitionStatus,
useEffectEvent,
useResourceEffect,
};

// create a proxy to throw a custom error
Expand Down
158 changes: 0 additions & 158 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3989,9 +3989,6 @@ export const ContextOnlyDispatcher: Dispatcher = {
if (enableUseEffectEventHook) {
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
}
if (enableUseEffectCRUDOverload) {
(ContextOnlyDispatcher: Dispatcher).useResourceEffect = throwInvalidHookError;
}

const HooksDispatcherOnMount: Dispatcher = {
readContext,
Expand Down Expand Up @@ -4022,9 +4019,6 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMount: Dispatcher).useResourceEffect = mountResourceEffect;
}

const HooksDispatcherOnUpdate: Dispatcher = {
readContext,
Expand Down Expand Up @@ -4055,10 +4049,6 @@ const HooksDispatcherOnUpdate: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdate: Dispatcher).useResourceEffect =
updateResourceEffect;
}

const HooksDispatcherOnRerender: Dispatcher = {
readContext,
Expand Down Expand Up @@ -4089,10 +4079,6 @@ const HooksDispatcherOnRerender: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerender: Dispatcher).useResourceEffect =
updateResourceEffect;
}

let HooksDispatcherOnMountInDEV: Dispatcher | null = null;
let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;
Expand Down Expand Up @@ -4310,27 +4296,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
mountHookTypesDev();
checkDepsAreNonEmptyArrayDev(updateDeps);
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

HooksDispatcherOnMountWithHookTypesInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -4514,26 +4479,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

HooksDispatcherOnUpdateInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -4717,26 +4662,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

HooksDispatcherOnRerenderInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -4920,26 +4845,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

InvalidNestedHooksDispatcherOnMountInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -5148,27 +5053,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
mountHookTypesDev();
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

InvalidNestedHooksDispatcherOnUpdateInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -5377,27 +5261,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}

InvalidNestedHooksDispatcherOnRerenderInDEV = {
readContext<T>(context: ReactContext<T>): T {
Expand Down Expand Up @@ -5606,25 +5469,4 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
}
9 changes: 0 additions & 9 deletions packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export type HookType =
| 'useRef'
| 'useEffect'
| 'useEffectEvent'
| 'useResourceEffect'
| 'useInsertionEffect'
| 'useLayoutEffect'
| 'useCallback'
Expand Down Expand Up @@ -399,14 +398,6 @@ 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 `enableUseEffectCRUDOverload` is on everywhere.
useResourceEffect?: (
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) => void,
useInsertionEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
Expand Down
10 changes: 1 addition & 9 deletions packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import {
} from './ReactFizzConfig';
import {createFastHash} from './ReactServerStreamConfig';

import {
enableUseEffectEventHook,
enableUseEffectCRUDOverload,
} from 'shared/ReactFeatureFlags';
import {enableUseEffectEventHook} from 'shared/ReactFeatureFlags';
import is from 'shared/objectIs';
import {
REACT_CONTEXT_TYPE,
Expand Down Expand Up @@ -866,11 +863,6 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
if (enableUseEffectEventHook) {
HooksDispatcher.useEffectEvent = useEffectEvent;
}
if (enableUseEffectCRUDOverload) {
HooksDispatcher.useResourceEffect = supportsClientAPIs
? noop
: clientHookNotSupported;
}

export let currentResumableState: null | ResumableState = (null: any);
export function setCurrentResumableState(
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export {
useDeferredValue,
useEffect,
experimental_useEffectEvent,
experimental_useResourceEffect,
useImperativeHandle,
useInsertionEffect,
useLayoutEffect,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.experimental.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export {
useDeferredValue,
useEffect,
experimental_useEffectEvent,
experimental_useResourceEffect,
useImperativeHandle,
useInsertionEffect,
useLayoutEffect,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export {
createElement,
createRef,
experimental_useEffectEvent,
experimental_useResourceEffect,
forwardRef,
Fragment,
isValidElement,
Expand Down
5 changes: 0 additions & 5 deletions packages/react/src/ReactClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
useContext,
useEffect,
useEffectEvent,
useResourceEffect,
useImperativeHandle,
useDebugValue,
useInsertionEffect,
Expand All @@ -65,7 +64,6 @@ import {addTransitionType} from './ReactTransitionType';
import {act} from './ReactAct';
import {captureOwnerStack} from './ReactOwnerStack';
import * as ReactCompilerRuntime from './ReactCompilerRuntime';
import {enableUseEffectCRUDOverload} from 'shared/ReactFeatureFlags';

const Children = {
map,
Expand Down Expand Up @@ -132,6 +130,3 @@ export {
act, // DEV-only
captureOwnerStack, // DEV-only
};

export const experimental_useResourceEffect: typeof useResourceEffect | void =
enableUseEffectCRUDOverload ? useResourceEffect : undefined;
21 changes: 0 additions & 21 deletions packages/react/src/ReactHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,6 @@ export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
return dispatcher.useEffectEvent(callback);
}

export function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
if (!enableUseEffectCRUDOverload) {
throw new Error('Not implemented.');
}
const dispatcher = resolveDispatcher();
// $FlowFixMe[not-a-function] This is unstable, thus optional
return dispatcher.useResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
}

export function useOptimistic<S, A>(
passthrough: S,
reducer: ?(S, A) => S,
Expand Down

0 comments on commit f339670

Please sign in to comment.