0xMiden / 0xMiden/turnkey-sdk

useTurnkeyMiden cleanup never terminates the MidenClient it creates

Aberta Para iniciantes
#16 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
3
Forks
4
Merge médio
23min
PRs com merge (30d)
2

Descrição

### Summary

`useTurnkeyMiden` creates a `MidenClient` asynchronously and stores it in React state, but the effect cleanup closes over the stale `client` value from the render that started the effect.

### Why this matters

On the first render `client` is `null`. The effect starts `loadClient()`, which later creates the real `MidenClient` and calls `setClient(...)`. Because `client` is not in the dependency list, React keeps the original cleanup closure. On unmount or dependency changes, that cleanup calls `client?.terminate()` on the stale `null` value instead of terminating the active client.

`MidenClient.terminate()` is responsible for cleaning up the client worker/resources, so this can leak a client per mount or configuration change.

### Code path

`packages/use-miden-turnkey-react/src/useTurnkeyMiden.ts`:

```ts
const [client, setClient] = useState(null);
// ... async loadClient creates midenClient and setClient(midenClient)
return () => {
mounted = false;
client?.terminate();
setClient(null);
};
```

### Expected behavior

The hook should keep the active `MidenClient` in a ref and terminate `clientRef.current` during cleanup, so the cleanup sees the client created asynchronously by the effect.

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

The issue is in packages/use-miden-turnkey-react/src/useTurnkeyMiden.ts. Look at the useEffect cleanup function that currently closes over a stale client state. The fix is to use a ref to store the active MidenClient so the cleanup can access the latest instance. Start by reading the hook's implementation, then modify it to store the client in a ref and terminate clientRef.current in the cleanup. Verify by checking that the client's terminate method is called on unmount.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript, react, typescript
Domínio
frontend, tooling
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Pouca atividade
Clareza
Claramente especificada
Facilidade para iniciantes
70/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.