From 33309358b93517bdc9b8934b0589db06feda4d94 Mon Sep 17 00:00:00 2001 From: nanyuantingfeng Date: Wed, 21 Jan 2026 16:53:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(shared):=20=E6=94=AF=E6=8C=81clone?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=92=8Cdayjs=E5=AF=B9=E8=B1=A1=E7=9A=84?= =?UTF-8?q?=E5=85=8B=E9=9A=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增对含有clone方法对象和dayjs对象的克隆支持,完善clone函数功能并增加对应测试用例。 注: dayjs@1.11.10支持了标记位: `$isDayjsObject`, 更老的版本则使用clone函数 --- packages/shared/src/__tests__/index.spec.ts | 3 +++ packages/shared/src/clone.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/shared/src/__tests__/index.spec.ts b/packages/shared/src/__tests__/index.spec.ts index be7a04e6b71..0dd74a3f169 100644 --- a/packages/shared/src/__tests__/index.spec.ts +++ b/packages/shared/src/__tests__/index.spec.ts @@ -1,4 +1,5 @@ import moment from 'moment' +import dayjs from 'dayjs' import { Map as ImmutableMap } from 'immutable' import { isEqual } from '../compare' import { @@ -374,6 +375,8 @@ describe('clone and compare', () => { expect(clone(regexp) === regexp).toBeTruthy() const promise = Promise.resolve(1) expect(clone(promise) === promise).toBeTruthy() + const day = dayjs() + expect(clone(day).toISOString() === day.toISOString()).toBeTruthy() }) test('shallowClone', () => { diff --git a/packages/shared/src/clone.ts b/packages/shared/src/clone.ts index 6c850382963..20445f143dd 100644 --- a/packages/shared/src/clone.ts +++ b/packages/shared/src/clone.ts @@ -13,12 +13,18 @@ export const shallowClone = (values: any) => { if (values['_isAMomentObject']) { return values } + if (values['$isDayjsObject']) { + return values + } if (values['_isJSONSchemaObject']) { return values } if (isFn(values['toJS'])) { return values } + if (isFn(values['clone'])) { + return values['clone']() + } if (isFn(values['toJSON'])) { return values } @@ -48,12 +54,20 @@ export const clone = (values: any) => { if (values['_isAMomentObject']) { return values } + + if (values['$isDayjsObject']) { + return values + } + if (values['_isJSONSchemaObject']) { return values } if (isFn(values['toJS'])) { return values['toJS']() } + if (isFn(values['clone'])) { + return values['clone']() + } if (isFn(values['toJSON'])) { return values['toJSON']() } From 77f8aa2c59f74886cc8971d41ab59b14122c1360 Mon Sep 17 00:00:00 2001 From: gongyanyu Date: Sat, 7 Mar 2026 16:21:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(shared):=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shared/src/clone.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/shared/src/clone.ts b/packages/shared/src/clone.ts index 20445f143dd..3964660b53e 100644 --- a/packages/shared/src/clone.ts +++ b/packages/shared/src/clone.ts @@ -13,6 +13,9 @@ export const shallowClone = (values: any) => { if (values['_isAMomentObject']) { return values } + + // >= dayjs@1.11.10 has `$isDayjsObject` check logic + // following the `moment` convention, return the original object directly if (values['$isDayjsObject']) { return values } @@ -22,6 +25,9 @@ export const shallowClone = (values: any) => { if (isFn(values['toJS'])) { return values } + // < dayjs@1.11.10 has `clone` method, directly return a new object from `clone`, which won't cause logic issues. + // This check needs to be done before `toJSON` to avoid executing dayjs's `toJSON` method, which could cause type errors + // This logic check also applies to other similar objects, because the current method expects the return value to be the same as the input if (isFn(values['clone'])) { return values['clone']() }