Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should this.idx be this.index ? #21

Closed
tswaters opened this issue Apr 24, 2017 · 0 comments
Closed

should this.idx be this.index ? #21

tswaters opened this issue Apr 24, 2017 · 0 comments

Comments

@tswaters
Copy link
Contributor

tswaters commented Apr 24, 2017

I'm working on a higher order component that wraps fetchState. You can see it here:

https://github.com/tswaters/react-todo/blob/e0e539ae21528dfac07d1fdf24458012f0861a83/src/common/initial-data.jsx

The idea here is to load localization values a component needs in addition to any promises that need to be resolved prior to rendering.... I noticed a problem with this approach - I would sometimes get ready set to true without firing done, and no locale key found would show up.

(Initially, I tried to fix this by adding some kind of uniqueness to the component, so instead of a generic ready I actually used the name of the component as the key for done and for checking. This seemed to work initially, but has a flaw if multiples of the same component are in use - only the first is rendered.... (see this revision))

Anyway, inspecting the props of the component at the time of componentWillMount I found that I was getting the wrong data context the done was fired with. I tested this by including the name of the component with the ready boolean - and in some cases, the name as completely different than what should have been loading. This results in the component thinking it's already loaded and not going further.

I had a line to test this inside the componentWillMount

if (this.props.isDone && name !== this.props.name) {
  console.log('wtf?!')
}

So, I went to randomly digging around the react-router-server code and I came across this line:

reactRouterServerFetchStateParentIndex: this.idx

Here's the thing, this.idx is undefined always here. There is a this.index property. I tried toggling it to test it out and... everything works properly.

Is this a typo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant