fix(client): remove frozen ObjectStackClient singleton (server-switch split-brain) - #107
Merged
Merged
Conversation
… split-brain) `objectStackClient` was a module-level client built once at import with the initial API_URL. `ObjectStackClient` snapshots `baseUrl` at construction, so it stayed pinned to the startup host and would silently talk to the wrong server after the user connected elsewhere — a split-brain landmine. It had no real consumers (only a "is defined" test); every live call site uses the React-provider client (recreated on server/token change) or the live-URL helpers (`apiFetch`/`resolveApiUrl`, which read API_URL at call time). Remove the const; keep `getObjectStackClient()` (builds fresh against the current URL) as the documented non-React primitive, with a note on why there is no singleton. Add a regression test asserting it always reflects the latest `setObjectStackApiUrl` across a switch. Also fixes a latent tsc error in the P2 OptionBadge test (`type: "status"` is not a valid FieldType literal → `"select"`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Hardening from the UX session's flagged runtime server-switch gap.
The landmine
objectStackClientwas a module-level client built once at import with the initialAPI_URL.ObjectStackClientsnapshotsbaseUrlin its constructor, so the instance stayed pinned to the startup host — after the user connects to a different server, anything importing it would silently talk to the old host (split-brain).It had no real consumers (just an "is defined" test). Every live call site already uses either the React-provider client (recreated on server/token change via
_layout'suseMemo([token, serverUrl])) or the live-URL helpersapiFetch/resolveApiUrl/buildAuthInit(which readAPI_URLat call time).Change
getObjectStackClient()— it builds a fresh client against the current URL — as the documented non-React primitive, with a comment on why there is deliberately no singleton.getObjectStackClient()always reflects the latestsetObjectStackApiUrlacross a switch (server-a → server-b).tscerror in the P2OptionBadgetest (type: "status"isn't a validFieldTypeliteral →"select"; it slipped through because jest's babel transform doesn't typecheck).Verification: this isn't browser-observable (dead-code removal + a guarantee real consumers already had).
tscclean, the new regression test + full suite pass, lint clean.🤖 Generated with Claude Code