openearth / delta-vue-components

1 stars 1 forks source link

LayerListControls item not found fix #18

Open sjoerdbeentjes opened 3 years ago

sjoerdbeentjes commented 3 years ago

When I use the component in an application where it's used in multiple pages, i get this error:

image

It's kind of critical because the component does not function as expected after that.

This happens even if I force rerender the component. It seems like the selectedIds is not cleared when a new instance of the component is rerenderd.

My solution is to clear it manually on every mount.

petergoes commented 3 years ago

I agree with @bob-voorhoede that it can be done neater.

I looked at useSelected and there the state is created outside of the default function. This leads to the state being created globally which is, imho, the bug. By rewriting useSelected like so:

import { ref } from '@vue/composition-api'

export default function useSelected() {
  const selectedIds = ref([])

  function setSelectedIds(newList) {
    selectedIds.value = newList
  }

  return {
    selectedIds,
    setSelectedIds
  }
}

The selectedIds should be scoped to the component. I think that fixes the problem, but I did not tested it.