Skip to content

Firestore use*Once methods seem to be susceptible to race conditions and "state update on an unmounted component". #194

Closed
@mrtnkb

Description

@mrtnkb

This looks very similar to #35, but that was marked fixed in 2019.

For slow queries and fast UI changes it is possible for either the wrong result to be displayed or "state update on an unmounted component" warnings to be shown.

This seems to be caused by the async state update in the *Once method useEffects. setValue is called asynchronously and if the get responses are returned out of order, the value state will be set to the wrong result. It can also trigger an invalid call after a component is unmounted.

get(ref.current).then(setValue).catch(setError);

A possible solution would be to have these listen==false branches return a cleanup which would cause the get response to be ignored. A work around is switching to using the non-*Once methods.

get(ref.current).then(setValue).catch(setError);

get(ref.current).then(setValue).catch(setError);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions