Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds, useBounds(): Unexpected view reset on render (v9.119.0) #2319

Open
chrisandrew-dev opened this issue Jan 21, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@chrisandrew-dev
Copy link

  • three version: 0.171.0
  • @react-three/fiber version: 8.17.10
  • @react-three/drei version: 9.119.0
  • node version: 20.18.1
  • npm (or yarn) version: npm 10.8.2 / yarn 1.22.22

Problem description:

@react-three/drei v9.119.0 appears to break functionality of <Bounds /> / useBounds(). Rolling back to v9.80.2 fixes the issue.

I have a component, <Rig/>, that is responsible for changing the view based on the current route and search params. It functions similarly to <SelectToZoom /> in this example referenced by the Bounds docs, except that the to() method is used to fine-tune the view.

With v9.80.2, the view transitions smoothly from whatever the current view to the new view, whenever the view should be changed.

With v9.119.0, the view instantly resets to the initial view of the scene before transitioning to the new view, whenever the view should be changed. The 'snap' back to the initial view is jarring, and I wasn't able to isolate any obvious reason for the change (for example, checking for state and dependency changes that may trigger the reset).

Relevant code:

export const Rig = ({ children }) => {
  // ...
  const [searchParams] = useSearchParams();
  const selectedRegion = searchParams.get('selectedRegion');
  const bounds = useBounds();

  useEffect(() => {
    // ...

    if (!!selectedRegion) {
      bounds.to({ position: settings[selectedRegion].position, target: settings[selectedRegion].target });
    }

    // ...
  }, [selectedRegion, ... ]);

  useFrame(() => {
    // ...
  });

  return <group>{children}</group>;
}

const WebGlExperience = (props) => {
  // ...

  return (
    // ...
    <Bounds clip damping={3} observe margin={1}>
       // ...
       <Float ... >
         <Rig ... >
           // ...
         </Rig>
       </Float>
    </Bounds>
    // ...
  )
}

Suggested solution:

It's entirely reasonable to suspect the culprit is my garbage code. However, rolling back to v9.80.2 fixes the issue. Review changes made between versions that could have introduced changes to expected behaviour.

Please let me know if a demo is necessary to debug the problem and I will aim to put together a simplified version of the production code.

@chrisandrew-dev chrisandrew-dev added the bug Something isn't working label Jan 21, 2025
@talkingtab
Copy link
Contributor

An outsider, but I am trying to gain a good understanding of Bounds. It would indeed help if you can put together a minimal demo. (And personally, I find that half the time when I do this I find the problem in my code.)
Things of note when looking at the Bounds() source code
https://github.com/pmndrs/drei/blob/master/src/core/Bounds.tsx

the damping={3}. The source has a fairly large section about animation?

And latest version has deprecated to(), @deprecated Use moveTo and lookAt instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants