antvis / antvis/LarkMap

🤔 [QUESTION]基于useCreateLayer的组件在遇到Suspense的情况下会重复创建图层

Open
#250 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
87
Forks
34
PR merge metrics
No merged PRs in 30d

Description

### 🐛 Question description [Please make everyone to understand it]

所有基于 useCreateLayer的 Layer 组件在 React 19 下对 Suspense不友好,原因是“在 render 阶段创建并 addLayer,清理由 effect 管理”,而 effect 不会在被丢弃的 render 上运行。

### 💻 Link to minimal reproduction

```js
import { Suspense, useState } from 'react';
import { LarkMap, LineLayer } from '@antv/larkmap';

const lineData = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: [
[113.27, 23.12],
[113.31, 23.16],
],
},
},
],
};

const SuspenseGate = () => {
const [ready, setReady] = useState(false);
if (!ready) {
throw new Promise((resolve) => {
setTimeout(() => {
setReady(true);
resolve();
}, 0);
});
}
return null;
};

const Layers = () => (
<>



);

export default function App() {
return (


{
window.scene = scene;
}}
style={{ width: '100%', height: '100%' }}
mapType="Gaode"
mapOptions={{
center: [113.29, 23.14],
zoom: 13,
style: 'amap://styles/normal',
token: 'xx',
}}
>
loading…
}>




);
}

```
在控制台输入scene.getLayers()可以看到有多个LineLayer

### 🏞 Expected result

Marker组件在Suspense的情况下是符合预期的。预期在遇到Suspense的情况下结果与Marker的行为一致。

### 🚑 Any additional [like screenshots]

- **LarkMap Version**: 1.5.1

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the supplied React 19 example and inspect the useCreateLayer implementation alongside the Marker component's behavior. Use scene.getLayers() to verify the current duplicate-layer result under Suspense; done means the layer is created once and behaves like Marker.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.