如何修复任何 Bug
October 21, 2025
2025 年 10 月 21 日
I’ve been vibecoding a little app, and a few days ago I ran into a bug.
我一直在 vibecoding 一个小应用,几天前我碰到了一个 bug。
The bug went something like this. Imagine a route in a webapp. That route shows a sequence of steps—essentially, cards. Each card has a button that scrolls down to the next card. Everything works great. However, as soon as I tried to also call the server from that button, scrolling would no longer work. It would jitter and break.
这个 bug 大致是这样的。想象一个 webapp 中的路由。该路由展示一系列步骤——也就是卡片。每张卡片都有一个按钮,点击后会滚动到下一张卡片。一切运行良好。然而,一旦我尝试同时在该按钮里调用服务器,滚动就不再生效。它会抖动并失效。
So, adding a remote call somehow broke scrolling.
所以,添加一个远程调用不知怎地就破坏了滚动。
I wasn’t sure what’s causing the bug. Clearly, the newly added remote server call (which I was doing via React Router actions) was somehow interfering with my scrollIntoView
call. But I couldn’t tell how. I initially thought the problem was that React Router re-renders my page (an action causes a data refetch), but in principle there’s no reason why a refetch would interfere with an ongoing scroll. The server was returning the same items, so it shouldn’t have changed anything.
我还不确定 bug 的根因。显然,新加的远程服务器调用(我通过 React Router actions 实现)以某种方式干扰了我的 scrollIntoView
调用,但我看不出具体机制。起初我以为问题在于 React Router 会重新渲染页面(action 触发数据重新获取),但理论上重新获取数据不应影响正在进行的滚动。服务器返回的数据项完全相同,因此不该有任何变化。
In React, a re-render should always be safe to do. Something else was wrong—either in my code, or in React Router, or in React, or even in the browser itself.
在 React 中,重新渲染应该始终是安全的。问题出在别处——要么是我的代码,要么是 React Router,要么是 React,甚至可能是浏览器本身。
How do I fix this bug?
我该如何修复这个 bug?
Can I get Claude to fix it?
能让 Claude 来修吗?
Step 0: Just Fix It
第 0 步:直接修
I told Claude to fix the problem.
我让 Claude 去修复这个问题。
Claude tried a few things. It rewrote conditions in the useEffect
that contains the scrollIntoView
call and said that the bug was fixed. But that didn’t help. It then tried changing smooth
scrolling to instant
, and a few other things.
Claude 试了几种做法。它重写了包含 scrollIntoView
调用的 useEffect
里的条件,并说 bug 已修复。但这并没有帮助。随后它又把 smo...