Skip to content

useCallableFunctionResponse invokes the cloud function on every re-render #744

Description

@tyler-reitz

Problem

useCallableFunctionResponse constructs its observable source eagerly via rxfire's httpsCallable, which invokes the cloud function at hook-render time. Every re-render that doesn't hit the observable cache fires a real cloud function call that is then discarded.

Unlike useIdTokenResult (which wastes a network read), this has a write-side effect: the function executes and bills against quota on every render cycle.

Fix

Wrap in defer() so the function is invoked at subscription time, not render time:

const observable$ = defer(() => httpsCallable(functionRef, data, options));

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    v5Planned for v5

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions