Skip to content

Event still processing after component unmounted #2605

@tiye

Description

@tiye

Suppose a Backbone View named A, which contains a React component B. In B(React) there's a button, clicking the button unnmounts B(React) and rerenders A(Backbone). In my case I got an error like:

Uncaught TypeError: Cannot read property 'firstChild' of undefined f163bb52.main.min.js:7

After looking into it, I found events still processing even after that component unmounted from DOM. By examining processingEventQueue I found that event is that click event to do all this.

  /**
   * Dispatches all synthetic events on the event queue.
   *
   * @internal
   */
  processEventQueue: function() {
    // Set `eventQueue` to null before processing it so that we can tell if more
    // events get enqueued while processing.
    var processingEventQueue = eventQueue;
    eventQueue = null;
    forEachAccumulated(processingEventQueue, executeDispatchesAndRelease); <-- error from here
    ("production" !== "development" ? invariant(
      !eventQueue,
      'processEventQueue(): Additional events were enqueued while processing ' +
      'an event queue. Support for this has not yet been implemented.'
    ) : invariant(!eventQueue));
  },

For now I added setTimeout(100ms) in my click handler and it became ok.

Is there any plan to fix this case and React will just work with a timeout?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions