next.js: TransitionGroup addon causes "Only a ReactOwner can have refs"

With a help of @mlaursen (https://github.com/mlaursen/react-md/issues/150), I minimized the reproduction of the bug we encounter in #119 and #196.

Here is the pages/index.js:

import React from 'react'
import TransitionGroup from 'react-addons-transition-group'

class Test extends React.Component {
  render() {
    return <div ref={woop => console.log(woop)} />;
  }
}

export default class App extends React.Component {
  render() {
    return <div>
      <TransitionGroup>
        <Test key="test-1" ref={test => console.log(test)} />
      </TransitionGroup>
    </div>
  }
}

Once you open the page, you will get the following in your browser console:

Warning: getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.
Warning: getInitialState was defined on ReactTransitionGroup, a plain JavaScript class. This is only supported for classes created using React.createClass. Did you mean to define a state property instead?
<div data-reactid="3"></div>
Uncaught Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded

If I drop the TransitionGroup component, the page works fine.

Does anyone have a clue of what is the cause of this issue?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Don’t bundle ReactJS into Next.js, and provide developers a choice of using either “pure” ReactJS or ReactJS-with-addons

Actually, we are considering if should do this. It allows users to use any versions of React and make things more explicit.

I have succeeded in patching Next.js, so it uses external React, ReactDOM, and ReactMD (Metarial UI toolkit)! I will try to clean my patch up and will publish it as a PR, though I am not a JS developer, so I don’t expect it will get merged, but at least, it can be a starting point for someone.

Unfortunately, it’s not on our roadmap yet, but It seems critical to me. cc @rauchg

If it is not on the roadmap, could you, please, guide me on how I can build a custom Next.js bundles with ReactJS-with-addons?

You have to add import 'react-addons-transition-group' to client/next.js and run gulp release. But you’d have to fix the webpack config in next.js too.

Given the fact that react-addons require private ReactJS methods access (i.e. they require to be bundled together with ReactJS), it seems that Next.js should consider one of the following approaches:

  • Don’t bundle ReactJS into Next.js, and provide developers a choice of using either “pure” ReactJS or ReactJS-with-addons
  • Provide extra Next.js bundles for ReactJS-with-addons (Next.js will end up with 4 bundles: dev/prod * ReactJS-with-addonds/ReactJS-without-addons)

/cc @nkzawa