记录一次bug排查
背景
测试同学提了一个测试环境表格无法切换每页条数的 bug。
排查过程
在测试环境操作后发现,确实存在该问题,但是切换到对应测试分支,本地运行,未能重现。
在测试环境的操作发现实际上切换每页条数的回调 onShowSizeChange 确实会触发,但是此后又变回原每页条数。
对于测试环境与本地开发的表现不一致,在排除了各种可能性之后,猜测是依赖版本不一致导致的。
版本不一致出现问题此前已经出现过一次:我本地的有段代码提示了一个 eslint 的 no-throw-literal,但是别的同事都没有报错, eslintrc 的配置是一样的。最终发现是我的 umi 版本比较高,其中依赖的 @typescript-eslint/eslint-plugin 在 2.13.0 新增了 no-throw-literal 这个配置,而别的小伙伴们的版本低于此,故不会报错。
因此执行命令 npm ci ,该命令会按照 packge-lock.json 中记录的版本进行安装,下面是这个命令的说明
This command is similar to
npm-install, except it’s meant to be used in automated environments such as test platforms, continuous integration, and deployment – or any situation where you want to make sure you’re doing a clean install of your dependencies. It can be significantly faster than a regular npm install by skipping certain user-oriented features. It is also more strict than a regular install, which can help catch errors or inconsistencies caused by the incrementally-installed local environments of most npm users.
重新安装依赖之后果然本地可以重现该问题。
此后经过 debug 发现,切换 pageSize 会先后触发 onShowSizeChange 和表格的 onChange,表格的 onChange 重新将 pageSize 设置回去。
总结
最终如何解决上述 bug 就不赘述了。
主要想总结的是:遇到 bug,如果出现代码和运行环境之类的各种条件都一致,但是表现就是不一致的情况,那么很有可能是依赖包的版本不一致导致的 👻