-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
Todos not populated until browser refresh #93
Comments
There are a few things this could be based on your implementation Use
|
@prescottprue Thanks for all the details. I will clean up this.loggedIn stuff, I was just being lazy trying to get stuff to work. I created localAuth so that I had an easy (documented with my own code) way of accessing profile data for the user. I actually did follow https://github.com/prescottprue/react-redux-firebase/tree/master/examples/complete/simple pretty closely, but it does not have auth setup. After auth I notice that there is no request to firebase for /todos. I see a request for /users only. |
I pulled down the simple complete example and changed to firebase config to point at my instance and added a login / logout interface. I'm able to repro the issue with this setup. I made minor changes to how the todos render, because my setup is just a simple array of strings. No other changes were made. To repro with the existing firebase api key thats setup you will have to turn on google signon in firebase console.
|
I managed to work around this auth issue by separating the firebaseConntect for 'todos' into its own component. I don't load the todos component until after auth is complete. |
@jarbot Do you mind sharing how you ended up separating the todos component? |
@Absolutestunna are you experiencing a similar issue? I'm starting to suspect my setup is the issue. Either some React.js, babel or webpack version incompatibility. The firebase connect pattern does not trigger a re-render when the todo list changes. I'm thinking of manually getting the list now with this.props.firebase.ref('todos').once('value') and managing updates/refresh on my own. The decorator pattern does not work in my stack either. This may have something to do with it. To answer your question though I did something like so (this is untested pseudo code):
|
@jarbot Is there a reason you didn't want to use firebaseConnect re-rendering
Working PatternAs long as you pass auth as a prop, the component should re-render since one of the props will change (from import React, { Component, PropTypes } from 'react'
import { isLoaded, isEmpty, pathToJS, dataToJS } from 'react-redux-firebase'
import { connect } from 'react-redux'
class App extends Component {
render() {
const { auth } = this.props
if (!isLoaded(auth) || isEmpty(auth)) {
return (<p>you need to login</p>)
}
return <TodoComponent todos={this.props.todos} />;
}
}
const fbWrappedComponent = firebaseConnect([
'/todos'
])(App)
export default connect(
({ firebase }) => ({
todos: dataToJS(firebase, 'todos'),
auth: pathToJS(firebase, 'auth')
})
)(fbWrappedComponent) I suggest moving your login logic to its own route similar to the material example. No DecoratorsEven if you are not using decorators, you can still use Higher Order Components as indicated in the docs and the Readme: class SomeComponent extends Component {
}
export default connect()(SomeComponent)
// vs
@connect()
export default class SomeComponent extends Component {
} |
I just have a habit of using lodash, no other reason. Thanks for the working example. I will test it soon. I was able to use the "Higher Order Components" without decorators but re-renders were not being triggered when the data was changing on firebase. I suspect this is an issue with my setup. I need to start a new project to figure out whats going on. |
Working example will be noted in docs and simple example README for clarity. Closing since this is understood behavior. |
….4.0 release * Added notes from #93 to simple example.
I'm using Google Sign-in for auth. This seems to be working as expected. When my app first launches the user must login to Google then the app renders after auth, but Todos are not populated until browser refresh or hot module reload.
I see this in the reactReduxFirebase log when the app starts w/ no auth:
react-redux-firebase.js:7425 event: /todos:cancel
After that events don't fire for todos, only user/profile updates.
You can see the full log before/after auth here: http://pastebin.com/whHWzrQX
Here is my App.js:
Here is where I handle logins:
I'm rendering todos in both places for debugging purposes.
Here is my store setup:
The text was updated successfully, but these errors were encountered: