Skip to content

Commit a7276e9

Browse files
author
danhnguyen
committed
♻️ refactor(useCreateLayer.ts): add source validation before layer creation
1 parent 7a2515e commit a7276e9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
.kiro
2526

2627
.eslintcache
2728
.vercel

libs/composables/layers/useCreateLayer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { shallowRef, unref, computed, watch, ref } from 'vue';
22
import type { CreateBaseLayerActions, Nullable, LayerTypes } from '@libs/types';
3-
import { getNanoid, hasLayer } from '@libs/helpers';
3+
import { getNanoid, hasLayer, hasSource } from '@libs/helpers';
44
import { useMapReloadEvent, useLogger } from '@libs/composables';
55
import type { MaybeRef } from 'vue';
66
import type {
@@ -272,6 +272,17 @@ export function useCreateLayer<Layer extends LayerSpecification>(
272272
return;
273273
}
274274

275+
// Validate source exists before adding layer
276+
if (!hasSource(map, sourceData)) {
277+
layerStatus.value = LayerStatus.Error;
278+
logError(
279+
`Error creating layer: Source '${sourceData}' does not exist`,
280+
null,
281+
{ layerId, type, sourceId: sourceData },
282+
);
283+
return;
284+
}
285+
275286
const layerSpec = {
276287
id: layerId,
277288
type,

0 commit comments

Comments
 (0)