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

fix: update readonly props without strict mode #679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions src/ImageryLayer/ImageLayer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meta, StoryObj } from "@storybook/react";
import { ArcGisMapServerImageryProvider, IonImageryProvider } from "cesium";
import { ArcGisMapServerImageryProvider, IonImageryProvider, IonWorldImageryStyle } from "cesium";
import { StrictMode } from "react";

import Viewer from "../Viewer";

Expand All @@ -13,15 +14,45 @@ export default {
} as Meta;

export const Basic: Story = {
render: args => (
argTypes: {
tile: { options: ["arcgis", "cesium"], control: { type: "select" } },
} as any,
render: ({ tile, ...args }: any) => (
<Viewer full>
<ImageryLayer
{...args}
imageryProvider={ArcGisMapServerImageryProvider.fromUrl(
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
)}
imageryProvider={
tile === "arcgis"
? ArcGisMapServerImageryProvider.fromUrl(
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
)
: IonImageryProvider.fromAssetId(IonWorldImageryStyle.AERIAL)
}
/>
<ImageryLayer alpha={0.5} imageryProvider={IonImageryProvider.fromAssetId(3812, {})} />
</Viewer>
),
};

export const Strict: Story = {
argTypes: {
tile: { options: ["arcgis", "cesium"], control: { type: "select" } },
} as any,
render: ({ tile, ...args }: any) => (
<StrictMode>
<Viewer full>
<ImageryLayer
{...args}
imageryProvider={
tile === "arcgis"
? ArcGisMapServerImageryProvider.fromUrl(
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
)
: IonImageryProvider.fromAssetId(IonWorldImageryStyle.AERIAL)
}
/>
<ImageryLayer alpha={0.5} imageryProvider={IonImageryProvider.fromAssetId(3812, {})} />
</Viewer>
</StrictMode>
),
};
7 changes: 3 additions & 4 deletions src/ImageryLayer/ImageryLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export type ImageryLayerCesiumReadonlyProps = Omit<
imageryProvider: ImageryProvider | Promise<ImageryProvider>;
};

export type ImageryLayerProps = ImageryLayerCesiumProps &
ImageryLayerCesiumReadonlyProps;
export type ImageryLayerProps = ImageryLayerCesiumProps & ImageryLayerCesiumReadonlyProps;

const cesiumProps = [
"alpha",
Expand Down Expand Up @@ -109,8 +108,8 @@ const ImageryLayer = createCesiumComponent<CesiumImageryLayer, ImageryLayerProps

// Remove the awaited result from the waiting list.
if (context.__$internal?.imageryLayerWaitingList) {
context.__$internal.imageryLayerWaitingList =
context.__$internal.imageryLayerWaitingList.filter(i => i !== imageryProvider);
const index = context.__$internal.imageryLayerWaitingList.indexOf(imageryProvider);
context.__$internal.imageryLayerWaitingList.splice(index, 1);
}

if (!result) return;
Expand Down
4 changes: 2 additions & 2 deletions src/core/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
// Update properties of cesium element
useEffect(() => {
const update = async () => {
if (mountReadyRef.current) {
await mountReadyRef.current;
if (unmountReadyRef.current) {
await unmountReadyRef.current;
}

const propsWC = propsWithChildren(props);
Expand Down
Loading