Skip to content

Commit

Permalink
fix: force update when some data properties are updated on reearth/co…
Browse files Browse the repository at this point in the history
…re (#483)

fix: force update when some data properties are updated
  • Loading branch information
keiya01 committed Feb 22, 2023
1 parent 1d94558 commit 867238c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/Map/Layer/hooks.ts
@@ -1,4 +1,5 @@
import { useAtom } from "jotai";
import { isEqual, pick } from "lodash-es";
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";

import {
Expand All @@ -8,6 +9,7 @@ import {
type Atom,
evalFeature,
ComputedFeature,
type Data,
} from "../../mantle";
import type { DataRange, Feature, Layer } from "../../mantle";

Expand Down Expand Up @@ -81,6 +83,20 @@ export default function useHooks(
};
}, [layer, forceUpdateFeatures]);

const prevForceUpdatableData = useRef<Pick<Data, "csv" | "jsonProperties">>();
useLayoutEffect(() => {
const data = layer?.type === "simple" ? layer.data : undefined;
const forceUpdatableData = pick(data, "csv", "jsonProperties");

if (isEqual(forceUpdatableData, prevForceUpdatableData.current) || !data?.url) {
return;
}

forceUpdateFeatures();

prevForceUpdatableData.current = forceUpdatableData;
}, [layer, forceUpdateFeatures]);

// Clear expression cache if layer is unmounted
useEffect(
() => () => {
Expand Down

0 comments on commit 867238c

Please sign in to comment.