Skip to content

Fix cursor pagination crash on empty page#2663

Open
joshhanley wants to merge 2 commits into
mainfrom
josh/fix-cursor-pagination-empty-page
Open

Fix cursor pagination crash on empty page#2663
joshhanley wants to merge 2 commits into
mainfrom
josh/fix-cursor-pagination-empty-page

Conversation

@joshhanley

Copy link
Copy Markdown
Member

The Scenario

When a Flux pagination component renders cursor pagination on an empty page, Flux can throw an error instead of rendering the pagination controls.

This can happen when a stale cursor URL is opened, records are deleted, or filtering leaves the current cursor page empty.

<flux:pagination :paginator="$users" />

The Problem

Flux's simple pagination view calls ->encode() directly on the previous and next cursor values:

$paginator->previousCursor()->encode()
$paginator->nextCursor()->encode()

Laravel's cursor paginator returns null from previousCursor() and nextCursor() when the current page has no items. The pagination buttons can still render in that state because they are controlled by onFirstPage() and hasMorePages().

That means Flux can call encode() on null while rendering the previous or next button.

The Solution

Use the same approach that was merged in Livewire in livewire/livewire#10302.

Capture the previous and next cursors before rendering the buttons, then fall back to the current cursor when Laravel returns null.

The wire:key and setPage calls now use null-safe encoding, so an empty cursor page reloads the current cursor instead of throwing while the view renders.

Related to livewire/livewire#10302

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

Successfully merging this pull request may close these issues.

1 participant