Skip to content

Conversation

@regexident
Copy link
Contributor

@regexident regexident commented Jun 7, 2025

I discovered the bug while experimenting with an approach of adjusting the alphaTarget/alphaDecay dynamically, based on the simulation's total kinetic energy (i.e. sum of node velocities): the simulation just kept running, despite alpha having dropped far, far below 0.001 already.

Any change to alphaTarget/alphaDecay caused the simulation to get restarted, even if alpha had already fallen below alphaMin.

There are a couple of places where runOrResumeSimulation(); gets called, but currently only one of them is guarded by a alpha >= alphaMin check, so I move the check into runOrResumeSimulation() itself.

The bug is trivially reproducible by doing something like this:

function handleTick(e: { alpha: number; alphaTarget: number }) {
    // the re-fires the simulation, but due to `alphaTarget < alphaMin` it should still terminate:
    alphaTarget = Math.random() * alphaMin;
    console.log(alpha, alphaTarget, alpha >= alphaMin);
}

<ForceSimulation {alphaTarget} onTick={handleTick} ...>...</ForceSimulation>

@changeset-bot
Copy link

changeset-bot bot commented Jun 7, 2025

🦋 Changeset detected

Latest commit: 950214d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
layerchart Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
layerchart ✅ Ready (View Log) Visit Preview 950214d

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/layerchart@546

commit: 950214d

Copy link
Owner

@techniq techniq left a comment

Choose a reason for hiding this comment

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

Nice catch! I noticed this the other day while I was experimenting with something. Thanks for the fix!

@techniq
Copy link
Owner

techniq commented Jun 7, 2025

@regexident care to run pnpm format to apply prettier formatting and make CI happy?

…on running, when its inputs change, even if `alpha < alphaMin`
@regexident regexident force-pushed the fix-force-simulation-termination branch 2 times, most recently from 950214d to cd6f755 Compare June 7, 2025 15:12
@regexident regexident force-pushed the fix-force-simulation-termination branch from cd6f755 to 950214d Compare June 7, 2025 15:21
@techniq techniq merged commit f37703b into techniq:next Jun 7, 2025
6 of 7 checks passed
@github-actions github-actions bot mentioned this pull request Jun 6, 2025
@techniq techniq mentioned this pull request Sep 23, 2025
This was referenced Oct 19, 2025
This was referenced Dec 27, 2025
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.

2 participants