<commit_before>import * as React from 'react'
import Router, { withRouter } from 'next/router'
import Link from 'next/link'

const pages = {
  '/a': 'Foo',
  '/b': 'Bar'
}

class HeaderNav extends React.Component {
  constructor ({ router }) {
    super()

    this.state = {
      activeURL: router.asPath,
      activeURLTopLevelRouterDeprecatedBehavior: router.asPath,
      activeURLTopLevelRouter: router.asPath
    }
  }

  componentDidMount () {
    Router.onRouteChangeComplete = this.handleRouteChangeTopLevelRouterDeprecatedBehavior
    Router.events.on('routeChangeComplete', this.handleRouteChangeTopLevelRouter)
    this.props.router.events.on('routeChangeComplete', this.handleRouteChange)
  }

  componentWillUnmount () {
    Router.onRouteChangeComplete = null
    Router.events.on('routeChangeComplete', this.handleRouteChangeTopLevelRouter)
    this.props.router.events.off('routeChangeComplete', this.handleRouteChange)
  }

  handleRouteChange = url => {
    this.setState({
      activeURL: url
    })
  };

  handleRouteChangeTopLevelRouter = url => {
    this.setState({
      activeURLTopLevelRouter: url
    })
  };

  handleRouteChangeTopLevelRouterDeprecatedBehavior = url => {
    this.setState({
      activeURLTopLevelRouterDeprecatedBehavior: url
    })
  };

  render () {
    return (
      <nav>
        {
          Object.keys(pages).map(url => (
            <Link href={url} key={url} prefetch>
              <a className={`${this.state.activeURL === url ? 'active' : ''} ${this.state.activeURLTopLevelRouter === url ? 'active-top-level-router' : ''} ${this.state.activeURLTopLevelRouterDeprecatedBehavior === url ? 'active-top-level-router-deprecated-behavior' : ''}`}>
                { pages[url] }
              </a>
            </Link>
          ))
        }
      </nav>
    )
  }
}

export default withRouter(HeaderNav)
<commit_msg>Remove route event in componentWillUnmount (#6196)<commit_after>import * as React from 'react'
import Router, { withRouter } from 'next/router'
import Link from 'next/link'

const pages = {
  '/a': 'Foo',
  '/b': 'Bar'
}

class HeaderNav extends React.Component {
  constructor ({ router }) {
    super()

    this.state = {
      activeURL: router.asPath,
      activeURLTopLevelRouterDeprecatedBehavior: router.asPath,
      activeURLTopLevelRouter: router.asPath
    }
  }

  componentDidMount () {
    Router.onRouteChangeComplete = this.handleRouteChangeTopLevelRouterDeprecatedBehavior
    Router.events.on('routeChangeComplete', this.handleRouteChangeTopLevelRouter)
    this.props.router.events.on('routeChangeComplete', this.handleRouteChange)
  }

  componentWillUnmount () {
    Router.onRouteChangeComplete = null
    Router.events.off('routeChangeComplete', this.handleRouteChangeTopLevelRouter)
    this.props.router.events.off('routeChangeComplete', this.handleRouteChange)
  }

  handleRouteChange = url => {
    this.setState({
      activeURL: url
    })
  };

  handleRouteChangeTopLevelRouter = url => {
    this.setState({
      activeURLTopLevelRouter: url
    })
  };

  handleRouteChangeTopLevelRouterDeprecatedBehavior = url => {
    this.setState({
      activeURLTopLevelRouterDeprecatedBehavior: url
    })
  };

  render () {
    return (
      <nav>
        {
          Object.keys(pages).map(url => (
            <Link href={url} key={url} prefetch>
              <a className={`${this.state.activeURL === url ? 'active' : ''} ${this.state.activeURLTopLevelRouter === url ? 'active-top-level-router' : ''} ${this.state.activeURLTopLevelRouterDeprecatedBehavior === url ? 'active-top-level-router-deprecated-behavior' : ''}`}>
                { pages[url] }
              </a>
            </Link>
          ))
        }
      </nav>
    )
  }
}

export default withRouter(HeaderNav)

{'fraction_non_alphanumeric': 0.12697993664202745, 'fraction_numerical': 0.0010559662090813093, 'mean_word_length': 3.074193548387097, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558891', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1102, 'n_words': 181}