Skip to content

fix(client-react): create WalletAPIClient once in WalletAPIProvider#574

Merged
Justkant merged 1 commit into
mainfrom
fix/provider-strict-mode-client
May 30, 2026
Merged

fix(client-react): create WalletAPIClient once in WalletAPIProvider#574
Justkant merged 1 commit into
mainfrom
fix/provider-strict-mode-client

Conversation

@Justkant
Copy link
Copy Markdown
Collaborator

The provider created the client inside a useState initializer. Since the WalletAPIClient constructor has a side effect (it registers itself on transport.onMessage), React strict mode's double-invocation constructed a second, discarded client whose constructor hijacked the transport. Responses were then routed to a client with no pending requests, throwing no ongoingRequest — which broke the Next.js simulator example.

Use the ref "create once" pattern so exactly one client is instantiated and remains the owner of the transport, even under strict mode.

Also make the example's simulator flag detection more forgiving: ?simulator (bare) now activates the simulator, not just ?simulator=true.

The provider created the client inside a `useState` initializer. Since the
`WalletAPIClient` constructor has a side effect (it registers itself on
`transport.onMessage`), React strict mode's double-invocation constructed a
second, discarded client whose constructor hijacked the transport. Responses
were then routed to a client with no pending requests, throwing
`no ongoingRequest` — which broke the Next.js simulator example.

Use the ref "create once" pattern so exactly one client is instantiated and
remains the owner of the transport, even under strict mode.

Also make the example's simulator flag detection more forgiving: `?simulator`
(bare) now activates the simulator, not just `?simulator=true`.
@Justkant Justkant self-assigned this May 30, 2026
@Justkant Justkant requested review from a team and ComradeAERGO as code owners May 30, 2026 17:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 30, 2026

🦋 Changeset detected

Latest commit: 4ac78e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@ledgerhq/wallet-api-client-react Patch
@ledgerhq/client-nextjs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
wallet-api-wallet-api-tools Ready Ready Preview, Comment May 30, 2026 5:41pm

Request Review

@Justkant Justkant merged commit abf28de into main May 30, 2026
12 checks passed
@Justkant Justkant deleted the fix/provider-strict-mode-client branch May 30, 2026 17:45
@github-actions github-actions Bot mentioned this pull request May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant