Skip to content

useIdTokenResult fires a redundant token fetch on every re-render #743

Description

@tyler-reitz

Problem

useIdTokenResult constructs its observable source eagerly:

const observable$ = from(user.getIdTokenResult(forceRefresh));

from(promise) is called at hook-render time, so every re-render that doesn't hit the observable cache fires a discarded getIdTokenResult network request. This is the same pattern fixed in useStorageDownloadURL by #735.

Fix

Wrap in defer() so the promise is constructed at subscription time, not render time:

const observable$ = defer(() => user.getIdTokenResult(forceRefresh));

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