Git Product home page Git Product logo

Comments (13)

ryanflorence avatar ryanflorence commented on April 24, 2024

Yeah, that seems weird.

Sent from my iPhone

On Jul 9, 2014, at 2:14 AM, Aliaksei [email protected] wrote:

It seems now that the root hander will be inited and rendered twice, because root Route calls render first time on initial and the second time after parsing URL and setState. It means Route creates two instances of handler and any functionality in render and componentDidMount is called twice almost at the same time, what is totally confusing and can lead to strange bugs.

// in each controller
componentDidMount: function() {
console.log(name);
}

// output
FrontController
FrontController
PageController
SubPageController

Reply to this email directly or view it on GitHub.

from react-router.

mjackson avatar mjackson commented on April 24, 2024

This is expected behavior. Your render function shouldn't have weird side effects.

from react-router.

ryanflorence avatar ryanflorence commented on April 24, 2024

@mjackson can you give a quick explanation on why this is expected?

from react-router.

mjackson avatar mjackson commented on April 24, 2024

It's expected because we need some time to run the willTransitionTo hooks. We don't know the state until after they run. If we were to set state immediately, users could see a flash of something they're not supposed to, like a page that requires auth.

But anyway, your render function should be able to be called many times without creating side effects, so this shouldn't be an issue.

from react-router.

ryanflorence avatar ryanflorence commented on April 24, 2024

oh that's right, thanks, was not firing on all cylinders for a minute there.

On Wed, Jul 9, 2014 at 11:04 AM, Michael Jackson [email protected]
wrote:

It's expected because we need some time to run the willTransitionTo
hooks. We don't know the state until after they run. If we were to set
state immediately, users could see a flash of something they're not
supposed to, like a page that requires auth.

But anyway, your render function should be able to be called many times
without creating side effects, so this shouldn't be an issue.


Reply to this email directly or view it on GitHub
#77 (comment)
.

from react-router.

sophiebits avatar sophiebits commented on April 24, 2024

Is it not possible to render nothing while waiting for willTransitionTo hooks on the initial render?

from react-router.

mjackson avatar mjackson commented on April 24, 2024

@spicyj The idea is that this.props.activeRoute will be undefined, so when you use it in your render function, you are essentially rendering nothing.

The other option would be to somehow tap into React.renderComponent to stop it from trying to render something until we're ready, or to possibly create our own renderComponent method which we used to have, but I'd like to avoid.

from react-router.

ryanflorence avatar ryanflorence commented on April 24, 2024

sure, just branch in render on whatever you're waiting for, probably some state in a store somewhere, or props.activeRoute

from react-router.

sophiebits avatar sophiebits commented on April 24, 2024

Maybe I'm not understanding still, but why does the root component (FrontController in the above example) need to be rendered before the URL is parsed? Something like:

render: function () {
  if (!this.state.path) {
    return null;
  }
  return this.props.handler(computeHandlerProps(this.state.matches || [], this.state.activeQuery));
}

from react-router.

mjackson avatar mjackson commented on April 24, 2024

@spicyj Doesn't React 0.10 get mad if you return null from render?

from react-router.

mjackson avatar mjackson commented on April 24, 2024

BTW, I'd love to be able to return null, and in fact we tried that approach in an earlier version of this lib. But as I recall React threw an Error.

from react-router.

sophiebits avatar sophiebits commented on April 24, 2024

Sorry, you're right; it does. You could return <div /> until React 0.11 comes out.

from react-router.

mjackson avatar mjackson commented on April 24, 2024

@spicyj That's a good idea. I think it will prevent a lot of confusion. Looking forward to 0.11! :D

from react-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.