Skip to content

Fix: encodeDates mutates the object passed to people.set (#479) - #608

Open
sarmah-rup wants to merge 1 commit into
mixpanel:masterfrom
sarmah-rup:fix/encode-dates-mutation
Open

Fix: encodeDates mutates the object passed to people.set (#479)#608
sarmah-rup wants to merge 1 commit into
mixpanel:masterfrom
sarmah-rup:fix/encode-dates-mutation

Conversation

@sarmah-rup

Copy link
Copy Markdown

What I hit

I passed a Date to mixpanel.people.set(...) and the Date on my own object silently turned into a string on the next render, which broke a date-picker bound to that object. This is issue #479.

Minimal repro:

var props = { created: new Date('2020-01-02T03:04:05Z') };
mixpanel.people.set(props);
props.created; // "2020-01-02T03:04:05"  <- mutated in place, no longer a Date

Why

_.encodeDates (src/utils.js) writes the encoded strings back onto the object it is given (obj[k] = _.formatDate(v)) and recurses onto the same nested references, so it edits the exact object the caller passed to people.set / set_once (and group set).

Fix

Build a copy instead of mutating the input. The encoded output is identical to before; only the side effect on the caller's object is removed. (_.isObject excludes arrays, so recursion still only descends into plain objects.)

Test

Added cases to tests/unit/utils.js: encoding still works (top-level + nested) and the input object is no longer mutated (top-level + nested). Full tests/unit/* suite passes (684 passing, 0 failing) and eslint ./src is clean.

Closes #479.

@sarmah-rup
sarmah-rup requested review from a team and jakewski July 21, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant