Skip to content

[Bug Report] SchemaField 在 React19 中 title 等属性无法传递组件 #4307

@liuweiGL

Description

@liuweiGL
  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

1. git clone https://github.com/liuweiGL/formily-react19-bug1.git
2. pnpm i
3. pnpm dev

通过注释 vite.config.ts 中的 process.env.NODE_ENV = 'production' 查看不同环境下 react 的表现

What is expected?

在 react19 中 production 环境正常工作

What is actually happening?

当 process.env.NODE_ENV = 'production' 生效时,页面报错

Uncaught Error: Minified React error #130; visit https://react.dev/errors/130?args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at createFiberFromTypeAndProps (react-dom-client.production.js:2562:24)
    at reconcileChildFibersImpl (react-dom-client.production.js:5465:27)
    at react-dom-client.production.js:5574:29
    at reconcileChildren (react-dom-client.production.js:6013:9)
    at updateFunctionComponent (react-dom-client.production.js:6255:3)
    at beginWork (react-dom-client.production.js:7243:14)
    at performUnitOfWork (react-dom-client.production.js:10855:14)
    at workLoopSync (react-dom-client.production.js:10736:37)
    at renderRootSync (react-dom-client.production.js:10717:7)
    at performWorkOnRoot (react-dom-client.production.js:10322:40)

Package

@formily/[email protected]


通过 debug 发现 React.createElement 方法返回的数据结构在 development 跟 production 环境不一致,分别如下。

  1. development 环境

Image

  1. production 环境

Image

可以发现 production 环境没有 _owner 属性了,但是在

if ('$$typeof' in source && '_owner' in source) {

中依赖了该属性判断是否需要跳过编译,紧接着

if ('$$typeof' in source && '_owner' in source) {

判断为 false 之后 react element 对象被继续遍历,最后导致 type 属性被下面的代码过滤了

if (String(path[0]).indexOf('x-') == -1 && isFn(target)) return

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions