acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 216 forks source link

Invalid prop `RoutingContext` supplied to `ReduxRouterContext`, expected a single ReactElement. #266

Closed catamphetamine closed 8 years ago

catamphetamine commented 8 years ago

Following https://github.com/acdlite/redux-router/issues/260 , because it is unable to be reopened.

Seems that the fix didn't actually fix the issue. I get it now: PropTypes.instanceOf(Component) won't work because it's not an instance of a Component but rather a class extending Component. The only suitable PropType is PropTypes.func then.

Scarysize commented 8 years ago

Interesting. Maybe we should just add a test case to make sure it will work correctly.

catamphetamine commented 8 years ago

I don't know why but the second time I render the whole thing it doesn't output the warning:

renderIntoDocument(
      <Provider store={store}>
        <ReduxRouter RoutingContext={function(props) { return <div /> }}>
          {routes}
        </ReduxRouter>
      </Provider>
    );

I event put it into separate it tests, still no second warning.

  it('only accepts React.Components for "RoutingContext" prop', () => {
    const reducer = combineReducers({
      router: routerStateReducer
    });

    const history = createHistory();
    const store = reduxReactRouter({
      history
    })(createStore)(reducer);

    store.dispatch(push({ pathname: '/parent/child/123', query: { key: 'value' } }));

    // let consoleErrorSpy = sinon.spy(console, 'error');

    let tree = renderIntoDocument(
      <Provider store={store}>
        <ReduxRouter RoutingContext={function(props) { return <div /> }}>
          {routes}
        </ReduxRouter>
      </Provider>
    );

    renderIntoDocument(
      <Provider store={store}>
        <ReduxRouter>
          {routes}
        </ReduxRouter>
      </Provider>
    );

    // assert(consoleErrorSpy.calledOnce, 'console.error must have been called');
    // expect(consoleErrorSpy.args[0][0]).to.contain(
    //   'Invalid prop `RoutingContext` of type `Function` supplied to `ReduxRouterContext`'
    // );

    // console.error.restore();
    // consoleErrorSpy = sinon.spy(console, 'error');

    renderIntoDocument(
      <Provider store={store}>
        <ReduxRouter RoutingContext={function(props) { return <span /> }}>
          {routes}
        </ReduxRouter>
      </Provider>
    );

    // assert(consoleErrorSpy.called, 'console.error must have been called in this case too');

    // console.error.restore();
  });
catamphetamine commented 8 years ago

Ok, here you go. The tests. https://github.com/acdlite/redux-router/pull/267

Scarysize commented 8 years ago

fixed by #267

Scarysize commented 8 years ago

republished on npm.