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

Sending messages during the rendering phase can cause infinite update loops #933

Closed
jstarry opened this issue Feb 10, 2020 · 3 comments
Closed

Comments

@jstarry
Copy link
Member

jstarry commented Feb 10, 2020

Suggested changes

Option 1. Update the scheduler queue to prevent this
Option 2. Update documentation to warn against this behaviour

@mc1098
Copy link
Contributor

mc1098 commented Sep 8, 2021

#2040 documents this behaviour so I think the documentation label can be removed now.

@siku2 siku2 closed this as completed Sep 9, 2021
@siku2
Copy link
Member

siku2 commented Sep 9, 2021

Closing this because it's documented behaviour now. If there's a need for the scheduler to be changed, a new issue should be opened.

@zelds
Copy link

zelds commented Dec 6, 2023

    let (store, dispatch) = use_store::<Store>();
    let history = use_navigator().unwrap();
    let projects = use_state(Vec::new);


    if store.token.is_empty() {
        dispatch.reduce_mut(move |store| {
            store.error_message = "Please create account or login.".to_owned()
        });
        history.push(&Route::Login)
    }
    {
        let projects = projects.clone();
        use_effect(move || {
            spawn_local(async move {
                match get_projects(&store.token).await {
                    Ok(user_projects) => projects.set(user_projects),
                    Err(APIError::NotAuthenticated) => dispatch.reduce_mut(move |store| {
                        store.token = String::new();
                        store.email = String::new();
                    }),
                    Err(error) => {
                        log!(error.to_string())
                    }
                }
            });
        });
    };

I try to prevent loop using loaded = use_state(false) but in this case works ok for first load. And if I delete "project" from different component, using REST and use navigator to redirect to this component, its freezes, and show same data as it is at first render (without requesting REST again). Try to understand how to fix it, or atleast bypass.

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

No branches or pull requests

4 participants