til
  • README
  • Software Development Roles
  • solid
  • README
    • service-worker
  • docker
    • arg
    • 更新docker版本
  • editor
    • vscode
    • Creating a VS Code Theme
  • english
    • words
  • front-end
    • ==
    • ECMAScript
    • IIFE
    • Label
    • basic
    • html.js.css渲染顺序
    • npm-vs-yarn
    • obj-delete-key-value
    • react
    • split-join-and-replace
    • video
    • 前端自检清单
    • 递归及去重
    • css
      • css换肤
      • flex
      • list
      • nth-child和nth-of-type区别
      • padding
      • position
      • 层叠上下文
      • 层叠样式(+)
      • 正方形
      • 语义化标签
    • dom
      • DOCTYPE
      • HEAD
      • 修改document
      • 自定义表单验证
    • electron
      • basic
    • es6
      • basic-type
      • basic
      • prototype-example
      • defineProperty
      • understanding-es6
        • 0.introduction
        • Appendix A: Smaller Changes
        • Appendix B: Understanding ES7
        • Block-Binding
        • Proxies&Reflection
        • class
        • 解构赋值
        • function
        • improved-array
        • iterators&generators
        • modules
        • object
        • promise
        • Map&Set
        • symbol
    • images
      • 前端角度看图片
    • interview_case
      • lexical_scope
      • redux和localstroage存储位置
    • javascript
      • fuck-the-js
      • js-engine-work
      • js原生操作dom
      • what-is-function-program
      • 执行上下文
      • articles
        • JavaScript中使用函数组合
        • JavaScript中的依赖注入
        • JavaScript作用域链中的标识符解析和闭包
        • JavaScript是何如工作的--概述
        • JavaScript深拷贝
        • JavaScript的全局变量是如何工作的
        • js继承常见的误解
        • node12&chrome中7个新的提案功能
        • 你真的懂JavaScript吗
      • date
        • index
      • engines
        • basic
        • JavaScript引擎基础:外形和内联缓存
        • v8中推测性优化的介绍
        • 优化原型
        • 更快的异步功能和promise
      • events
        • baisc
        • 事件冒泡和捕获
        • 定义事件
        • 页面生命周期
      • higher-order-function
        • curry
        • monad
      • module
        • basic
        • main&module
      • objects
        • iterator
        • spread
        • examples
          • iterator
      • performance
        • blocking-css
        • cache
      • prototype
        • Property-Descriptors
        • basic
        • prototype-shadow
      • you-dont-known-js
        • async&performance
          • Chapter 1: Asynchrony: Now & Later
          • Chapter 2: Callbacks
          • Chapter 3: Promises
          • Chapter 4: Generators
        • scope & closures
          • apA
          • apB
          • apC
          • apD
          • chapter1-what-is-scope
          • chapter2-lexical-scope
          • chapter3-function-vs-block-scope
          • chapter4-hoisting
          • chapter5-scope-closure
        • this & object prototypes
          • chapter1-this-or-that
          • chapter2-this-make-sense
          • chapter3-objects
          • chapter4-mixing(up)-class-object
          • chapter5-prototype
          • chapter6-behavior-delegation
        • types&grammer
          • Chapter1-Types
          • Chapter2-Values
          • Chapter3-Natives
          • Chapter4-coercion
          • Chapter5-grammer
        • up & going
          • chapter1-into-programming
          • chapter2-into-javascript
          • chapter3-into-YDKJS
    • mobile
      • iPhone分辨率终极指南
    • npm
      • arguments
      • build
    • react-native
      • prop-methods
    • react
      • PropTypes
      • basic
      • codebase-overview
      • component-element-instance
      • context
      • how-to-known-component-is-func-or-class
      • overview
      • react16.9
      • react18计划
      • react的设计原则
      • reconciliation
      • setState
      • useMemo
      • why-do-we-write-super-props
      • 从头实现一个react
      • concurrent
        • 引入并发模式(仅试验)
      • conf
        • conf-2019
      • events
        • 合成事件概述
      • hooks
        • custom-hook
        • effect-hook
        • hooks-api
        • intro
        • overview
        • rules
        • state-hook
        • hooks-vs-class
          • thinking-in-react-hooks
      • overreact
        • Development模式是如何工作的
        • How-Does-setState-Know-What-to-Do
        • Why-Do-React-Elements-Have-a-$$typeof-Property
        • Why-Do-React-Hooks-Rely-on-Call-Order
        • how-to-known-component-is-func-or-class
        • preparing-tach-talk-motivation
        • react作为ui运行
        • things-i-dont-known-as-2018
        • ui-element-problem-and-build-yourself
        • why-do-we-write-super-props
        • 一份完整的useEffect指南
        • 为什么X不是Hook
        • 函数组件与类有什么不同?
        • 演讲准备2-what-why-how
        • 编写弹性组件
        • 让setInterval在React-Hooks中为声明式
      • practice
        • render
      • react-dom
        • basic
      • react-redux
        • apiv7.1-hooks
        • connect
        • shallow-equal
      • redux
        • applyMiddleware
        • applyMiddleware2-细节
        • example
    • regex
      • index
    • stories
      • 数组下标
      • 阻止事件冒泡
    • svelte
      • compile-svelte-in-your-head-1
      • compiler-overview
      • parser
        • 写一个解析器-JavaScript的JSON解析器
    • turbopack
      • basic
    • typescript
      • interface和type的区别
    • webpack
      • hash
      • webpack4-for-react
      • webpack4
      • webpack4to5
      • babel
        • babel-parser和acorn的区别
        • babel.7.11
        • family
        • react16.14使用new-transform
        • update-to-7
    • pdf
      • deep-js
        • basic
      • react
        • reintroducing
  • git
    • capital
    • emoji
  • http
    • http2.0
    • response
  • rails
    • api
    • flash
    • middleware-vs-metal
    • model
    • performance
    • routes
    • environment
      • error
    • patterns
      • service
    • sidekiq
      • params
    • deploy
      • capistrano
        • ssh
  • ruby
    • self
    • net
      • http请求携带cookie
  • server
    • ss
    • ssh
    • user
    • crawler
      • puppeteer
    • nginx
      • domain-without-80
      • nginx节省带宽
  • sql
    • rails
    • search
Powered by GitBook
On this page
  • react使用new transform概要
  • 杂记
  • react16.8 -> react16.14.0
  • 16.9
  • 16.10
  • 16.11.0
  • 16.12.0
  • 16.13.0
  1. front-end
  2. webpack
  3. babel

react16.14使用new-transform

PreviousfamilyNextupdate-to-7

Last updated 4 years ago

react使用new transform概要

React使用。

首先要babel去支持,要把@babel/preset-react这个预设插件升级到[7.9.0](https://babeljs.io/blog/2020/03/16/7.9.0)及以上.

然后配置如下:

presets: [
    [
      '@babel/preset-react',
      {
        runtime: 'automatic',
        development: process.env.BABEL_ENV !== 'production'
      }
    ],
    // ...
]

React使用这个new transform对于版本也有要求,但是不一定需要react@^17才行,详见,可以看到react17及以上,react16.14.0,react15.7.0和react0.14.0版本都支持。

笔者从react16.8升级到了react16.14,由于项目庞大,没有直接升级到大版本,但是也整理了react16.8到react16.14.0的变更点。在文章下面罗列了出来,不感兴趣的可以忽视。

升级react(16.14.0)使用new transform 之后 出现:

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.

tsconfig 写上之后,发现对应的jsx选项报错:

Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.

这是由于vscode的ts版本,右下角点击版本号之后进行选择4.1.x。

但是发现tsx里移除React声明之后还是会有问题:

Could not find a declaration file for module 'react/jsx-dev-runtime'. '/Users/username/workspace/project/node_modules/react/jsx-dev-runtime.js' implicitly has an 'any' type.

这个是因为@types的react和react-dom版本不支持(目前是16.14.0)版本的react,但是@types里没有对应的版本,17以下只到了16.9.1。为了不出现其他的未知问题,没有更新对应的types到17。

创建一个xxx.d.ts文件写下:

declare module "react/jsx-runtime" {
  export default any;
}

这样基本就可以了。

Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?ts(2794)
lib.es2015.promise.d.ts(33, 34): An argument for 'value' was not provided.

但是为了不出现其他的问题,暂时就先这样,打算过段时间再折腾。

请原谅笔者现在才发出来,之前在公司里升级后在预发环境上放了近一个月,算下来这次的更新已经过去了两个月左右了。

由于出现了上面的部分加上不确定因素,为了不影响线上,暂时就没有升级了。

因为升级的不单单只有babel和react,还有eslint等配置梳理,很多break change。为了不出其他的幺蛾子,ts暂时就不做大的升级,所以new transform暂时也不做ts支持。

杂记

react16.8 -> react16.14.0

react

  • 移除unstable_ConcurrentMode

react-dom

  • 废弃以前 UNSAFE_* 周期方法

react-dom

react-dom

  • nextjs 中的问题

react-dom

  • react-native-web 中的问题

react-dom

react-dom

  • 修复useEffect的依赖项在多个root节点没有触发

react is

react

  • 冲突的样式规则会触发警告

  • 增加flag,质疑 unstable_createPortal,大版本移除,直接改名createPortal

  • ReactDOM添加version属性

react dom

react dom

这个是由于ts不支持,预计在。

但是升级了ts到4.1之后, ,这些报错是 4.1.0-dev.20201101 相对于4.0.5 出现的(11.2号机器人报告),后面就发版了4.1-rc及4.1.2,应该不是bug了,eslint没有检测出来,要手动修改:

讲道理,ts4.1在中就支持了。但是还是会出问题。并且no-misused-promises被设置成了checksVoidReturn和no-floating-promises设置成ignoreVoid为false也不行。

那再看一下4.1的breaking,就是 不被支持了。

升级之后,你可能也有移除import吧。使用react-codemod会有点问题

javascript:废弃 ( ,16.x的版本会在dev警告)

弃用 组件模式

useEffect里调用setState造成的循环进行

Suspense内使用findDOMNode的问题

改进effect中的setState执行,

修复hook更新没有被记忆的情况

unmount的时候清除一些属性来节省内存

修复IE10/11的textContent的问题

使用Object.is代替其polyfill

修复mouseenter在嵌套的react容器出发两次

修复lazy和memo的type类型

string类型的ref会加上提示 后续可以通过来进行处理

废弃createFactory

一个函数组件在另一个组件渲染阶段被更新时触发警告

修复onMouseEnter在disabled上面触发的问题

dev环境的StrictMode会执行生命周期两次,scu也应如此

dangerouslySetInnerHTML不要调用toString()

传统模式()下Suspense的effect的clean-up不触发的问题

移除在16.13.0添加的警告信息

支持新的jsx转换

new transform
此处
4.1里支持
有些报错
eslint-4.7
https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#resolves-parameters-are-no-longer-optional-in-promises
https://github.com/reactjs/react-codemod/issues/283
16.9
breaking change
module pattern
提示
崩溃
流程改进
16.10
Reset didReceiveUpdate in beginWork
Clear more properties in detachFiber
prevent firefox marking required textareas invalid
Optimize objectIs
16.10.1
16.10.2
16.11.0
Fix mouseenter handlers fired twice
16.12.0
[Bugfix] Passive effects triggered by synchronous renders in a multi-root app
useEffect callback never called
Fix react-is memo and lazy type checks
16.13.0
Add different string ref warning when owner and self are different
codemod
Add React.createFactory() deprecation warning
Re-enable shorthand CSS property collision warning
Warn about conflicting style values during updates
16.13.0/warnings-for-conflicting-style-rules
Warn for update on different component in render
Add unstable_renderSubtreeIntoContainer and unstable_createPortal feature flags
instead of unstable
Fix onMouseEnter is fired on disabled buttons
StrictMode should call sCU twice in DEV
Remove toString of dangerouslySetInnerHTML
16.13.1
legacy mode
Bugfix: Dropped effects in Legacy Mode Suspense
Don't fire the render phase update warning for class lifecycles
16.14.0
Introducing the New JSX Transform