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

v3.6.0 Draggable throws Error can't access property "x", translate is undefined #567

Closed
thomasaull opened this issue Jul 22, 2022 · 2 comments · Fixed by #568
Closed

v3.6.0 Draggable throws Error can't access property "x", translate is undefined #567

thomasaull opened this issue Jul 22, 2022 · 2 comments · Fixed by #568
Labels
bug Something isn't working

Comments

@thomasaull
Copy link

Some basic vue example:

<template>
  <div
    :id="id"
    ref="elRoot"
    class="DragAndDrop"
    @mousedown.stop.prevent="onMouseDown"
  ></div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import { Draggable, store } from '@dflex/draggable'
import cuid from 'cuid'

export default defineComponent({
  name: 'DragAndDrop',
  components: {},

  setup() {
    const id = `draggable-button.${cuid.slug()}`
    let draggedEvent: Draggable
    const elRoot = ref()

    const onMouseDown = (event: MouseEvent) => {
      draggedEvent = new Draggable(id, { x: event.clientX, y: event.clientY })

      document.addEventListener('mouseup', onMouseUp)
      document.addEventListener('mousemove', onMouseMove)
    }

    const onMouseMove = (event: MouseEvent) => {
      if (!draggedEvent) return

      draggedEvent.dragAt(event.clientX, event.clientY)
    }

    const onMouseUp = () => {
      if (draggedEvent) {
        draggedEvent.endDragging()

        document.removeEventListener('mouseup', onMouseUp)
        document.removeEventListener('mousemove', onMouseMove)
      }
    }

    onMounted(() => {
      store.register(id)
    })

    return {
      id,
      elRoot,
      onMouseDown,
      onMouseMove,
    }
  },
})
</script>

<style lang="scss">
.DragAndDrop {
  $block: &;

  width: 200px;
  height: 100px;
  border: 2px solid fuchsia;
  border-radius: 10px;
  background-color: rgba(fuchsia, 0.1);
}
</style>

As soon as the onMouseDown is fired, there is an error:

can't access property "x", translate is undefined

It happens with 3.6.0 but works fine with 3.5.4. I was trying to create a reproduction on Codesandbox but for some reason I can't add @dflex/draggable as a dependency there…

@jalal246 jalal246 added the bug Something isn't working label Jul 22, 2022
@jalal246 jalal246 linked a pull request Jul 22, 2022 that will close this issue
@jalal246
Copy link
Member

Hi @thomasaull, thanks for reporting this issue. DFlex does somehow "lazy loading" in order to be scalable and prevent any potential blocking event. To do so, the registration is partitioned to multiple levels. So it doesn't create all the related instance once when your app is mounted. While this is handled in DnD, I forgot to deal with it in the Draggable only :)

@jalal246 jalal246 reopened this Jul 22, 2022
@thomasaull
Copy link
Author

Thanks for the quick fix :)

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 a pull request may close this issue.

2 participants