Skip to content

Commit

Permalink
[4.x] Fix pagination with the nocache tag (#9394)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Feb 9, 2024
1 parent e100f68 commit 36a955b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/StaticCaching/NoCache/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Statamic\StaticCaching\NoCache;

use Illuminate\Pagination\AbstractPaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Statamic\Facades\Cascade;
use Statamic\Facades\Data;

Expand Down Expand Up @@ -113,6 +115,8 @@ public function restore()
$this->regions = $this->regions->merge($session['regions'] ?? []);
$this->cascade = $this->restoreCascade();

$this->resolvePageAndPathForPagination();

return $this;
}

Expand All @@ -124,6 +128,15 @@ private function restoreCascade()
->toArray();
}

private function resolvePageAndPathForPagination(): void
{
AbstractPaginator::currentPathResolver(fn () => Str::before($this->url, '?'));

AbstractPaginator::currentPageResolver(function () {
return Str::of($this->url)->after('page=')->before('&')->__toString();
});
}

private function cacheRegion(Region $region)
{
Cache::forever('nocache::region.'.$region->key(), $region);
Expand Down
2 changes: 1 addition & 1 deletion src/Tags/Concerns/OutputsItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function getPaginationData($paginator)
'current_page' => $paginator->currentPage(),
'prev_page' => $paginator->previousPageUrl(),
'next_page' => $paginator->nextPageUrl(),
'auto_links' => $paginator->render('pagination::default'),
'auto_links' => (string) $paginator->render('pagination::default'),
'links' => $paginator->renderArray(),
];
}
Expand Down

0 comments on commit 36a955b

Please sign in to comment.