Skip to content

renderWithHooks may initialize workInProgressHook at the beginning #15301

@Jokcy

Description

@Jokcy

Do you want to request a feature or report a bug?
bug

What is the current behavior?
example here https://codesandbox.io/s/34mvmoln65
Based on issue #15219 I found the reason of this issue is that, when ErrorThrower throws renderWithHooks just break down and keep workInProgressHook stay useMemo. Because of the componentDidCatch in ErrorHandler we can go on the render phase. But when we reach the StatefulComponent we got useMemo as workInProgressHook and it make StatefulComponent with first hook useMemo.

I guess we can fix this just set workInProgressHook to null at the beginning of renderWithHooks. I post this issue because I see this comment in renderWithHooks, based on this example, all this variables may also not be reset when start renderWithHooks, so maybe it's better to put them back?

// The following should have already been reset
  // currentHook = null;
  // workInProgressHook = null;

  // remainingExpirationTime = NoWork;
  // componentUpdateQueue = null;

  // didScheduleRenderPhaseUpdate = false;
  // renderPhaseUpdates = null;
  // numberOfReRenders = 0;
  // sideEffectTag = 0;

If no other concerns about this, I just want to put them back to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions