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

chore: update dependency cesium to v1.116.0 #625

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
keiya01 committed Apr 4, 2024
commit 33f7bafe6c27e24e37d2299b5184fa00ca30fe55
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@
},
"peerDependencies": {
"cesium": "1.x",
"react": ">=18.2.0"
"react": ">=18.2.0",
"react-dom": ">=18.2.0"
},
"devDependencies": {
"@storybook/addon-essentials": "8.0.5",
@@ -75,4 +76,4 @@
"vitest": "1.4.0",
"web-streams-polyfill": "4.0.0"
}
}
}
29 changes: 20 additions & 9 deletions src/Entity/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Entity as CesiumEntity } from "cesium";
import { ReactNode } from "react";

import { createCesiumComponent, EventProps, PickCesiumProps, Merge, EventTarget } from "../core";
import {
createCesiumComponent,
EventProps,
PickCesiumProps,
Merge,
EventTarget,
RootComponentInternalProps,
} from "../core";

export type { EventTarget } from "../core";

@@ -75,13 +82,14 @@ export type EntityCesiumEvents = {
onDefinitionChange?: () => void;
};

export type EntityOtherProps = EventProps<EventTarget> & {
children?: ReactNode;
/** If true, the entity will be selected. It works only inside Viewer not CesiumWidget. */
selected?: boolean;
/** If true, the entity will be tracked by the camera. It works only inside Viewer not CesiumWidget. */
tracked?: boolean;
};
export type EntityOtherProps = RootComponentInternalProps &
EventProps<EventTarget> & {
children?: ReactNode;
/** If true, the entity will be selected. It works only inside Viewer not CesiumWidget. */
selected?: boolean;
/** If true, the entity will be tracked by the camera. It works only inside Viewer not CesiumWidget. */
tracked?: boolean;
};

export type EntityProps = EntityCesiumProps &
EntityCesiumReadonlyProps &
@@ -164,9 +172,12 @@ const Entity = createCesiumComponent<CesiumEntity, EntityProps>({
}
}
},
provide(element) {
provide(element, _ctx, props) {
return {
entity: element,
__$internal: {
onUpdate: props?.onUpdate,
},
};
},
cesiumProps,
2 changes: 2 additions & 0 deletions src/ImageryLayer/ImageryLayer.ts
Original file line number Diff line number Diff line change
@@ -99,6 +99,8 @@ const ImageryLayer = createCesiumComponent<CesiumImageryLayer, ImageryLayerProps
result = maybePromise as ImageryProvider;
}

if (!result) return;

const element = new CesiumImageryLayer(result, props);
context.imageryLayerCollection.add(element, props.index);
return element;
43 changes: 27 additions & 16 deletions src/core/hooks.ts
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
const wrapperRef = useRef<HTMLDivElement>(null);
const stateRef = useRef<State>();
const eventManager = ctx?.[eventManagerContextKey];
const mountReadyRef = useRef<Promise<void>>();

// Update properties
const updateProperties = useCallback(
@@ -157,8 +158,8 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
);
}

unmount();
mount();
await unmount();
mountReadyRef.current = mount();
}
},
[], // eslint-disable-line react-hooks/exhaustive-deps
@@ -224,7 +225,12 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
setMounted(true);
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const unmount = useCallback(() => {
const unmount = useCallback(async () => {
// Wait mount before unmount
if (mountReadyRef.current) {
await mountReadyRef.current;
}

// Destroy cesium element
if (element.current && destroy) {
destroy(element.current, ctx, wrapperRef.current, stateRef.current);
@@ -257,24 +263,29 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP

// To prevent re-execution by hot loader, execute only once
useLayoutEffect(() => {
mount();
return () => unmount();
mountReadyRef.current = mount();
return () => {
unmount();
};
}, []); // eslint-disable-line react-hooks/exhaustive-deps

// Update properties of cesium element
useEffect(() => {
const propsWC = propsWithChildren(props);
if (mounted) {
if (!shallowEquals(propsWC, prevProps.current)) {
updateProperties(propsWC);
ctx.__$internal?.onUpdate?.();
const update = async () => {
const propsWC = propsWithChildren(props);
if (mounted) {
if (!shallowEquals(propsWC, prevProps.current)) {
await updateProperties(propsWC);
ctx.__$internal?.onUpdate?.();
}
} else {
// first time
prevProps.current = propsWC;
initialProps.current = propsWC;
mountedRef.current = true;
}
} else {
// first time
prevProps.current = propsWC;
initialProps.current = propsWC;
mountedRef.current = true;
}
};
update();
}, [ctx.__$internal, mounted, props, updateProperties]);

// Expose cesium element

Unchanged files with check annotations Beta

</Provider>,
).unmount();
expect(ctx.entityCollection?.remove).toBeCalledWith(expect.any(CesiumEntity));

Check failure on line 55 in src/Entity/Entity.test.tsx

GitHub Actions / CI

src/Entity/Entity.test.tsx > should unmount

AssertionError: expected "spy" to be called with arguments: [ Any<Entity> ] Received: Number of calls: 0 ❯ src/Entity/Entity.test.tsx:55:40
});
</Provider>,
).unmount();
expect(destroy).toBeCalledWith("foobar", value, null, undefined);

Check failure on line 77 in src/core/component.test.tsx

GitHub Actions / CI

src/core/component.test.tsx > core/component > should call destroy fn on unmounted

AssertionError: expected "spy" to be called with arguments: [ 'foobar', { hoge: 1 }, null, …(1) ] Received: Number of calls: 0 ❯ src/core/component.test.tsx:77:21
expect(destroy).toBeCalledTimes(1);
});
rerender(<Component foo={2} />);
expect(createFn).toBeCalledTimes(2);

Check failure on line 195 in src/core/component.test.tsx

GitHub Actions / CI

src/core/component.test.tsx > core/component > should remount when cesium read only props are updated

AssertionError: expected "spy" to be called 2 times, but got 1 times ❯ src/core/component.test.tsx:195:22
expect(destroyFn).toBeCalledTimes(1);
expect(cesiumElement.foo).toBe(2);
});
);
expect(cesiumElement.foo).toBe(1);
expect(onUpdate).toBeCalledTimes(1);

Check failure on line 284 in src/core/component.test.tsx

GitHub Actions / CI

src/core/component.test.tsx > core/component > should invoke onUpdate event when being dirty

AssertionError: expected "spy" to be called 1 times, but got 0 times ❯ src/core/component.test.tsx:284:22
});
it("should render container", () => {
expect.anything(),
state,
);
expect(destroyFn).toBeCalledWith(expect.anything(), expect.anything(), null, state);

Check failure on line 338 in src/core/component.test.tsx

GitHub Actions / CI

src/core/component.test.tsx > core/component > should keep state

AssertionError: expected "spy" to be called with arguments: [ Anything, Anything, null, {} ] Received: Number of calls: 0 ❯ src/core/component.test.tsx:338:23
});
it("should not render when noChildren is true", () => {
name + "CesiumProps" === nodeName
? "cesiumProps"
: name + "CesiumReadonlyProps" === nodeName
? "cesiumReadonlyProps"

Check warning on line 80 in scripts/generator/parser.mts

GitHub Actions / CI

Insert `··`
: name + "CesiumEvents" === nodeName

Check warning on line 81 in scripts/generator/parser.mts

GitHub Actions / CI

Insert `··`
? "cesiumEvents"

Check warning on line 82 in scripts/generator/parser.mts

GitHub Actions / CI

Replace `······` with `··········`
: name + "OtherProps" === nodeName

Check warning on line 83 in scripts/generator/parser.mts

GitHub Actions / CI

Replace `······` with `··········`
? "otherProps"

Check warning on line 84 in scripts/generator/parser.mts

GitHub Actions / CI

Insert `······`
: name + "Props" === nodeName

Check warning on line 85 in scripts/generator/parser.mts

GitHub Actions / CI

Replace `······` with `············`
? "props"

Check warning on line 86 in scripts/generator/parser.mts

GitHub Actions / CI

Insert `········`
: undefined;

Check warning on line 87 in scripts/generator/parser.mts

GitHub Actions / CI

Insert `········`
if (!key) return;
const props = tc
!t
? ""
: !t.cesiumTypes.length
? t.text

Check warning on line 77 in scripts/generator/renderer.mts

GitHub Actions / CI

Insert `··`
: t.cesiumTypes

Check warning on line 78 in scripts/generator/renderer.mts

GitHub Actions / CI

Insert `··`
.concat()
.sort((a, b) => a.start - b.start)
.map<[CesiumTypeExpr, CesiumTypeExpr | undefined]>((s, i, a) => [