fix: handle Temporal objects correctly in proxy deepClone and deepEqual #434
MergedKyleAMathewsmerged 6 commits into
main fromrefs/pull/434/headmerged by KyleAMathews kevin-dp(GitHub profile, opens in a new tab) requested changes
@@ -133,3 +133,17 @@133133 return clone as unknown as T134134 }135135136+ // Handle Temporal objects137+ // Check if it's a Temporal object by checking for the Temporal brand138+ if (typeof (obj as any)[Symbol.toStringTag] === `string`) {139+ const tag = (obj as any)[Symbol.toStringTag]140+ const temporalTypes = [141+ `Temporal.PlainDate`,142+ `Temporal.PlainTime`,143+ `Temporal.PlainDateTime`,144+ `Temporal.ZonedDateTime`,145+ `Temporal.Instant`,146+ `Temporal.PlainYearMonth`,147+ `Temporal.PlainMonthDay`,148+ `Temporal.Duration`,149+ `Temporal.TimeZone`,@@ -133,3 +133,6 @@133133 return clone as unknown as T134134 }135135136+ // Handle Temporal objects137+ // Check if it's a Temporal object by checking for the Temporal brand138+ if (typeof (obj as any)[Symbol.toStringTag] === `string`) {@@ -244,3 +268,9 @@244268 return true245269 }246270271+ // Handle Temporal objects272+ // Check if both are Temporal objects of the same type273+ const aTag = (a as any)[Symbol.toStringTag]274+ const bTag = (b as any)[Symbol.toStringTag]275+276+ if (typeof aTag === `string` && typeof bTag === `string`) {@@ -246,0 +275,21 @@275+276+ if (typeof aTag === `string` && typeof bTag === `string`) {277+ const temporalTypes = [278+ `Temporal.PlainDate`,279+ `Temporal.PlainTime`,280+ `Temporal.PlainDateTime`,281+ `Temporal.ZonedDateTime`,282+ `Temporal.Instant`,283+ `Temporal.PlainYearMonth`,284+ `Temporal.PlainMonthDay`,285+ `Temporal.Duration`,286+ `Temporal.TimeZone`,287+ `Temporal.Calendar`,288+ ]289+290+ const aIsTemporal = temporalTypes.includes(aTag)291+ const bIsTemporal = temporalTypes.includes(bTag)292+293+ if (aIsTemporal && bIsTemporal) {294+ // If they're different Temporal types, they're not equal295+ if (aTag !== bTag) return false@@ -246,0 +283,21 @@283+ `Temporal.PlainYearMonth`,284+ `Temporal.PlainMonthDay`,285+ `Temporal.Duration`,286+ `Temporal.TimeZone`,287+ `Temporal.Calendar`,288+ ]289+290+ const aIsTemporal = temporalTypes.includes(aTag)291+ const bIsTemporal = temporalTypes.includes(bTag)292+293+ if (aIsTemporal && bIsTemporal) {294+ // If they're different Temporal types, they're not equal295+ if (aTag !== bTag) return false296+297+ // Use Temporal's built-in equals method if available298+ if (typeof (a as any).equals === `function`) {299+ return (a as any).equals(b)300+ }301+302+ // For Duration, use toString comparison as it doesn't have equals303+ if (aTag === `Temporal.Duration`) {@@ -741,4 +806,5 @@741806 return value.bind(ptarget)742807 }743808744- // If the value is an object, create a proxy for it809+ // Check if it's a Temporal object - don't proxy them as they're immutable810+ const isTemporalObject =kevin-dp(GitHub profile, opens in a new tab) approved these changes
KyleAMathews merged thisd64b4a8
KyleAMathews closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 1aed4aa1773c0f785413d590986e0fdd5a455d78
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 8 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