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
- Fix #204 React addons require React in a special way. That causes Webpack to push React into the app's bundle. This fix adds new externals entries to prevent that. — committed to arunoda/next.js by arunoda 10 years ago
- Fix #204 (#401) React addons require React in a special way. That causes Webpack to push React into the app's bundle. This fix adds new externals entries to prevent that. — committed to vercel/next.js by arunoda 10 years ago
- next-dev test runner (#172) This is a very early version of the next-dev test runner. I'm opening this early to get thoughts from folks re: the direction of the design and implementation. Fixes #204... — committed to vercel/next.js by wbinnssmith 4 years ago
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
You have to add
import 'react-addons-transition-group'toclient/next.jsand rungulp 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:
/cc @nkzawa