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

overrideItemIdKeyNameBeforeInitialisingDndZones not working as expected in Svelte v5 #571

Open
EricSSartorius opened this issue May 6, 2024 · 4 comments

Comments

@EricSSartorius
Copy link

In V4, importing and calling overrideItemIdKeyNameBeforeInitialisingDndZones at the top of the component using DND worked as expected. In Svelte v5 (RC) this no longer works. I get an error saying Uncaught Error: can only override the id key before initialising any dndzone. The UI renders but after trying to drag an item everything breaks.

@isaacHagoel
Copy link
Owner

isaacHagoel commented May 18, 2024

Hi @EricSSartorius,
I tried to reproduce this today but it seems to work fine for me.
I tried this using svelte 5.0.0-next.136 (tried v4 as well):

<script>
    import {dndzone, overrideItemIdKeyNameBeforeInitialisingDndZones} from "svelte-dnd-action";
    overrideItemIdKeyNameBeforeInitialisingDndZones("_id");
    function handleSort(e) {
        items = e.detail.items;
    }
    let items = [
        {_id:1, title: 'I'},
        {_id:2, title: 'Am'},
        {_id:3, title: 'Yoda'}
    ];
</script>
<style>
    section {
        width: 12em;
        padding: 1em;
        height: 7.5em;
    }
    div {
        height: 1.5em;
        width: 10em;
        text-align: center;
        border: 1px solid black;
        margin: 0.2em;
        padding: 0.3em;
    }
</style>
<section use:dndzone={{items}} on:consider={handleSort} on:finalize={handleSort}>
    {#each items as item(item._id)}
        <div>
            {item.title}
        </div>
    {/each}
<

What am I missing? Can you provide a way to reproduce?

@EricSSartorius
Copy link
Author

I tried to reproduce with something simple in SvelteBlitz but was having trouble myself which makes me think that the current complexity of my app is related to the problem.

I am currently fetching data from the DB in the page.server.ts file, sending that to the +page.svelte file and setting it in a store so that I can implement custom functionality to lazyload items on scroll, then in the child Board component I am setting overrideItemIdKeyNameBeforeInitialisingDndZones. navigating to the page is giving me an error but after refresh it loads fine. I can try to simplify code in my repo and maybe get things to work but I'm not sure why everything is perfectly fine in Svelte v4 but not v5 though.

@EricSSartorius
Copy link
Author

New information around this @isaacHagoel (still not working for me).

I realized the problem isn't with multiple instances of DND on one page, it is when going from one page that contains overrideItemIdKeyNameBeforeInitialisingDndZones to another that also contains it that the error occurs. When I navigated from a page that did not have overrideItemIdKeyNameBeforeInitialisingDndZones to the page that did, everything worked fine but not if they both contain the function.

There must be something different with load order when changing pages that I am not aware of in V5.

@isaacHagoel
Copy link
Owner

isaacHagoel commented Aug 16, 2024 via email

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

No branches or pull requests

2 participants