firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Setting a timer for a long period of time, i.e. multiple minutes

Open saeedhei opened this issue 9 years ago • 58 comments

I want to use firebase auth with react native for Login and Signup but I got a yellow error: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See (https://github.com/facebook/react-native/issues/12981) for more info. (Saw setTimeout with duration 111862ms)

How Can I Fix That? I don't want to ignore that, I want to understand this error and solve that with the best and Standard way. And This is my Code:

 export default class Login extends Component {
        constructor(props) {
            super(props)
            this.state = {
                email: '',
                password: '',
                response: ''
            }
            this.signUp = this.signUp.bind(this)
            this.login = this.login.bind(this)
        }
        async signUp() {
            try {
                await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
                this.setState({
                    response: 'Account Created!'
                })
                setTimeout(() => {
                    this.props.navigator.push({
                        id: 'App'
                    })
                }, 1500)
            } catch (error) {
                this.setState({
                    response: error.toString()
                })
            }
        }
        async login() {
            try {
                await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
                this.setState({
                    response: 'user login in'
                })
                setTimeout(() => {
                    this.props.navigator.push({
                        id: 'App'
                    })
                })

            } catch (error) {
                this.setState({
                    response: error.toString()
                })
            }

        }
        render() {
            return (
                <View style={styles.container}>
                    <View style={styles.containerInputes}>
                        <TextInput
                            placeholderTextColor="gray"
                            placeholder="Email"
                            style={styles.inputText}
                          //  onChangeText={(email) => this.setState({ email })}
                            onChangeText={(email) => {console.log(email);}}
                        />
                        <TextInput
                            placeholderTextColor="gray"
                            placeholder="Password"
                            style={styles.inputText}
                            password={true}
                            onChangeText={(password) => this.setState({ password })}
                        />
                    </View>
                    <TouchableHighlight
                        onPress={this.login}
                        style={[styles.loginButton, styles.button]}
                    >
                        <Text
                            style={styles.textButton}
                        >Login</Text>
                    </TouchableHighlight>
                    <TouchableHighlight
                        onPress={this.signUp}
                        style={[styles.loginButton, styles.button]}
                    >
                        <Text
                            style={styles.textButton}
                        >Signup</Text>
                    </TouchableHighlight>
                </View>
            )
        }
    }

I Asked From Stackoverflow too, Link

saeedhei avatar Jul 14 '17 19:07 saeedhei

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Jul 14 '17 19:07 google-oss-bot

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jul 14 '17 19:07 google-oss-bot

I assume you are including real-time database in your code? We pro-actively refresh the token when database or other Firebase services are included. The token typically has a lifetime of one hour. We would need to use some other native utility or external dependency to replace the underlying setTimeout usage for this. This will take some time to implement. It seems benign for now so I see this as a low priority.

bojeil-google avatar Jul 14 '17 20:07 bojeil-google

Yeah I'm using real-time database and when I added firebase to my project, I got This svbzc Thank you @bojeil-google

saeedhei avatar Jul 14 '17 21:07 saeedhei

@bojeil-google Could you please update here when this has been resolved? Thank you!

justColbs avatar Aug 07 '17 21:08 justColbs

constructor() { super(); console.ignoredYellowBox = [ 'Setting a timer' ]; }

andy-awsdev7 avatar Aug 15 '17 19:08 andy-awsdev7

I wonder, this issue show up only in Android, and maybe it's caused by using react-navigator, I say this, because once I all repeat from tutorial and tutor doesn't get this error and only difference between our works it's I use react-navigator instead react-native-router-flux and I work with Android instead IOS

liketurbo avatar Aug 15 '17 20:08 liketurbo

Maybe, we could throw this code below in to the project, and reset all setTimeout ?

const highestTimeoutId = setTimeout(() => ';');
for (let i = 0; i < highestTimeoutId; i++) {
    clearTimeout(i); 
}
// source: https://stackoverflow.com/questions/3847121/how-can-i-disable-all-settimeout-events

liketurbo avatar Aug 16 '17 11:08 liketurbo

When will This issue be resolved?

saeedhei avatar Oct 23 '17 16:10 saeedhei

There are bunch of high priority features and bug fixes in the pipeline. We'll switch to this issue immediately after. It's been labeled as a P3 issue which is appropriate for its severity.

bojeil-google avatar Oct 23 '17 17:10 bojeil-google

Hello guys, any update on this issue please? I have not been able to use Firebase on Android because of it.

mutazmq avatar Nov 25 '17 15:11 mutazmq

Using the native sdk instead of the js/web sdk fixes the problem.

https://github.com/invertase/react-native-firebase

It involves a lot more configuration and it won’t work with Expo tho.

mopx avatar Nov 25 '17 15:11 mopx

My understanding is that this is not a blocking issue and can be suppressed. I will try to experiment with a quick solution using react-native-background-timer and report back.

bojeil-google avatar Nov 26 '17 00:11 bojeil-google

Ok, I tried testing this issue with react native 0.48.4 and firebase 4.6.2 using an Android emulator (API 25) and I was not able to replicate this. I am not getting the warning at all.

bojeil-google avatar Nov 28 '17 03:11 bojeil-google

I am still getting this warning

Narutuffy avatar Nov 28 '17 05:11 Narutuffy

Can you provide more detailed information about your environment to facilitate replication?

bojeil-google avatar Nov 28 '17 07:11 bojeil-google

I use Expo and get this error. Perhaps it is specific to Expo, which may be why you did not get an error on your emulator.

On Tue, Nov 28, 2017 at 2:38 AM, bojeil-google [email protected] wrote:

Can you provide more detailed information about your environment to facilitate replication?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-js-sdk/issues/97#issuecomment-347438764, or mute the thread https://github.com/notifications/unsubscribe-auth/AdTknxE4yq8eD5wXOenm_14wg7o8KCJ1ks5s67h7gaJpZM4OYphr .

bogannathan avatar Nov 28 '17 14:11 bogannathan

I also used expo version ^21.0.0.

bojeil-google avatar Nov 28 '17 18:11 bojeil-google

Getting the same warning here (not using Expo)

deniscapp avatar Nov 29 '17 19:11 deniscapp

expo ^23.0.0 and getting this error on emulator and android device

kay-es avatar Nov 29 '17 21:11 kay-es