NervJS / taro-docs

Taro 文档
MIT License
18 stars 245 forks source link

debugReact 选项在 3.5.12 版本与 React 17 有冲突 #117

Closed Gino2333 closed 1 year ago

Gino2333 commented 1 year ago

相关平台

飞书小程序

复现仓库

git@github.com:Gino2333/FerishuTaroTest.git

使用框架: React

复现步骤

npm run dev:lark 使用飞书小程序开发者工具打开项目报错

[TMA][ERROR][RUNTIME] initApp fail, EngineError: -4026 Error: app service js execute fail: app-service.js load error: TypeError: Cannot read properties of undefined (reading 'isBatchingLegacy'), stack: TypeError: Cannot read properties of undefined (reading 'isBatchingLegacy') at ensureRootIsScheduled (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/vendors.js:45137:35) at scheduleUpdateOnFiber (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/vendors.js:44988:5) at Object.updateContainer (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/vendors.js:48366:14) at Root.render (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/taro.js:2117:38) at Object.render (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/taro.js:1859:29) at renderReactRoot (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/taro.js:490:90) at createReactApp (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/taro.js:555:21) at ./src/app.jsx (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/app.js:12073:134) at __webpack_require__ (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/runtime.js:71:36) at checkDeferredModules (file:///Users/zhanghao/.mpdev-ide/builds/f49d9074c9b0a3868aa302f47680cefd/__dist__/runtime.js:43:35)

期望结果

小程序正常运行

实际结果

小程序无法启动

环境信息

👽 Taro v3.5.12

  Taro CLI 3.5.12 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 14.19.2 - ~/.nvm/versions/node/v14.19.2/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v14.19.2/bin/yarn
      npm: 9.1.3 - ~/.nvm/versions/node/v14.19.2/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.12 => 3.5.12 
      @tarojs/components: 3.5.12 => 3.5.12 
      @tarojs/helper: 3.5.12 => 3.5.12 
      @tarojs/plugin-framework-react: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-alipay: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-jd: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-qq: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-swan: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-tt: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-weapp: 3.5.12 => 3.5.12 
      @tarojs/react: 3.5.12 => 3.5.12 
      @tarojs/router: 3.5.12 => 3.5.12 
      @tarojs/runtime: 3.5.12 => 3.5.12 
      @tarojs/shared: 3.5.12 => 3.5.12 
      @tarojs/taro: 3.5.12 => 3.5.12 
      @tarojs/taro-h5: 3.5.12 => 3.5.12 
      @tarojs/webpack5-runner: 3.5.12 => 3.5.12 
      babel-preset-taro: 3.5.12 => 3.5.12 
      eslint-config-taro: 3.5.12 => 3.5.12 
      react: ^17.0.0 => 17.0.2 
AdvancedCat commented 1 year ago

Taro 升级了 react-reconciler 至 v0.27,以支持 React18 的新特性。

经过排查,开启 debugReact 选项后,Taro会使用 React development 模式的代码,此时 react-reconciler 内部会读取一些仅在 development 下才有的属性,比如 isBatchingLegacy,而这个属性 React v17 并没有抛出。

使用 React18 是 ok,因为它抛出了相关字段。

AdvancedCat commented 1 year ago

如果是新项目,建议直接升级到 React18;

如果是旧项目,且仍需要 debugReact 的功能,可能暂时不能使用新版本了。

bigmeow commented 1 year ago

这个得写到文档里(3.5升级指南) 因为项目的生态库也要同时升级到react18,还是挺麻烦的

Chen-jj commented 1 year ago

这个得写到文档里(3.5升级指南) 因为项目的生态库也要同时升级到react18,还是挺麻烦的

@AdvancedCat 辛苦鑫哥抽空更新下文档~