question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React freezing Chrome, task manager reports 100% cpu on tab + ~5mb memory increase per second. (0.14 + 0.14.2)

See original GitHub issue

Sorry about the vauge description, can’t think of what to provide except source and a trace stack as I’m rather flummoxed. Edited source to convey gist. My issue originates w/ an onClick handler inside Row:

import React, {Component, PropTypes} from 'react';
import radium from 'radium';

let Row = ({storeName, deals, dateSelected, isOpen, toggleOpen, updateDateSelected}) => (
  <div style={{marginBottom: 20}}>
    <div onClick={toggleOpen}> // <- onClick works fine
      ...
    </div>
    <div>
      {
        days.map((day, i) => (
          <div onClick={() => updateDateSelected(day)}> // <- onClick is DEVIL
            ...
          </div>
        ))
      }
    </div>
  </div>
);

Row = radium(Row);

import {connect} from 'react-redux';
import {updateDateSelected} from 'actions/configActions';

@connect(null, {updateDateSelected})
export default class RowContainer extends Component {
  static propTypes = {
    updateDateSelected: PropTypes.func,
  }

  constructor() {
    super();
    this.state = {isOpen: false};
  }

  toggleOpen() {
    this.setState({isOpen: !this.state.isOpen});
  }

  render() {
    return (
      <Row
        {...this.props}
        {...this.state}
        toggleOpen={::this.toggleOpen}
      />
    );
  }
}

When triggering updateDateSelected the page immediately freezes, a debugger statement allows some investigation. updateDateSelected calls a redux reducer (manages state.config.deals):

export default handleActions({
  ...
  [CONFIG_DEALS_UPDATE_DATE_SELECTED]: (state, action) => (
    update(state, {
      $set: {dateSelected: action.payload},
    })
  ),
}, {
  dateSelected: moment().startOf('day').valueOf(),
});

Some middleware is called, this component which contains Row is re-rendered w/ the correctly updated props:

import React, {Component, PropTypes} from 'react';
import Row from 'views/config/ConfigDeals/Row';

const ConfigDeals = ({deals, stores, dateRangeStart, dateSelected}) => (
  <div>
    {
      stores.map(store => (
        <Row {...store} {...{dateSelected}}/>
      ))
    }
  </div>
);

import {connect} from 'react-redux';

@connect(state => ({
  dateSelected: state.config.deals.dateSelected,
  deals: state.collections.deals.entities,
  stores: state.meta.stores,
}))
export default class ConfigDealsContainer extends Component {
  static propTypes = {
    deals: PropTypes.array,
    stores: PropTypes.array,
    dateSelected: PropTypes.number,
  }

  render() {
    const {deals, stores, dateSelected} = this.props;
    return <ConfigDeals {...{deals, stores, dateSelected}}/>;
  }
}

This is the point where I’d expect React to stop doing stuff, but it keeps going. Stepping forwards w/ the debugger yields this trace stack:

Mixin.perform (Transaction.js?6dff:149)
ReactDefaultBatchingStrategy.batchedUpdates (ReactDefaultBatchingStrategy.js?ef70:62)
batchedUpdates (ReactUpdates.js?ce09:94)
ReactEventListener.dispatchEvent (ReactEventListener.js?2365:204)

The particular function call that seems to trip everything up is this.closeAll(0); @ Transaction:149, this comment @ Transaction:108 seemed pertinent:

Executes the function within a safety window. Use this for the top level
methods that result in large amounts of computation/mutations that would
need to be safety checked. The optional arguments helps prevent the need
to bind in many cases.

I’m unsure what the large ammounts of computation/mutation could be.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

41reactions
gaearoncommented, Apr 11, 2017

You can press pause icon in Scripts tab of DevTools while it’s stuck and you should see the callstack. This should help you get an idea of which code is running in a loop and why.

4reactions
WangLetocommented, Feb 16, 2019

When I’m new to React, I made stupid mistake to create a Foo class and use <Foo></Foo> in its own render function, which also leads to totally freezing scene. Write here for anyone who could possibly meet this problem again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix High CPU Usage in Google Chrome
If your Google Chrome has high CPU usage on startup, background tasks are likely causing the issue, as pointed out by iTechtics. To...
Read more >
My ReactJS app in Chrome Task Manager CPU is High but ...
My concern is that when I open Chrome's task manager it says CPU usage is anywhere from 50 to 120; however, if I...
Read more >
CPU at 100% - Google Chrome Community
Every 5-10 minutes for no discernible reason chrome uses all my CPU cores and freezes for about 2-7 seconds. This is mostly irrelevant...
Read more >
why the hell is chrome and the task manager taking up literally ...
I'd assume it works for any chrome/chromium based browser, eg. opera (the ... Task manager always says its using 100% cpu when you...
Read more >
Why do my browsers use often 100% of my Memory and CPU ...
I see it in the Task Manager. It always freezes and is slow just to change tab to tab, especially when I have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found