Skip to content

fix(core): initialize services earlier to ensure the map has been created for plugins#364

Closed
dopenguin wants to merge 2 commits intonextfrom
vue3/fix-map-creation
Closed

fix(core): initialize services earlier to ensure the map has been created for plugins#364
dopenguin wants to merge 2 commits intonextfrom
vue3/fix-map-creation

Conversation

@dopenguin
Copy link
Member

Summary

The map may not have been initialized if the services weren't fully received from a remote source when a plugin has been added.

Instructions for local reproduction and review

  • Change map in mainStore to null.
  • Call e.g. coreStore.map.getLayers() in setupPlugin of fullscreen and log the result
  • No error should occur

…ated for plugins

The map may not have been initialized if the services weren't fully received from a remote source
when a plugin has been added.
@dopenguin dopenguin self-assigned this Sep 23, 2025
@dopenguin dopenguin added the bug Something isn't working label Sep 23, 2025
@dopenguin dopenguin added this to the POLAR@3 milestone Sep 23, 2025
Copy link
Member

@warm-coolguy warm-coolguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏓 @dopenguin
🏓 @oeninghe-dataport I made a comment requesting your feedback, too.

M-M-M-MULTIBALL.

const overlay = useTemplateRef<typeof PolarMapOverlay>('polar-map-overlay')

let map: Map | null = null
let map: Map = {} as Map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oeninghe-dataport This is a workaround to avoid null checks later on in all plugins. It is assumed and/or planned that, before anything else gets their turn, createMap is run and completed. So effectively, nothing will ever run into an uninitialized map, except for the first call to createMap itself.

It still is an object rather than a real new Map() so errors regarding this are more apparent. What's your feedback on this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this really simplifies the code. Again, as #356 changes a lot here, I integrated this there -> 725b14b

const map = useTemplateRef('map')

createMap(
await createMap(
Copy link
Member

@warm-coolguy warm-coolguy Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having trouble imagining how this works. I've checked the code in the snowbox, too, and apparently createMap and addPlugin calls can be made fully independant of each other. This is especially troubling me since I do not understand in which map the added plugin will end up in, and how to control and direct that behaviour.

I'd have expected a return value to createMap that is required to either run addPlugin with as a parameter, or that addPlugin is registered on, id est:

const polarInstance = await createMap()
// addPlugin on instance
polarInstanceaddPlugin(...)
// XOR addPlugin requires instance as parameter
addPlugin(polarInstance, ...)

The way it is currently written, I could just

createMap()
addPlugin()
addPlugin()
addPlugin()
createMap()
addPlugin()

without await (since nothing is actively forcing me to await except for the following errors, if they occur ...) and be none the wiser what I have actually done. (I also tried to just randomly call addPlugin before createMap, but that fails internally due to pinia not being initialized.)

Maybe I'm missing the idea here?

Copy link
Member Author

@dopenguin dopenguin Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the state of this branch, all plugins are added to the same store. createMap effectively works on the same store. #356 tackles that.

However, your expectation seems to go a way that seems valid, even though it is a doubled effort.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oeninghe-dataport Due to the possibly duplicate effort I'd like your take on this detail, too. If this is already handled, we may as well close this thread. May need a ☎️ to resolve this quickly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@warm-coolguy I think your expectation is handled in #356 ; have a look at

const map = await createMap(
and
addPlugin(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this changes heavily with #356, I integrated this changes there. -> e0f3b57

Copy link
Collaborator

@oeninghe-dataport oeninghe-dataport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const map = useTemplateRef('map')

createMap(
await createMap(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@warm-coolguy I think your expectation is handled in #356 ; have a look at

const map = await createMap(
and
addPlugin(

const map = useTemplateRef('map')

createMap(
await createMap(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this changes heavily with #356, I integrated this changes there. -> e0f3b57

const overlay = useTemplateRef<typeof PolarMapOverlay>('polar-map-overlay')

let map: Map | null = null
let map: Map = {} as Map
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this really simplifies the code. Again, as #356 changes a lot here, I integrated this there -> 725b14b

Comment on lines +189 to +191
if (coreStore.configuration.checkServiceAvailability) {
checkServiceAvailability(coreStore.configuration, serviceRegister)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dopenguin Is there a compelling reason to move this here? As I incorporated the changes from this PR into #356, I stumbled on this, as configureApp doesn't know the configuration anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this here so it is called earlier than before. Nothing really relevant

Copy link
Member

@warm-coolguy warm-coolguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏓 @dopenguin @oeninghe-dataport Since the conceptional stuff seems to be resolved, more is up to you two guys getting this mergable/merged. I approve as far as my concerns go.

@dopenguin
Copy link
Member Author

Relevant changes have been integrated into #356, closing this PR.

@dopenguin dopenguin closed this Oct 6, 2025
@dopenguin dopenguin deleted the vue3/fix-map-creation branch October 29, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants