Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix failing test
  • Loading branch information
poteto committed Oct 19, 2022
commit 96ed5e0f1fe0d10fcdaa2eca779ee56473be8bf3
8 changes: 6 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,17 +1947,21 @@ function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();
const eventFn = wrapEventFunction(callback);
hook.memoizedState = eventFn;
useEventImpl(eventFn, callback);
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn = wrapEventFunction(callback);
const hook = updateWorkInProgressHook();
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
// Always return a new function
return wrapEventFunction(callback);
}

function mountInsertionEffect(
Expand Down
8 changes: 6 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,17 +1947,21 @@ function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();
const eventFn = wrapEventFunction(callback);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Now that we don't reuse the eventFn anymore, there's not any advantage to using it in place of a ref-style mutable object. So I would change this back to something like {impl: eventFn} to avoid confusion.

Also I'm noticing now that during initial render, you don't need to schedule a commit effect. It's already initialized to the correct implementation.

hook.memoizedState = eventFn;
useEventImpl(eventFn, callback);
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn = wrapEventFunction(callback);
const hook = updateWorkInProgressHook();
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
// Always return a new function
return wrapEventFunction(callback);
}

function mountInsertionEffect(
Expand Down