Skip to content

Commit 4c20cce

Browse files
fix(AdvancedMarker): resolve race condition with slot content rendering
Fixed timing issue where AdvancedMarker components with custom slot content would not render correctly on initial load due to template refs being undefined when the watcher ran with immediate: true. Changes: - Add markerRef as watcher dependency to properly track template ref changes - Add guard clause to wait for markerRef when custom slot content is used - Add flush: 'post' to ensure DOM updates complete before watcher execution - Track markerRefChange to trigger updates when template ref becomes available Fixes rendering issues where: - AdvancedMarkers appeared as regular Markers until re-renders occurred - Custom slot content was ignored on initial component mount - Users needed workarounds like dummy markers to trigger proper rendering Related to GitHub issue #322. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 7ae74fc commit 4c20cce

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/AdvancedMarker.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ export default defineComponent({
5757
);
5858
5959
watch(
60-
[map, options, pinOptions],
61-
async (_, [oldMap, oldOptions, oldPinOptions]) => {
60+
[map, options, pinOptions, markerRef],
61+
async (_, [oldMap, oldOptions, oldPinOptions, oldMarkerRef]) => {
6262
const hasOptionChange = !equal(options.value, oldOptions) || !equal(pinOptions.value, oldPinOptions);
63-
const hasChanged = hasOptionChange || map.value !== oldMap;
63+
const hasMarkerRefChange = markerRef.value !== oldMarkerRef;
64+
const hasChanged = hasOptionChange || hasMarkerRefChange || map.value !== oldMap;
6465
6566
if (!map.value || !api.value || !hasChanged) return;
6667
68+
// If we need custom slot content but markerRef isn't available yet, wait for it
69+
if (hasCustomSlotContent.value && !markerRef.value) return;
70+
6771
const { AdvancedMarkerElement, PinElement } = api.value.marker;
6872
6973
if (marker.value) {
@@ -104,6 +108,7 @@ export default defineComponent({
104108
},
105109
{
106110
immediate: true,
111+
flush: "post", // Ensure DOM updates happen before this watcher runs
107112
}
108113
);
109114

0 commit comments

Comments
 (0)