Skip to content

Update for Svelte 5 #24

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

Open
groundbirdaircat opened this issue May 5, 2024 · 5 comments
Open

Update for Svelte 5 #24

groundbirdaircat opened this issue May 5, 2024 · 5 comments

Comments

@groundbirdaircat
Copy link

Svelte 5 now has a RC, so I'm curious if there are any chances of this being updated to support Svelte 5?

I'm thinking a minimal update would only require updating peer dependencies.

This would at least get rid of the warning when installing packages:

npm WARN Could not resolve dependency:
npm WARN peer svelte@">=3.5.0" from svelte-virtual-scroll-list@1.3.0
npm WARN node_modules/svelte-virtual-scroll-list
npm WARN   dev svelte-virtual-scroll-list@"^1.3.0" from the root project
npm WARN
npm WARN Conflicting peer dependency: svelte@4.2.15
npm WARN node_modules/svelte
npm WARN   peer svelte@">=3.5.0" from svelte-virtual-scroll-list@1.3.0
npm WARN   node_modules/svelte-virtual-scroll-list
npm WARN     dev svelte-virtual-scroll-list@"^1.3.0" from the root project

However, to be compatible with Svelte 5 configured to Runes mode project-wide, more involved changes would be required.

Are there any plans/thoughts on this matter?

@JoshuaHintze
Copy link

I would like to know the same. Whether this project is abandoned or not. Its one of the few that I found to work decently well with dynamic sized data.

@v1ack
Copy link
Owner

v1ack commented Jun 3, 2024

Hello
Unfortunately I'm no longer frontend dev and I don't have time to maintain this lib.
But MR welcome

@mrxbox98
Copy link

I tried just changing the Item.svelte to svelte 5 and scrolling through the list would randomly jump for me. If anyone else wants to look over it:

<svelte:options runes={true} />

<script lang="ts">
    import { onDestroy, onMount } from "svelte";

    const {
        resize,
        horizontal = false,
        uniqueKey,
        type = "item",
    }: {
        resize: (arg0: { id: any; size: number; type: any }) => void;
        horizontal: boolean;
        uniqueKey: any;
        type: string;
    } = $props();

    let resizeObserver: ResizeObserver | null;
    let itemDiv: HTMLElement;
    let previousSize: number;

    const shapeKey = horizontal ? "offsetWidth" : "offsetHeight";

    onMount(() => {
        if (typeof ResizeObserver !== "undefined") {
            resizeObserver = new ResizeObserver(dispatchSizeChange);
            resizeObserver.observe(itemDiv);
        }
    });
    
    $effect(dispatchSizeChange);

    onDestroy(() => {
        if (resizeObserver) {
            resizeObserver.disconnect();
            resizeObserver = null;
        }
    });

    function dispatchSizeChange() {
        const size = itemDiv ? itemDiv[shapeKey] : 0;
        if (size === previousSize) return;
        previousSize = size;
        resize({ id: uniqueKey, size, type });
    }
</script>

<div bind:this={itemDiv} class="virtual-scroll-item">
    <slot />
</div>

@Coinhexa
Copy link

been a while since svelte 5 has come out, anyone got a fork of this lib with svelte 5 running?

@groundbirdaircat
Copy link
Author

@Coinhexa Not sure if there's a working fork, but this lib does currently function with Svelte 5 as-is.

Now that Svelte 5 is no longer in alpha, the dependency issues I posted in the OP are no longer present.

This lib does use stores though, so I believe you still can't force Runes-mode project wide (haven't tested lately, but don't see why this would change).

Also, I believe the Svelte team plans on deprecating stores eventually (Svelte 6 maybe? not sure), which would be EOL for this lib unless it gets updated.

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

5 participants