STRML / react-router-component

Declarative router component for React.
http://strml.viewdocs.io/react-router-component
MIT License
873 stars 94 forks source link

React 0.14 Incompatibility: Mutating props #148

Closed parshap closed 9 years ago

parshap commented 9 years ago

Directly mutating props of a component is not possible in React 0.14. This was deprecated in React 0.13:

Mutating props after an element is created is deprecated and will cause warnings in development mode; future versions of React will incorporate performance optimizations assuming that props aren't mutated

https://facebook.github.io/react/blog/2015/02/24/react-v0.13-rc1.html#breaking-changes

I was testing the React 0.14 beta and found react-router-component currently does this in matchRoutes.js, which throws an error when running with react@0.14.0-beta:

TypeError: Can't add property pattern, object is not extensible
    at matchRoutes (node_modules/react-router-component/lib/matchRoutes.js:36:29)
    ...

props.pattern seems to be only be used in the same context, two lines down, so I think it would be an easy fix to just use a local variable var pattern instead of mutating props.pattern. This may be a breaking change though, as route components will no longer expose the pattern prop (though not sure if anyone actually depended on this behavior).

STRML commented 9 years ago

Thanks for letting me know.

It's assigned to props.pattern as a form of caching. We could cache them elsewhere. I don't believe there is really any good use for children to be passed the pattern as a prop.

STRML commented 9 years ago

In fact, we actually remove that prop before passing props to the child. So it is likely safe to just cache this directly on the element itself.

STRML commented 9 years ago

Your issue should be fixed in master. Try it out.

STRML commented 9 years ago

Full React 0.14 support is coming soon.