From 335083ea6ed2b5602efd64feaed3e7288c022062 Mon Sep 17 00:00:00 2001 From: keiya sasaki <34934510+keiya01@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:31:25 +0900 Subject: [PATCH] fix: prevent unnecessary re-mount (#670) --- src/Globe/Globe.stories.tsx | 18 +++++++++++------- src/core/hooks.ts | 5 ++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Globe/Globe.stories.tsx b/src/Globe/Globe.stories.tsx index 4b404ba1..11dce26b 100644 --- a/src/Globe/Globe.stories.tsx +++ b/src/Globe/Globe.stories.tsx @@ -1,11 +1,11 @@ import { action } from "@storybook/addon-actions"; import { Meta, StoryObj } from "@storybook/react"; import { CesiumTerrainProvider, EllipsoidTerrainProvider, IonResource } from "cesium"; +import { StrictMode } from "react"; import Viewer from "../Viewer"; import Globe from "./Globe"; -import { StrictMode } from "react"; type Story = StoryObj; @@ -28,16 +28,20 @@ export const Basic: Story = { }; export const Promise: Story = { - args: { enableLighting: true }, - render: args => ( + args: { enableLighting: true, isTerrainEnabled: false } as any, + render: ({ isTerrainEnabled, ...args }: any) => ( diff --git a/src/core/hooks.ts b/src/core/hooks.ts index 80af8934..8e408673 100644 --- a/src/core/hooks.ts +++ b/src/core/hooks.ts @@ -78,6 +78,7 @@ export const useCesiumComponent = (propsWithChildren(props)); const prevProps = useRef({} as Props); const [mounted, setMounted] = useState(false); + const mountedRef = useRef(false); const wrapperRef = useRef(null); const stateRef = useRef(); const eventManager = ctx?.[eventManagerContextKey]; @@ -145,7 +146,7 @@ export const useCesiumComponent = 0) { + if (mountedRef.current && updatedReadonlyProps.length > 0) { if (process.env.NODE_ENV !== "production") { console.warn( `Warning: <${name}> is recreated because following read-only props have been updated: ${updatedReadonlyProps.join( @@ -254,6 +255,7 @@ export const useCesiumComponent =