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

Server Side Pagination breaks if data empty #3216

Open
VitAndrGuid opened this issue Feb 12, 2025 · 0 comments
Open

Server Side Pagination breaks if data empty #3216

VitAndrGuid opened this issue Feb 12, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@VitAndrGuid
Copy link
Contributor

VitAndrGuid commented Feb 12, 2025

Current Behavior

Im using the Pagination component along with tanstack query to do some server side pagination.

When changing to the next page, tanstack query sets the query data to undefined and after it finishes loading it sets to the next page, however this breaks pagination as triggers the onPageChange event with page: 0, probably because the pagination component sees that data is undefined and resets the page to 0, this makes sense for client side pagination but not so much for server side.

Tbh idk if this is a bug as this is be intended but i think some other people will face this "gotcha" aswell, so if this is a wontfix this should be documented (i can open a PR for this)

"@skeletonlabs/skeleton": "3.0.0-next.10"
"@skeletonlabs/skeleton-svelte": "1.0.0-next.18"

Expected Behavior

Current page should not be reset on data changes unless explicitely told to ? or perhaps make data a optional prop as it only makes sense for client side pagination

Steps To Reproduce

<script lang="ts">
	import { Pagination } from '@skeletonlabs/skeleton-svelte';

	let page = $state(1);
	let pageSize = $state(2);

	const mockData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

	let data = $state<number[]>(mockData);

	const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

	const mockFetchNext = () => {
		// comment this line to fix the "bug"
		data = [];
		page = page + 1;
		delay(500).then(() => (data = mockData));
	};
</script>

<button class="btn preset-filled" onclick={mockFetchNext}>next</button>

<pre>{JSON.stringify({ data, page, pageSize })}</pre>

<Pagination bind:page bind:pageSize {data} count={data.length} />

Link to Reproduction / Stackblitz

No response

More Information

No response

@VitAndrGuid VitAndrGuid added the bug Something isn't working label Feb 12, 2025
@endigo9740 endigo9740 added this to the v3.0 (Next) milestone Feb 12, 2025
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

No branches or pull requests

2 participants