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

Component caching and react ids #13

Open
jbrantly opened this issue Feb 24, 2016 · 0 comments
Open

Component caching and react ids #13

jbrantly opened this issue Feb 24, 2016 · 0 comments

Comments

@jbrantly
Copy link

Consider a simple cached component:

class Hello extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>
  }

  componentCacheKey() {
    return this.props.name;
  }
}

And usage like this:

const people = [{id: 0, name: 'Joe'}, {id: 1, name: 'Mary'}, {id: 2, name: 'Joe'}]

class App extends React.Component {
  render() {
    return <div>
      {people.map(person => <Hello key={person.id} name={person.name} />)}
    </div>
  }
}

If you were to run the above with SSR, React will complain that there was a difference between the client and the server when rendering. The issue is that the caching key only looks at the name prop but the actual output from the cache also contains the react id which includes the key from the first Hello component. When the second Hello component is rendered with the same name but a different key, the id is incorrect.

As an FYI, I know there have been some recent changes to React to remove the id on the clientside, and I believe I recall reading somewhere that they might be able to remove the ids in SSR as well which would address this issue.

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