Repository navigation
Conversation
PresenceAdapter.transformState() built the returned state with newState[key] = ..., so a presence key named "__proto__" invoked the __proto__ setter instead of becoming a key. The entry was missing from presenceState() while join and sync events still fired for it, and the returned object's prototype was replaced by the transformed presences. Define each key as an own property instead, as is already done for the presence metas.
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
Summary
A presence key named
__proto__is silently missing fromchannel.presenceState(), even though thejoinandsyncevents fire for it.PresenceAdapter.transformState()built its result withnewState[key] = ..., which for that key calls the__proto__setter instead of creating an entry. This defines each key as an own property instead.Problem and reproduction
presenceState(). The same file already handles__proto__for presence metas (it copies property descriptors because plain assignment treats__proto__as a setter); the top-level keys were missed.transformStateinsrc/phoenix/presenceAdapter.tsreduced into{}withnewState[key] = transformState(presences).presence_stateframe containing{"alice": {...}, "__proto__": {...}}(presence keys are chosen by clients viaconfig.presence.key) yieldsObject.keys(channel.presenceState())of['alice'], no__proto__entry, and the returned object's prototype is the transformed presences array. The raw phoenix state does contain the key.Solution
Object.definePropertyper key (enumerable, writable, configurable, same as a normal property), so the key is kept as an own property and the object keepsObject.prototype.Object.fromEntries(works, but its multi-line call form conflicts with this package'scomma-danglelint rule),Object.create(null)(would change the prototype of the returned object for everyone).Verification
test/presence.protoKey.test.ts: onmasterit fails (['alice']instead of['__proto__', 'alice']); with the patch it passes. It also checks the entry's value and that the returned object keepsObject.prototype.realtime-jssuite (vitest, no Docker):master26 files / 509 tests pass (1 skipped); patch 27 files / 510 tests pass (1 skipped), i.e. only the new test is added.prettier --check,eslinton the changed files, andnx build @supabase/realtime-jsare clean.Prior-art and overlap check
gh search(open and closed); terms:__proto__, prototype, presenceState, presence key, transformState; and a scan of open PRs touchingpresenceAdapter.ts(none).Risks
__proto__key now appears.