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

Hotspots bug out when using React.StrictMode #124

Open
khalv opened this issue Aug 24, 2023 · 0 comments
Open

Hotspots bug out when using React.StrictMode #124

khalv opened this issue Aug 24, 2023 · 0 comments

Comments

@khalv
Copy link

khalv commented Aug 24, 2023

This issue was a real pain in the a** to debug...

Let's look at this code, from renderImage:

    if (state === "update") {
      this.panorama.destroy();
    }
    this.panorama = pannellum.viewer(
      this.props.id ? this.props.id : this.state.id,
      jsonConfig
    );

What it says is that it only destroys the old viewer if we're in an update, essentially assuming that we'll only ever mount once.

Well, the thing about React.StrictMode is that it invokes component mounting twice! Since the VIewer constructor adds the pnlm-render-container by finding the pannellum element by ID and appending elements to it, it means that both pnlm-render-container + all hotspots will be added twice. The duplicate hotspots will be overlaid to the screen and never update their positions. Great.

Instead of even bothering with the whole "state" thing, why not just delete it only if the old viewer is not undefined?

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

No branches or pull requests

1 participant