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']) {