Skip to content

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

@benwiles1

Description

@benwiles1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions