From dca92cc5c32b1711cbfd0cd873cdf4a4944d5ebc Mon Sep 17 00:00:00 2001 From: liuwei Date: Sat, 21 Jun 2025 10:30:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(json-schema):=20schema=20=E7=9A=84=20title?= =?UTF-8?q?=20=E7=AD=89=E5=B1=9E=E6=80=A7=E5=9C=A8=20react19=20production?= =?UTF-8?q?=20=E7=8E=AF=E5=A2=83=E4=B8=AD=E6=97=A0=E6=B3=95=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #4307 --- packages/json-schema/src/__tests__/shared.spec.ts | 12 ++++++++++++ packages/json-schema/src/shared.ts | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/json-schema/src/__tests__/shared.spec.ts b/packages/json-schema/src/__tests__/shared.spec.ts index 7c2c50e26b1..ec04685aac7 100644 --- a/packages/json-schema/src/__tests__/shared.spec.ts +++ b/packages/json-schema/src/__tests__/shared.spec.ts @@ -1,8 +1,20 @@ import { isNoNeedCompileObject, createDataSource } from '../shared' import { observable } from '@formily/reactive' import { Schema } from '../schema' +import { createElement } from 'react' test('isNoNeedCompileObject', () => { + expect( + isNoNeedCompileObject( + createElement( + function Test() { + return null + }, + {}, + null + ) + ) + ).toBeTruthy() expect(isNoNeedCompileObject({})).toBeFalsy() expect(isNoNeedCompileObject({ $$typeof: null, _owner: null })).toBeTruthy() expect(isNoNeedCompileObject({ _isAMomentObject: true })).toBeTruthy() diff --git a/packages/json-schema/src/shared.ts b/packages/json-schema/src/shared.ts index 7ed112c82a4..59a79a2d514 100644 --- a/packages/json-schema/src/shared.ts +++ b/packages/json-schema/src/shared.ts @@ -1,7 +1,16 @@ -import { isFn, each, isPlainObj, isArr, toArr, FormPath } from '@formily/shared' +import { + isFn, + each, + isPlainObj, + isArr, + toArr, + FormPath, + isReactElement, +} from '@formily/shared' import { isObservable, untracked } from '@formily/reactive' import { Schema } from './schema' import { ISchema } from './types' +import { isValidElement } from 'react' const REVA_ACTIONS_KEY = Symbol.for('__REVA_ACTIONS') @@ -150,7 +159,7 @@ export const traverseSchema = ( } export const isNoNeedCompileObject = (source: any) => { - if ('$$typeof' in source && '_owner' in source) { + if (isReactElement(source) || isValidElement(source)) { return true } if (source['_isAMomentObject']) {