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

Using Controlled zoom & ZoomContent at the same time breaks #448

Open
1 of 4 tasks
tarngerine opened this issue Nov 2, 2023 · 5 comments
Open
1 of 4 tasks

Using Controlled zoom & ZoomContent at the same time breaks #448

tarngerine opened this issue Nov 2, 2023 · 5 comments
Assignees
Labels

Comments

@tarngerine
Copy link

tarngerine commented Nov 2, 2023

Issue Type

  • Bug report
  • Feature request
  • Question / support request
  • Other

Description

See repro in Codesandbox link: https://codesandbox.io/s/snowy-hill-ltjwwc?file=/src/App.tsx

Using Controlled with ZoomContent prop breaks the webpage that it's used in. Using them separately works fine.

After the first zoom-in, the first zoom-out breaks (no animation), and every interaction on the website thereafter is locked.

@rpearce
Copy link
Owner

rpearce commented Nov 3, 2023

That sounds rough. Thanks for the report! I'll see what I can do.

@rpearce rpearce self-assigned this Nov 12, 2023
@rpearce rpearce added the bug label Nov 12, 2023
@rpearce
Copy link
Owner

rpearce commented Dec 15, 2023

This is the next issue I'm doing! Time-expectation-wise, I'll be able to look at it within the next week.

Thank you for your patience.

@rpearce
Copy link
Owner

rpearce commented Dec 20, 2023

Okay... initial finding:

Converting this

ZoomContent={(props) => <CustomZoomContent {...props} />}

to this

ZoomContent={CustomZoomContent}

works with the Controlled zoom.

However, the Uncontrolled component doesn't have this limitation. Let's see...

@rpearce
Copy link
Owner

rpearce commented Dec 20, 2023

I also was able to get it working using React.useCallback:

  const Zoom2Content = useCallback(
    (props: ControlledProps) => <CustomZoomContent {...props} />,
    []
  );

You can see that working on this CodeSandbox

@rpearce
Copy link
Owner

rpearce commented Dec 20, 2023

I think that the issue is that ={() => <Something />} creates a new instance of that component on every render, but this might not work for a reason I haven't figured out yet.

When we use Uncontrolled (the default component), it works, for (props) => <CustomZoomContent {...props} /> has only been called once, and Uncontrolled manages its own zoomed/unzoomed state.

However, with the Controlled example, if we update the parent component state, then a new instance of () => <Something /> is created and passed on every render, and the ZoomContent property seems like it can't handle that. Maybe it should?

There are some workarounds I've listed above, and this seems like a bit of a deep dive to figure out any further that I don't have time for tonight, unfortunately. G'night!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants