website icon indicating copy to clipboard operation
website copied to clipboard

fix: blog pagination reset - implement URL parameter persistence

Open waygeance opened this issue 9 months ago • 5 comments

What kind of change does this PR introduce?

Bugfix (pagination state persistence) with minor refactoring.

Issue Number:

  • Closes #2213

Screenshots/videos:

Before:

  • Navigating to page N (e.g., page 3) and refreshing caused the blog to reset to page 1.
  • Pagination state was not reflected in the URL.
  • Hydration mismatch warnings appeared in the console.

After:

  • Pagination state persists via ?page=N.
  • Category filter persists via ?type=Category.
  • No hydration errors.
  • TypeScript compilation passes successfully.

Screencast from 2026-02-25 16-50-33.webm

If relevant, did you update the documentation?

Not required. This change affects internal state handling and does not modify public documentation or APIs.

Summary

This PR fixes the bug where the blog pagination resets to page 1 after a browser reload.

Previously, pagination state was stored only in component state and was not synchronized with the URL. As a result, refreshing the browser caused the blog to reload on page 1, losing the current pagination context.

Changes made:

  • Initialized currentPage from URL query parameters in pages/blog/index.page.tsx.
  • Added an updateUrl helper function to synchronize pagination and filter state with the browser URL.
  • Updated toggleCategory to reset pagination to page 1 when filters change.
  • Removed server-side URL parameter access to prevent hydration mismatches.
  • Resolved TypeScript errors.
  • Applied Prettier formatting.

This ensures pagination and filter state persist across reloads and eliminates hydration warnings.

Does this PR introduce a breaking change?

No. This change is backward compatible and does not affect any public APIs or external behavior.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

waygeance avatar Feb 27 '26 21:02 waygeance

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
website ✅ Ready (View Log) Visit Preview 0cd8cbe577faf70e7f7aff5a08bc671c7e219164

github-actions[bot] avatar Mar 03 '26 12:03 github-actions[bot]

Hi @Utkarsh-123github Boss, I have resolved the error please review when you get time ☺️

waygeance avatar Mar 03 '26 12:03 waygeance

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 100.00%. Comparing base (4bd72bb) to head (0cd8cbe). :warning: Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2291   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           30        30           
  Lines          672       672           
  Branches       211       211           
=========================================
  Hits           672       672           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Mar 03 '26 13:03 codecov[bot]

Any Updates on this @Utkarsh-123github Boss :relaxed:

waygeance avatar Mar 21 '26 16:03 waygeance

Hi @Utkarsh-123github Boss, Can you please review the PR when you get time :relaxed:

waygeance avatar Apr 11 '26 09:04 waygeance