Skip to content

fix: replace setTimeout with requestAnimationFrame for fitView#351

Open
itvi-1234 wants to merge 3 commits into
ioflux-org:mainfrom
itvi-1234:fix/jerk
Open

fix: replace setTimeout with requestAnimationFrame for fitView#351
itvi-1234 wants to merge 3 commits into
ioflux-org:mainfrom
itvi-1234:fix/jerk

Conversation

@itvi-1234

@itvi-1234 itvi-1234 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Description

Replaced setTimeout with requestAnimationFrame (rAF) and removed the animation duration.
By using requestAnimationFrame, we sync our fitView call exactly with the browser's paint cycle. This guarantees that fitView fires instantly after the DOM has fully committed the resolved node positions, making the load sequence look like a single, seamless frame.

closes #348

Before (the jerky situation)

image

After (the smooth)

image

itvi-1234 added 2 commits June 6, 2026 15:55
…collision resolution

Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
@itvi-1234

Copy link
Copy Markdown
Contributor Author

Hi @AgniveshChaubey , could you please review this PR whenever have some time

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Preview Deployed!

Item Status
Latest Deploy Visit Preview
Environment Preview (PR-351)
Action View Logs

Last updated at 2026-06-06T10:41:38Z

…on node update

Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
useEffect(() => {
if (!collisionResolved) return;
const rafId = requestAnimationFrame(() => {
fitView({ padding: 0.05, duration: 300 });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reducing the animation duration makes the UX look a bit odd. Also, requestAnimationFrame did make the animation a bit smooth, but when you look closely, you'll still notice that the zoom-in is happening in steps. It would be a good idea to figure out the root cause and fix that instead of applying patches.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey all,
I am exploring the root causes of this and I found something which I'd like to share with you.
This problem occurs because the canvas is animating its viewport scale before the node measurement(after nodes are initially rendered) have finished. So this create a sudden jerky visual jump.

Some root causes might be :

Unmeasured node dimension: This happens when we have fitView: true enabled or trigger a viewport change on mount, react flow calculates the zoom level using unmeasured (0, 0) dimensions. A millisecond later, the DOM renders the nodes, updates their width/height boundaries, and React Flow snaps the camera hard to fix the view.

Asynchronous Layout Engines & fitView Loops: This happens when the layout algorithms like Dagre etc. to auto-arrange elements on load, these manipulate positions asynchronously.
If a zoom action begins before the data finishes mapping or before setNodes() fully finishes updating the internal React Flow store, the math behind the zoom focal point gets broken by stale positioning, causing the canvas to glitch back and forth.

React 18 Concurrent Rendering & React.StrictMode:
In development environments, React.StrictMode renders component hierarchy twice.
Two overlapping zoom adjustments attempt to lock on the state coordinates simultaneously.

These above causes found out from an internet, we have to see that if one of these causing the problem or not , And might be there could be other causes as well that would be need to find out.

@AgniveshChaubey

Copy link
Copy Markdown
Member

We're about to release v0.9.0, but we can't move ahead with this recently introduced issue. If anyone has some time, can we look into this? That'll help us proceed with the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: zoom-in animation stutters during application reload

3 participants