Urgent.News

What's breaking now, across thousands of outlets.

Tech

After every save, I refetch the page I'm on — not page one

Here's a bug I've shipped more than once: you edit a user on page 3 of an admin table, save, and the table jumps back to page 1. The edit worked. The user just isn't visible anymore, and for a second you wonder whether it worked at all. The fix in my starter kit's Users page is one argument: after closing the modal, call fetchUsers(meta.current_page) instead of fetchUsers(1). The modal closes,…

A common error occurs when editing a user on an admin table: the page jumps back to the first page, making it unclear whether the edit was successful or not. To fix this issue, my starter kit's Users page simply calls fetchUsers(meta.current_page) after closing the modal, rather than always fetching from page one. This reloads the table with the latest data from the server, ensuring the edited or newly added user appears in the correct position.

The delete operation follows the same principle: after calling client.delete( /users/ + id), the code still calls fetchUsers(meta.current_page) to keep the page displaying the correct information. An edge case exists when deleting the last row on a page, which would step back a page if the response comes back empty, but the simpler approach of staying on the same page is preferred for the common case.

The reason for refetching is that the server is the authoritative source for the table's data, and the list endpoint is relatively inexpensive. Instead of attempting to manually update the local row with optimistic updates, one refetch provides the server's ordering, correct page meta, and any concurrent changes made by other admins. Refetching incurs the cost of a single GET request but ensures the admin sees the updated state without guessing.

The underlying principle here is to trust the server's data and avoid making assumptions about the new state after a mutation. Optimistic updates can improve performance when dealing with slow lists or expensive mutations, but for an admin table over a local API, the refetch approach is fast, simple, and never incorrect. I reserve more advanced techniques for cases where they offer greater value.

Keeping the user on the same page might seem trivial, but it significantly enhances trust in the tool and avoids unnecessary navigation to verify changes. The Users page, the paginated API behind it, and the entire admin panel are included in my Laravel + React SaaS Starter Kit, available for $19 as a one-time purchase with Sanctum authentication and role-based access, allowing developers to avoid building these components from scratch.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Turning an Old Gaming Laptop into a Home Lab

I work in security evaluation, which mostly means looking at systems from the outside and checking whether they do what they say.

  • Author repurposes old Dell G7 7588 gaming laptop as home lab.
  • Installs Proxmox VE 9.2 hypervisor, allocates storage for guests.
  • Runs Debian 13 container as unprivileged LXC for security learning.

How to Turn Vertical Photos into WhatsApp Stickers (512 512 WebP, Under 100 KB)

Every phone gallery is full of tall photos — your cat mid-yawn, a birthday cake, a friend pulling a face. WhatsApp stickers are square.

  • WhatsApp stickers must be 512x512 pixels and WebP format under 100KB
  • Crop or pad portrait photos to fit 512x512 canvas without losing subject
  • Adjust WebP quality from 90 to 30 to achieve desired file size

More from Friday 30 October →