Skip to content

Commit f510cc4

Browse files
committed
Address feedback (will be squashed)
1 parent bb85612 commit f510cc4

6 files changed

+22
-28
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
enableUpdaterTracking,
4949
enableCache,
5050
enableTransitionTracing,
51+
enableUseEventHook,
5152
} from 'shared/ReactFeatureFlags';
5253
import {
5354
FunctionComponent,
@@ -412,16 +413,10 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
412413

413414
switch (finishedWork.tag) {
414415
case FunctionComponent: {
415-
if ((flags & Update) !== NoFlags) {
416-
try {
417-
commitHookEffectListUnmount(
418-
HookSnapshot | HookHasEffect,
419-
finishedWork,
420-
finishedWork.return,
421-
);
416+
if (enableUseEventHook) {
417+
if ((flags & Update) !== NoFlags) {
418+
// useEvent doesn't need to be cleaned up
422419
commitHookEffectListMount(HookSnapshot | HookHasEffect, finishedWork);
423-
} catch (error) {
424-
captureCommitPhaseError(finishedWork, finishedWork.return, error);
425420
}
426421
}
427422
break;

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
enableUpdaterTracking,
4949
enableCache,
5050
enableTransitionTracing,
51+
enableUseEventHook,
5152
} from 'shared/ReactFeatureFlags';
5253
import {
5354
FunctionComponent,
@@ -412,16 +413,10 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
412413

413414
switch (finishedWork.tag) {
414415
case FunctionComponent: {
415-
if ((flags & Update) !== NoFlags) {
416-
try {
417-
commitHookEffectListUnmount(
418-
HookSnapshot | HookHasEffect,
419-
finishedWork,
420-
finishedWork.return,
421-
);
416+
if (enableUseEventHook) {
417+
if ((flags & Update) !== NoFlags) {
418+
// useEvent doesn't need to be cleaned up
422419
commitHookEffectListMount(HookSnapshot | HookHasEffect, finishedWork);
423-
} catch (error) {
424-
captureCommitPhaseError(finishedWork, finishedWork.return, error);
425420
}
426421
}
427422
break;

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import {
9090
requestUpdateLane,
9191
requestEventTime,
9292
markSkippedUpdateLanes,
93-
isAlreadyRenderingProd,
93+
isInvalidExecutionContextForEventFunction,
9494
} from './ReactFiberWorkLoop.new';
9595

9696
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
@@ -1803,13 +1803,15 @@ function mountEvent<T>(callback: () => T): () => T {
18031803
const hook = mountWorkInProgressHook();
18041804
const ref = {current: callback};
18051805

1806-
function event(...args) {
1807-
if (isAlreadyRenderingProd()) {
1806+
function event() {
1807+
if (isInvalidExecutionContextForEventFunction()) {
18081808
throw new Error('An event from useEvent was called during render.');
18091809
}
1810-
return ref.current.apply(this, args);
1810+
return ref.current.apply(this, arguments);
18111811
}
18121812

1813+
// TODO: We don't need all the overhead of an effect object since there are no deps and no
1814+
// clean up functions.
18131815
mountEffectImpl(
18141816
UpdateEffect,
18151817
HookSnapshot,

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import {
9090
requestUpdateLane,
9191
requestEventTime,
9292
markSkippedUpdateLanes,
93-
isAlreadyRenderingProd,
93+
isInvalidExecutionContextForEventFunction,
9494
} from './ReactFiberWorkLoop.old';
9595

9696
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
@@ -1803,13 +1803,15 @@ function mountEvent<T>(callback: () => T): () => T {
18031803
const hook = mountWorkInProgressHook();
18041804
const ref = {current: callback};
18051805

1806-
function event(...args) {
1807-
if (isAlreadyRenderingProd()) {
1806+
function event() {
1807+
if (isInvalidExecutionContextForEventFunction()) {
18081808
throw new Error('An event from useEvent was called during render.');
18091809
}
1810-
return ref.current.apply(this, args);
1810+
return ref.current.apply(this, arguments);
18111811
}
18121812

1813+
// TODO: We don't need all the overhead of an effect object since there are no deps and no
1814+
// clean up functions.
18131815
mountEffectImpl(
18141816
UpdateEffect,
18151817
HookSnapshot,

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ export function isAlreadyRendering() {
16031603
);
16041604
}
16051605

1606-
export function isAlreadyRenderingProd() {
1606+
export function isInvalidExecutionContextForEventFunction() {
16071607
// Used to throw if certain APIs are called from the wrong context.
16081608
return (executionContext & RenderContext) !== NoContext;
16091609
}

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ export function isAlreadyRendering() {
16031603
);
16041604
}
16051605

1606-
export function isAlreadyRenderingProd() {
1606+
export function isInvalidExecutionContextForEventFunction() {
16071607
// Used to throw if certain APIs are called from the wrong context.
16081608
return (executionContext & RenderContext) !== NoContext;
16091609
}

0 commit comments

Comments
 (0)