Skip to content

Bug: CM double rendering affects how the renderer deals with events #20271

@drcmda

Description

@drcmda

My custom renderer registers events in the createInstance phase: https://github.com/pmndrs/react-three-fiber/blob/master/src/renderer.tsx#L359 it recognizes events of a certain type and stores them on the main instance. i believe this is also similar to how art does it: https://github.com/facebook/react/blob/master/packages/react-art/src/ReactARTHostConfig.js#L284 The instance will later go through its event-handler array to call them when needed.

The problem

Concurrent mode double renders the view, creates all the instances twice, adds the events twice, but only appends the second fragment to the container node. The first fragment is left hanging. It has written its events into the main instance, but it is not taken away nor is removeChild called on it. The main instance has both events listed as active and will execute them both, it does not know that one leads to a dead fragment.

Demo

Demo to reproduce: https://codesandbox.io/s/react-three-fiber-gestures-forked-v6vyv (click the box, it has two "up" events in the console)

From looking through the react-art source-code, it should exhibit the same problem.

Solution

I can understand that components need to be pure. But the renderer needs to mutate and store stuff. The reconciler should give some indication that a created instance is invalid, so that its internal effects can be removed.

If this turns out to be not a bug, how should the renderer store the events? If we take react-art as a reference it adds them in createInstance and removes them on removeChild.

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