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

Sources ignore changes to properties which occur between setup() and map load #114

Open
mattico opened this issue Jan 7, 2025 · 1 comment · May be fixed by #115
Open

Sources ignore changes to properties which occur between setup() and map load #114

mattico opened this issue Jan 7, 2025 · 1 comment · May be fixed by #115

Comments

@mattico
Copy link

mattico commented Jan 7, 2025

Hey, thanks for your work on this library!

setup(props, { slots }) {
const cid = inject(componentIdSymbol)!,
source = SourceLib.getSourceRef<GeoJSONSource>(cid, props.sourceId),
registry = new SourceLayerRegistry(),
opts = { ...props, type: "geojson" };
provide(sourceIdSymbol, props.sourceId);
provide(sourceLayerRegistry, registry);
useSource(source, opts as SourceOptionProps, registry);
watch(
isRef(props.data) ? props.data : () => props.data,
(v) => {
source.value?.setData(
(v as DataType) || { type: "FeatureCollection", features: [] },
);
},
{ immediate: true },
);
return () => [
createCommentVNode("GeoJSON Source"),
source.value && slots.default ? slots.default({}) : undefined,
];
},

If a change is made to props.data between setup() and map load, the source isn't initialized, so the watch doesn't call setData(), and the inner MGL source doesn't get updated with the new data from the prop.

We ran into this with the GeoJSON source but it should affect most of the other sources which use this watch() + source.setX() pattern.

@francois2metz
Copy link
Member

Hi,

Thanks for reporting the issue. I'll take a look to better understand the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants