Conversation
extend() built the extended object with a shallow spread. A spread evaluates getters and writes their current values as plain data properties, so the config and providers accessors stopped tracking the client. Because setProviders reassigns the backing array rather than mutating it, an extended client was pinned to whatever the provider list was at extend time — a host that extended before registering its wallet providers got a client whose getProvider always returned undefined, and execution could never run. Copy property descriptors instead, so the base and every extension share one live view of config and providers.
A host application and a widget can share one SDK client, and the client then carries the host's integrator, referrer and fee. Any caller that needs its own has to send them with the request, so pin the precedence: options on the request win over client config, and the client is only a fallback.
🦋 Changeset detectedLatest commit: 479fb19 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
Contributor
|
📦 Preview published under the Install the exact version(s) — npm i @lifi/sdk-provider-bitcoin@0.0.0-preview-479fb196
npm i @lifi/sdk-provider-ethereum@0.0.0-preview-479fb196
npm i @lifi/sdk-provider-solana@0.0.0-preview-479fb196
npm i @lifi/sdk-provider-stellar@0.0.0-preview-479fb196
npm i @lifi/sdk-provider-sui@0.0.0-preview-479fb196
npm i @lifi/sdk-provider-tron@0.0.0-preview-479fb196
npm i @lifi/sdk@0.0.0-preview-479fb196 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
client.extend()built the extended object with a shallow spread:configandprovidersare accessor properties. A spread evaluates them and writes their current values as plain data properties, so the extension stops tracking the client. BecausesetProvidersreassigns_providersrather than mutating it, an extended client is pinned to whatever the provider list was at extend time.Verified against the published
@lifi/sdk@4.8.0dist:So a host that extends before registering its wallet providers gets a client whose
getProvideralways returnsundefined— execution can never run. Chain and RPC storage were unaffected, becausesetChains/getChains/getRpcUrlsclose over_storagerather than going through an accessor.Changes
createClient.ts: copy property descriptors instead of spreading, so the base and every extension share one live view ofconfigandproviders.createClient.unit.spec.ts: two failing-first tests — providers registered after the extension is created, and base/extension sharing one list.getRoutes.unit.spec.ts: lock request-level attribution precedence. Once a host and a widget share a client, the client carries the host'sintegrator,referrerandfee, so every caller that needs its own must send them with the request. These pin that contract.Testing steps
pnpm test— 249 tests pass.biome,tsc, circular-deps andknipall clean via the pre-commit gate.Why did I implement it this way?
Descriptor copying is the minimal change that keeps
extend's existing shape and semantics. The alternative — makingsetProvidersmutate the array in place — would fix the symptom but leaveconfigstill copied by value.Context
Found while investigating JUM-1527 (deduplicating the SDK bootstrap between the Jumper app and the widget). The
extend-based approach was the obvious way to share a client between a host and a widget, and this is why it did not work.