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

Updating props to <Globe> component clears terrainProvider if unset and recomputes terrainProvider if set #692

Open
benwiles1 opened this issue Jan 14, 2025 · 0 comments

Comments

@benwiles1
Copy link
Contributor

Reporoduction:

// example setup to cause props to change after 1 second
function useLightingDelay(){
    const [lighting, setLighting] = useState(true);
    useEffect(() => {
      const timer = setTimeout(() => {
        setLighting(false);
      }, 1000);
      return () => clearTimeout(timer);
    });
    return lighting;
}

// example terrain (same class as default terrain, but obviously a fresh instance)
// createWorldTerrainAsync() also has the same behavior if you want to test with promises.
const terrain = new EllipsoidTerrainProvider();

// after update, globe disappears, leaving only atmospheric effects
function Breaks(){
  const lighting = useLightingDelay();
  return (
    <Viewer>
      <Globe enableLighting={lighting}/>
    </Viewer>
  );
}

// after update, globe disappears, leaving only atmospheric effects
function AlsoBreaks(){
  const lighting = useLightingDelay();
  return (
    <Viewer terrainProvider={terrain}>
      <Globe enableLighting={lighting}/>
    </Viewer>
  );
}

// after update, globe disappears until terrain is recalculated
function Flashes(){
  const lighting = useLightingDelay();
  return (
    <Viewer>
      <Globe enableLighting={lighting} terrainProvider={terrain} />
    </Viewer>
  );
}

// after update nothing happens (other than lighting being disabled).
// this is what I would expect to happen for both examples above
function Workaround(){
  const lighting = useLightingDelay();
  return (
    <Viewer terrainProvider={terrain}>
      <Globe enableLighting={lighting} terrainProvider={terrain} />
    </Viewer>
  );
}

I believe this is due to the unconditional assignment at https://github.com/reearth/resium/blob/main/src/Globe/Globe.ts#L119 .
But I don't understand why it doesn't apply on the first render.

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