Skip to content

v2 - silent-connect ("neverAsk") regression #166

@avimak

Description

@avimak

v2 introduces a regression in the silent-connect (now "neverAsk") flow.

    // silently attempt to connect with a pre-authorized wallet
    useEffect(() => {
        // match the dapp with a wallet instance
        connect({ modalMode: "neverAsk" }).then(wallet => {
            // connect the dapp with the chosen wallet instance
            wallet?.enable().then(() => {
                const isConnected = !!wallet?.isConnected;
                setIsConnected(isConnected);
            });
        });
    }, []);

the code above works 100% of the time using v1.5, and it fails on v2.

I suspect a race because adding a timeout with delay=0 helps, i.e. -

    // silently attempt to connect with a pre-authorized wallet
    useEffect(() => {
        setTimeout(() => {
            // match the dapp with a wallet instance
            connect({ modalMode: "neverAsk" }).then(wallet => {
                // connect the dapp with the chosen wallet instance
                wallet?.enable().then(() => {
                    const isConnected = !!wallet?.isConnected;
                    setIsConnected(isConnected);
                });
            });
        }, 0); // <-- no real delay, just skip a cycle
    }, []);

to reproduce, simply use the first version (without a timeout), choose a wallet, approve the connection (aka "pre-authorize"), then refresh the page. do it with a visible browser-inspect-application tab displayed, you'll see the id being removed (ptobably because getAvailableWallets returns empty array).

one more thing - if you adding a timeout, the code works, but you'll see multiple storage ids, meaning there are more races in there.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions